Jump to content

  • Log In with Google      Sign In   
  • Create Account

Extracting LookAt Vector from View Matrix


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
27 replies to this topic

#21 Alin   Members   -  Reputation: 391

Like
0Likes
Like

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;

Sponsor:

#22 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

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


#23 Alin   Members   -  Reputation: 391

Like
0Likes
Like

Posted 17 December 2012 - 10:36 PM

Don't update m_vLookAt with vLook because it is a normalized directional vector while m_vLookAt is a point vector.

#24 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 18 December 2012 - 02:29 AM

@Alin: I used the exact code you posted to get the view matrix, the last code you posted doesn't change m_vLookAt, it take instance of it, I never add m_vLookAt = Look.

#25 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

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 L. Spiro   Crossbones+   -  Reputation: 13600

Like
0Likes
Like

Posted 18 December 2012 - 06:01 PM

Create the following matrix:
[ 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
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#27 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 18 December 2012 - 06:05 PM

Resolved!

I had to set the capsule LookAt to (m_vPosition + m_vLook).

Thanks everyone who participated in the thread!

#28 JohnnyCode   Members   -  Reputation: 219

Like
0Likes
Like

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS