Sign in to follow this  
repka3

My implementation of 3rd person camera.

Recommended Posts

Hi all, I'm new in game programming and i want to post you my implementation of 3rd person camera DAOC style or WoW style and ask you something. float yAngle = gDInput->mouseDX() / 200.0f; float pitch = gDInput->mouseDY() / 200.0f; // Create Rotation matrix R with rotation around "Right Camera vector" and around Y world vector D3DXMATRIX R; D3DXMatrixRotationAxis(&R, &mRightW, pitch); D3DXMATRIX L; D3DXMatrixRotationY(&L, yAngle); D3DXVec3TransformCoord(&mRightW, &mRightW, &L); R=R*L;//sum the trasformation //keep the char in center of view by moving eye and target pos while he is moving. D3DXVECTOR3 delta_char_Wpos=charWpos-old_charPosw; m_EyePos+=delta_char_Wpos; targetWpos+=delta_char_Wpos; //trasform eye (camera) position rotating around charwpos D3DXVECTOR3 fromPointToEye=m_EyePos-charWpos; D3DXVec3TransformCoord(&fromPointToEye,&fromPointToEye,&R); //trasform target position rotating around charwpos D3DXVECTOR3 fromPointToTarget=targetWpos-charWpos; D3DXVec3TransformCoord(&fromPointToTarget,&fromPointToTarget,&R); //make eye and target relative to char world position m_EyePos=charWpos+fromPointToEye; targetWpos=charWpos+fromPointToTarget; D3DXVECTOR3 m_UpVector(0, 1, 0); D3DXMatrixLookAtLH(&mView, &m_EyePos, &targetWpos, &m_UpVector); old_charPosw=charWpos; //save char pos for finding delta pos at next loop Everything work fine but i think this is not right way cause for examples if i want to limit the max pitch of camera there is no simple way. What do you think about this implementation? Need i to find a better way? Thx all who will answer..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this