Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


moving objects (d3d)

This topic is 5999 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have an object that i want to move forward relative to the direction it''s looking...i''ve written code that does this to the camera from a first person view, but it doesn''t seem to work on an object - the object must be rotated several times in order for it to begin going in the right direction..what am i doing wrong?

Share this post

Link to post
Share on other sites
It''s very hard to say unless you actually post the object code, and prefereably the camera code so i can compare them and see whats wrong.

It might just be a transformation mistake, i believe the transformations for objects and cameras occur in different orders.

The sad thing about artificial intelligence is that it lacks artifice and therefore intelligence.

Share this post

Link to post
Share on other sites
I''m going to assume that you have a matrix (not a vector) being used for the rotation/position/translation of the object.

Based on that all you would have to do is always use D3DXMatrixTranslate(&theobject)... and pass it something like 1,0,0 which will move the object always on it''s x axis.

Think of it this way..Your not moving the object relative to the world but to it''s self. So when ever you rotate the object with D3DXMatrixRotate(&theobject); your changing the orientation of the axis for that object, so that when every you do other rotations, or translations after this call, it will be relative to the new axis...

Hope that made some sense


"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....."

Share this post

Link to post
Share on other sites
i am using D3DXMatrixTtranslation() in my "build world matrix" function...here is the code for my "key up" ( move forward ) event:

for (p = 0; p < 6; p++)
TheShip[p].xPosWorld += sinf(D3DXToRadian(theShip[p].yRot)) * .2f;
theShip[p].zPosWorld -= cosf(D3DXToRadian(theShip[p].yRot)) * .2f;

i''m trying to move all ships forward no matter which way they are looking...it''s strange because a first person game i''m writing uses this code for the camera and it works fine in all directions...by the way, i''m applying the same formulas to my camera, so it will follow the player.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!