【发布时间】:2019-04-16 08:50:21
【问题描述】:
我在 VS 2015 社区中创建了一个 XNA 4.0 3D 项目。它有一个带有子弹模型的 Skybox,我试图模拟它的轨迹。我似乎无法将相机置于正确的位置,并且平移似乎在错误的轴上工作。
我尝试过改变模型、相机甚至视角的位置。
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
this.Exit();
mDeltaTime = gameTime;
mFlightTime += 0.1f;
//if (mAngleInput != 0)
//{
// mVelocity.X = (float)(mVelocityInput * Math.Cos(DegreeToRadian(mAngleInput)));
// mVelocity.Y = (float)(mVelocityInput * Math.Sin(DegreeToRadian(mAngleInput)));
//}
position = (mStartingPosition + mVelocity * mFlightTime) - (0.5f * mAcceleration * (float)Math.Pow(mFlightTime, 2)) / 5;
// This updates the world matrix, so that it reflects the changes to the position
// and angle. Remember that this matrix determines where the model will be located
// at in the 3D world.
// camTarget += new Vector3(0.1f,0,0);
// world = Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(position);
// view = Matrix.CreateLookAt(camTarget, position, Vector3.UnitY);
cameraPosition = (distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)));
Vector3 cameraTarget = position;
//original Vector3 cameraTarget = new Vector3(0, 0, 0);
viewVector = Vector3.Transform(cameraTarget - cameraPosition, Matrix.CreateRotationY(0));
// viewVector.Normalize();
angle += 0.002f;
world = Matrix.CreateScale(0.5f) * Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(position);
view = Matrix.CreateLookAt(cameraTarget, cameraPosition, Vector3.UnitY);
//original view = Matrix.CreateLookAt(cameraPosition, new Vector3(0, 0, 0), Vector3.UnitY);
base.Update(gameTime);
}
我希望模型从某个位置开始,然后根据我使用的轨迹公式移动水平 X 轴并放下垂直 Y 轴。一旦达到某个 Y 值就停止。
【问题讨论】:
-
谁能帮忙?
-
你能分享一下 Draw() 方法和变量初始化吗?
-
@Strom Game1.cs 文件在这里dropbox.com/s/wews924zmyqg6rj/Game1.cs?dl=0