How to calculate the current camera position? my code doesn't work...

Started by
4 comments, last by lucky6969b 6 years, 1 month ago

I want to calculate the position of the camera, but I always get a vector of zeros.


D3DXMATRIX viewMat;
pDev->GetTransform(D3DTS_VIEW, &viewMat);
D3DXMatrixInverse(&viewMat, NULL, &viewMat);
D3DXVECTOR3 camPos(viewMat._41, viewMat._42, viewMat._43);
log->Write( L"Camera Position: %f %f %f\n", camPos.x, camPos.y, camPos.z); 



Could anyone please shed some lights on this?
thanks
Jack
Advertisement

We would first need to see what happen in that GetTransform function.

And secondly we usually build the view matrix from the camera information and not the opposite, you're confusing me a little bit on that part. Can you explain your scenario a little more?

At first blush, I just want to "steal" the camera...

Some cameras are always kept at 0, 0, 0 and the world moves around them.

Set a break point after the GetTransform function and see what the values are before the inverse and see if they make sense.  I'm not a D3D guy so YMMV.

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

If the camera is indeed fixed, how can I estimate the distance between the camera and the geometries in the scene.
What I have on hand is the following information:
1) The vertex positions
2) The world transformations of the geometries
3) Probably the camera is at 0,0,0 then
thanks
Jack

This topic is closed to new replies.

Advertisement