Extracting Info from D3DXMATRIX
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?
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.
matLastPosition._41 = X position
matLastPosition._42 = Y position
matLastPosition._43 = Z 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?
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 BattlehorseRead 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...
how do I use D3DXMatrixDecompose()
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement