In Direct3D, I'm using the Matrix.LookAtLH function to compute the view matrix.
I am using this for the camera, which I orbit around a target by moving the origin to the target position开发者_C百科, rotating, and then moving the origin back to (0,0,0).
This is multiplied to the matrix that was originally computed from LookAtLH.
Is there a way I can, after a few of these operations, decompose the matrix to get the eye position, target position, and up vector?
View matricies are very easy to extract data from. Check out the documentation for the function you used (I've used the documentation for D3DXMatrixLookAtLH):
http://msdn.microsoft.com/en-us/library/bb205342%28v=vs.85%29.aspx
As you can see towards the bottom of the page, the matrix is internally generated like so:
zaxis = normal(At - Eye)
xaxis = normal(cross(Up, zaxis))
yaxis = cross(zaxis, xaxis)
xaxis.x yaxis.x zaxis.x 0
xaxis.y yaxis.y zaxis.y 0
xaxis.z yaxis.z zaxis.z 0
-dot(xaxis, eye) -dot(yaxis, eye) -dot(zaxis, eye) 1
Bear in mind, this is only valid for DirectX; transpose the above matrix when porting the same calculations to OpenGL because the coordinate system in DirectX is backwards to the norm.
Two options :
- Long and difficult : extract eye, up and lookAt from the new computed matrix
- Easy version : apply your transformations (translation, rotation, translation) to a copy of your eye, up, and lookAt. This way you will get very easily the new vectors.
精彩评论