3D Directional Movement

Started by
7 comments, last by AdmiralBinary 22 years, 5 months ago
OK, I have a working 3d "engine" and a model of a horrible monster in it. I can display the monster. I can rotate the monster. I can light the monster. Now, my question is: How do i get the dang thing to move? I know basically how to change x,y,z co-ordinates etc. but what i don''t know is how to move an object IN THE DIRECTION IT''S FACING. This is what I know about the object: - Its x,y,z co-ords - Its x,y,z axis rotation - Its colour (sorry, three points lookz better ) "Playse Halp...Plaes Help" - Leeloo from the 5th Element --------------- I finally got it all together... ...and then forgot where I put it.
Advertisement
P.S. Very stupid of me to forget this: I''m using Direct3D 8.0

---------------

I finally got it all together...
...and then forgot where I put it.
BUMP - pleeeeeease...

---------------

I finally got it all together...
...and then forgot where I put it.
Ahh well...I''ll check this for replies in the morning...goodnite all :D

---------------

I finally got it all together...
...and then forgot where I put it.
pos.x += ZAxisRotation.x * MoveDist;
pos.y += ZAxisRotation.y * MoveDist;
pos.z += ZAxisRotation.z * MoveDist;

Assuming MoveDist is a none zero float, and ZAxisRotation is the direction vector from your orientation matrix.
( look in the dx SDK for the matrix definition of the axis etc).

[The views stated herein do not necessarily represent the view of the company Eurocom ]

Eurocom Entertainment Software
www.Eurocom.co.uk

The Jackal

Edited by - Mark Duffill on November 20, 2001 7:33:24 AM
Well I suggest using a directx matrix. This will hold the position, rotation, scale, and velocity. just look in the sdk for all the functions that you can do. Order of operations is important.

usually you translate the position, then rotate the matrix, then scale (if you scaled first all the translating and rotating would be scaled also).

so now when you want to move the creature forward you just transalate the matrix by a forward like 0,0,1 this of course will move the creature forward on the creature''s current z-axis due to rotation. (note 0,0,1 here is relative to the creature and not abosulte to the world)

this saved me from having to constantly worry about how to handle rotations.

hope this helps
Pactuul
-Pac "The thing I like about friends in my classes is that they can't access my private members directly." "When listening to some one tell about their problem (whether it's code or not), don't listen to what went right or wrong, but what they assumed....."
Thanx evry1! I''ll try that... I didn''t know I should be storing the matrix lol.

---------------

I finally got it all together...
...and then forgot where I put it.
Er...Sorry about this - I tried sum stuff but I''m still confused: How exactly do I get the "direction vector" from the "orientation matrix"???

---------------

I finally got it all together...
...and then forgot where I put it.
OK here is the trick

I am assuming you have 4x4 matrix for the monster. The first 3 components of the first column (or row depending on whether your matrix is left or right handed) are the x,y,z components of a vector pointing up from your object. similarly the second column is a vector pointing to the right of the object and the third column is a vector pointing forward from the object.

if you have a matrix class, just make a method called GetIn(), which creates a vector from the third column. Then scale the vector by the amount you need and finally translate the matrix by that vector.

Hope that helps

This topic is closed to new replies.

Advertisement