Archived

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

Orientation of objects

This topic is 5377 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 recently been working on a space game and have been having some difficulty with object orientation. I have a camera which seems to move correctly using the mouse. I am using a position vector and 3 vectors for orientation of my ship/camera (directon, up, right). This is great for orienting the camera as I can use D3DXMatrixLookAtLH and pass in the vectors. However, when I try to orient a missile the same as my ship, it doesn't work. I set the 3 orientation vectors of my missile to match the orientation of my ship. The missile travels in the right direction but is not rotated correctly. Has anyone else seen this problem and solved it? Is there another way to design this so it is easier? I ask this question because the only orientation function I see in D3DX that is close is D3DXMatrixRollPitchYaw(). Since I am not sure how to convert 3 orientation vectors to roll, pitch and yaw angles I can't use this function. Thanks in advance. -dizzy [edited by - yzzid on March 24, 2003 11:26:02 AM]

Share this post


Link to post
Share on other sites
If you have 3 vectors representing the positive X, Y, and Z axes of an object''s orientation, and a vector representing its position, as follows:

X = (x1,x2,x3)
Y = (y1,y2,y3)
Z = (z1,z2,z3)
P = (x,y,z)

then a matrix to translate from the unrotated origin to that position is given by (seems too good to believe):

[x1,x2,x3,0]
[y1,y2,y3,0]
[z1,z2,z3,0]
[x ,y ,z ,1]

You will need to construct this matrix by hand. Here is code from my orientation class:

m_Matrix._11 = m_XAxis.x; m_Matrix._12 = m_XAxis.y; m_Matrix._13 = m_XAxis.z; m_Matrix._14 = 0;
m_Matrix._21 = m_YAxis.x; m_Matrix._22 = m_YAxis.y; m_Matrix._23 = m_YAxis.z; m_Matrix._24 = 0;
m_Matrix._31 = m_ZAxis.x; m_Matrix._32 = m_ZAxis.y; m_Matrix._33 = m_ZAxis.z; m_Matrix._34 = 0;
m_Matrix._41 = m_Position.x; m_Matrix._42 = m_Position.y; m_Matrix._43 = m_Position.z; m_Matrix._44 = 1;

So, given your ship''s orientation information, you can create a matrix to put the missile there.

The problem then becomes, how do you move that missile forward? Well, assuming that you want the missile to move in the (model space) positive z-direction, you can just add a multiple of the third row of the matrix to the fourth row (positive multiples move the missile forward). Now, if you want homing missiles, the process becomes somewhat more involved.

I wrote a space sim for an independent study high-school project two years back, I''d be glad to help if you need some more pointers.



~BenDilts( void );

PS. Make sure that both your missile and ship point the same direction in model space :-) You might be pointing the ship down the Z axis and the missile down the Y axis.

Share this post


Link to post
Share on other sites
It shouldn't be a problem unless your model orientation is different between the two.

NOTE TO SELF: Don't post while half asleep and don't post unless you read the ENTIRE reply.

[edited by - LordShade on March 25, 2003 6:28:14 AM]

Share this post


Link to post
Share on other sites
Wow! Thanks! That did the trick.
I searched high and low and I really wasn't able to find much info about this sort of thing.
Incidently, that is almost what I came up with. I had my rotations correct but I put the translation in the last column instead of the last row.

-dizzy

[edited by - yzzid on March 25, 2003 8:37:12 AM]

Share this post


Link to post
Share on other sites