I have created a simple camera class, moved it from my C# (XNA) source to C++ for d3d.
Commonly it is okay, but something is wrong with rotation. If i increase its pitch/yaw values, according to received player's mouse delta (cursor move), it rotates incorrect. It rotates 'around' 'world center', not position. 'world center' is changed if i change camera position.
After i move mouse left, camera is rotated like around 0;0;0 instead of own position.
XMVECTOR m_vecPosition; // x,y,z camera pos float m_fYaw, m_fPitch;// rotation
view matrix update function:
#define VectorForward XMVectorSet(0,0,1,0) XMMATRIX mtxRot = XMMatrixRotationRollPitchYaw(m_fPitch, m_fYaw, 0); XMVECTOR vecPos = XMVector3Transform(m_vecPosition, mtxRot); XMVECTOR vecLookAt = XMVector3Transform(VectorForward, mtxRot);//'forward' transformed vecLookAt += vecPos; XMVECTOR vecUp = XMVector3Transform(VectorUp, mtxRot); m_mtxView = XMMatrixLookAtLH(vecPos, vecLookAt, vecUp);
In XNA project my camera worked fine, like in FPS games, but it is impossible to move it to C++, this code definitely not correct.
And another question about camera if some one could help me:) Do i need to limit(lock) picth,yaw abs to PI*2 ? Or i what i need to do with always increasing yaw, for example ?
My camera rotates around 0;0;0, not around its position. Rotation camera makes always its look-at in center of the world. If i move camera position, i can offset its 'relative world center'. I need to make my camera properly first person, or properly third person..