27 replies to this topic
#21 Members - Reputation: 255
Posted 17 December 2012 - 06:33 AM
Try again, I believe it will work:
D3DXMATRIX m_mView;
D3DXMatrixIdentity( &m_mView );
D3DXVECTOR3 vLook = m_vLookAt;
D3DXVec3Normalize( &vLook, &(vLook - m_vPosition) );
D3DXVECTOR3 vRight = m_vRight;
D3DXVec3Cross( &vRight, &m_vUp, &vLook );
D3DXVec3Normalize( &vRight, &vRight );
D3DXVECTOR3 vUp = m_vUp;
D3DXVec3Cross( &vUp, &vLook, &vRight );
D3DXVec3Normalize( &vUp, &vUp );
m_mView._11 = vRight.x;
m_mView._12 = vUp.x;
m_mView._13 = vLook.x;
m_mView._14 = 0.0f;
m_mView._21 = vRight.y;
m_mView._22 = vUp.y;
m_mView._23 = vLook.y;
m_mView._24 = 0.0f;
m_mView._31 = vRight.z;
m_mView._32 = vUp.z;
m_mView._33 = vLook.z;
m_mView._34 = 0.0f;
m_mView._41 = -D3DXVec3Dot( &m_vPosition, &vRight );
m_mView._42 = -D3DXVec3Dot( &m_vPosition, &vUp );
m_mView._43 = -D3DXVec3Dot( &m_vPosition, &vLook );
m_mView._44 = 1.0f;
D3DXMATRIX m_mView;
D3DXMatrixIdentity( &m_mView );
D3DXVECTOR3 vLook = m_vLookAt;
D3DXVec3Normalize( &vLook, &(vLook - m_vPosition) );
D3DXVECTOR3 vRight = m_vRight;
D3DXVec3Cross( &vRight, &m_vUp, &vLook );
D3DXVec3Normalize( &vRight, &vRight );
D3DXVECTOR3 vUp = m_vUp;
D3DXVec3Cross( &vUp, &vLook, &vRight );
D3DXVec3Normalize( &vUp, &vUp );
m_mView._11 = vRight.x;
m_mView._12 = vUp.x;
m_mView._13 = vLook.x;
m_mView._14 = 0.0f;
m_mView._21 = vRight.y;
m_mView._22 = vUp.y;
m_mView._23 = vLook.y;
m_mView._24 = 0.0f;
m_mView._31 = vRight.z;
m_mView._32 = vUp.z;
m_mView._33 = vLook.z;
m_mView._34 = 0.0f;
m_mView._41 = -D3DXVec3Dot( &m_vPosition, &vRight );
m_mView._42 = -D3DXVec3Dot( &m_vPosition, &vUp );
m_mView._43 = -D3DXVec3Dot( &m_vPosition, &vLook );
m_mView._44 = 1.0f;
Sponsor:
#22 Members - Reputation: 358
Posted 17 December 2012 - 07:54 AM
Unfortutenly, the camera is working but I couldn't get the capsule mesh to look at the same direction as the camera.
I tried:
The above code works perfectly only when I calculate the view matrix using D3DXMatrixLookAtLH() instead of the code you posted.
I'm trying to use m_vRight so I can't just use D3DXMatrixLookAtLH() to calculate the view matrix.
I tried:
capsuleMesh->LookAt(camera->m_vLook.x, camera->m_vLook.y, camera->m_vLook.z);
The above code works perfectly only when I calculate the view matrix using D3DXMatrixLookAtLH() instead of the code you posted.
I'm trying to use m_vRight so I can't just use D3DXMatrixLookAtLH() to calculate the view matrix.
Edited by Medo3337, 17 December 2012 - 08:36 AM.
#25 Members - Reputation: 358
Posted 18 December 2012 - 05:42 PM
To be clear, the only problem I am facing now is making the capsule mesh look at the same direction as the camera, If someone can show how to make the capsule mesh look at the same direction as the camera, the question will be resolved.
#26 Crossbones+ - Reputation: 5172
Posted 18 December 2012 - 06:01 PM
Create the following matrix:
Multiply the object’s world matrix by this matrix to get the final world matrix.
L. Spiro
[ cam._11 cam._12 cam._13 0.0] [ cam._21 cam._22 cam._23 0.0] [ cam._31 cam._32 cam._33 0.0] [ 0.0 0.0 0.0 1.0]
Multiply the object’s world matrix by this matrix to get the final world matrix.
L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
#28 Members - Reputation: 37
Posted 21 December 2012 - 01:21 PM
maybe you could transform 0,0,1 vector (or any) by the view matrix. Resulting vector should be pointing in the direction of view, considered it to be a world space vector. It might be performance wiser operation then decomposing view matrix.






