Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 30th, 2012  |  syntax: None  |  size: 0.92 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how to move 3d object in XNA?
  2. float dirX = (float)Math.Sin(angle);
  3. float dirY = (float)Math.Cos(angle);
  4.  
  5. if (Keyboard.GetState().IsKeyDown(Keys.Up))
  6.         {
  7.             position += new Vector3(-dirX, dirY, 0);
  8.  
  9.             if (Keyboard.GetState().IsKeyDown(Keys.Left))
  10.             {
  11.                 angle += 0.015f;
  12.             }
  13.  
  14.             if (Keyboard.GetState().IsKeyDown(Keys.Right))
  15.             {
  16.                 angle -= 0.015f;
  17.             }
  18.         }
  19.        
  20. world = Matrix.CreateTranslation(position) * Matrix.CreateRotationY(angle) * Matrix.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(-90));
  21.        
  22. float dirX = (float)Math.Sin(angle);
  23. float dirZ = (float)Math.Cos(angle);
  24.  
  25. position += new Vector3(dirX, 0, dirZ);
  26.        
  27. Scale * Rotation * Translation
  28.        
  29. // this will rotate car around the Y axis, and then translate it to correct location
  30. world = Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(position);