Extracting Info from D3DXMATRIX

Started by
6 comments, last by Battlehorse 17 years, 1 month ago
Here's the deal: I'm creating a mini flight-simulator so that I can get familiar with C++ and DirectX 9. Thanks to the relative movement of the matrices that DirectX showed me, I was able to get the plane flying almost no-problem. BUT the camera is stand-still. I want the camera to follow the plane, just looking at it from a fixed point. SO I need to extract the position of the position/rotation matrix of the plane. Somebody posted something about multiplying 14 and 42 and whatever... Here's what I attempted from that: D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3 (camX, camY, camZ), // the camera position &D3DXVECTOR3 (matLastPosition._11 * matLastPosition._41 + matLastPosition._12 * matLastPosition._42 + matLastPosition._13 * matLastPosition._43, matLastPosition._21 * matLastPosition._41 + matLastPosition._22 * matLastPosition._42 + matLastPosition._32 * matLastPosition._43, matLastPosition._31 * matLastPosition._41 + matLastPosition._32 * matLastPosition._42 + matLastPosition._33 * matLastPosition._43), // the look-at position &D3DXVECTOR3 (0, 1, 0)); // the up direction Kin you tell me what I'm doing wrong?
Advertisement
Quote:Original post by Battlehorse
Here's the deal: I'm creating a mini flight-simulator so that I can get familiar with C++ and DirectX 9.

Thanks to the relative movement of the matrices that DirectX showed me, I was able to get the plane flying almost no-problem. BUT the camera is stand-still. I want the camera to follow the plane, just looking at it from a fixed point. SO I need to extract the position of the position/rotation matrix of the plane.

Somebody posted something about multiplying 14 and 42 and whatever... Here's what I attempted from that:


D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (camX, camY, camZ), // the camera position
&D3DXVECTOR3 (matLastPosition._11 * matLastPosition._41 + matLastPosition._12 * matLastPosition._42 + matLastPosition._13 * matLastPosition._43,
matLastPosition._21 * matLastPosition._41 + matLastPosition._22 * matLastPosition._42 + matLastPosition._32 * matLastPosition._43,
matLastPosition._31 * matLastPosition._41 + matLastPosition._32 * matLastPosition._42 + matLastPosition._33 * matLastPosition._43), // the look-at position
&D3DXVECTOR3 (0, 1, 0)); // the up direction

Kin you tell me what I'm doing wrong?



You can try using D3DXMatrixDecompose() to get the translation.

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

matLastPosition._41 = X position
matLastPosition._42 = Y position
matLastPosition._43 = Z position
how do I use D3DXMatrixDecompose()


also, Chris, I read somewhere that if I do

matLastPosition._41 = X position
matLastPosition._42 = Y position
matLastPosition._43 = Z position

then it only captures position correctly if there is no rotation. Is this right or is it bogus?
Quote:Original post by Battlehorse
how do I use D3DXMatrixDecompose()
Read the SDK docs? D3DXMatrixDecompose() gives you the rotation as a quaternion, which you should really be using instead of euler angles for a flight sim anyway, otherwise you're entering a world of pain with gimball lock...
Yes, mat._41/mat._42/mat._43 are just 3 values which represent position. I guess I don't know exactly what you are going for here. Are you trying to set the camera on the side of the plane, behind the plane, fixed position on the ground?
For now, I'm trying to have a camera, whose position is fixed at a point, but its target position, where it's pointing, fixed at the plane's position. In effect, one can fly the plane wherever and the camera will always be looking at it.

D3DXMatrixLookAtLH allows me to do this effectively, splitting the camera's matrix into 3 sets of 3 variables

-the position itself (fixed)
-the look-at position (plane)
-the *up* position (where the top of the camera is facing)

thanks for your help guys, but... :( doesn't seem to be working... Gotta go for now. I'll test this some more tomorrow.
Ah yes! That works perfectly! I was commenting a line I thought I wasn't commenting :D thanks for all help.

This topic is closed to new replies.

Advertisement