Reputation: 349
I've implemented a simple arc-ball camera and it works well - when I use the mouse, I update the View matrix with roll, pitch and yawn.
However, in order to properly calculate specular reflection, I need current camera position in world space which is not updated per-se when applying rotation.
Do you guys know how can retrieve current position from the View matrix? Or is there another way to update this?
Upvotes: 4
Views: 18642
Reputation: 137
You have some simple choices:
Inverse the view matrix by calling XMMatrixInverse or D3DXMatrixInverse so you get the "CameraWorld" matrix. Then its (_41,_42,_43) elements would be the position vector.
Inverse the view matrix (such as last time) but instead of reading forth roe, use XMMatrixDecompose or D3DXMatrixDecompose to get camera position and orientation.
A great idea is to have both View and InvView matrices in your program memory so as to access these info quickly: the matrix inversion is computationally expensive.
Upvotes: 7