I want to control my 3D model, move it every direction but I don't know way to do this. Anybody have any idea ?
Asked
Active
Viewed 2,037 times
0
-
Handle input keys, change the x/y/z location of the model, profit. – thedaian Sep 18 '11 at 04:47
-
If I want to turn left or right, how I have to process ? – beanhorstmann Sep 18 '11 at 04:50
-
Anybody can guide me to create a simple demo game, draw a ship (3D), and use keyboard to control it, arrow left or right to turn it left or right, arrow up to go forward, arrow down to go backward. Help me! – beanhorstmann Sep 18 '11 at 07:49
1 Answers
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