algo for moving in the direction of object facing

Started by
1 comment, last by edwinnie 20 years, 10 months ago
ok! i managed to get the object rotates abt itself... now i am figuring out how to make it move in the direction it is facing... any ideas to share? thx! edwin
Advertisement

The following members in your world matrix form a vector that points in the direction the object is facing:

_13, _23, _33

Assuming there are no scales or skews in your matrix (if it''s just rotation and translation, there won''t be), then that vector is also normalised (it''s length == 1).

So all you have to do is multiply that vector by the distance to move and add it to the translation part of the world matrix:

vec3 direction;
direction.x = worldmatrix._13;
direction.y = worldmatrix._23;
direction.z = worldmatrix._33;

worldmatrix._41 += direction.x * DISTANCE_TO_MOVE;
worldmatrix._42 += direction.y * DISTANCE_TO_MOVE;
worldmatrix._43 += direction.z * DISTANCE_TO_MOVE;


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

sighz doesnt seem to work...
looks like its due to the design of the scenegraph...
(i am using the one provided by GI (week 5 meshviewer))

thx!

edwinz

This topic is closed to new replies.

Advertisement