Archived

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

u0_80

moving objects (d3d)

Recommended Posts

u0_80    122
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
Promit    13246
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
Pactuul    122
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


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



Share this post


Link to post
Share on other sites
u0_80    122
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