
Untitled
By: a guest on
Apr 30th, 2012 | syntax:
None | size: 0.92 KB | hits: 18 | expires: Never
how to move 3d object in XNA?
float dirX = (float)Math.Sin(angle);
float dirY = (float)Math.Cos(angle);
if (Keyboard.GetState().IsKeyDown(Keys.Up))
{
position += new Vector3(-dirX, dirY, 0);
if (Keyboard.GetState().IsKeyDown(Keys.Left))
{
angle += 0.015f;
}
if (Keyboard.GetState().IsKeyDown(Keys.Right))
{
angle -= 0.015f;
}
}
world = Matrix.CreateTranslation(position) * Matrix.CreateRotationY(angle) * Matrix.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(-90));
float dirX = (float)Math.Sin(angle);
float dirZ = (float)Math.Cos(angle);
position += new Vector3(dirX, 0, dirZ);
Scale * Rotation * Translation
// this will rotate car around the Y axis, and then translate it to correct location
world = Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(position);