0

I want to control my 3D model, move it every direction but I don't know way to do this. Anybody have any idea ?

beanhorstmann
  • 269
  • 3
  • 6
  • 8

1 Answers1

1

You only have to provide to the effect the model's world transform.

 Matrix World = Matrix.CreateWorld(position, forward, up);

In your update method you can modify the position:

  LastPosition = Position;  

  if (IsKeyDonw(Left)  Position -= Vector3.UnitX * Speed * ElapsedTime; ForwardDirty = true;     
  if (IsKeyDonw(Right)  Position += Vector3.UnitX * Speed * ElapsedTime; ForwardDirty = true;     
  if (IsKeyDonw(Up)  Position -= Vector3.UnitZ * Speed * ElapsedTime;  ForwardDirty = true;     
  if (IsKeyDonw(Down)  Position += Vector3.UnitZ * Speed * ElapsedTime; ForwardDirty = true;     


// the forward is the direction where will point your model.

if (ForwardDirty) {
     Forward = Position - LastPosition;
     Forward.Normalize();
     ForwardDirty = false;
}

You also can base your movement in forward vector, or smooth the angle change interpolating the final forward with the current,...

Blau
  • 5,742
  • 1
  • 18
  • 27
  • +1: I wouldn't even bother with setting the `ForwardDirty` flag and just adjust the `Forward Vector3` inside of the `if` statement of the button press. – Neil Knight Oct 10 '11 at 13:29