Archived

This topic is now archived and is closed to further replies.

stefan5000

What's wrong with my camera-code?

Recommended Posts

Hi everyone! I''m currently workinf on a free camera code. But it doesn''t work correctly! My camera should move in the direction it is currently viewing. But that''s NOT the problem! The problem is that when I''m turning around the camera sometimes turns along the wrong axis! I want to be able to yaw, pitch and roll around the camera''s axis! But what''s wrong with my code? D3DXMATRIX Translation; D3DXMatrixTranslation(&Translation,0.0f,0.0f,0.0f); D3DXMATRIX Rotation; D3DXMatrixRotationYawPitchRoll(&Rotation,(CameraPan*Math::rad), CameraTilt*Math::rad),(CameraRoll*Math::rad)); D3DXMATRIX View; D3DXMatrixMultiply(&View,&Translation,&Rotation); Direct3D::D3DDevice->SetTransform(D3DTS_VIEW,&View); Thanks for any help! (Please don''t say that I should search on google! I searched now one week, but couldn''t find any helpful things!)

Share this post


Link to post
Share on other sites
Hi again!

I wasn''t stopping searching for answers and I found now the right code:


D3DXMATRIX m_matOrientation;
D3DXMATRIX m_matView;

D3DXQUATERNION qR;

D3DXQuaternionRotationYawPitchRoll(&qR, (CameraPan*Math::rad),(CameraTilt*Math::rad),(CameraRoll*Math::rad));

D3DXMatrixAffineTransformation(&m_matOrientation, 1.25f, NULL, &qR, &D3DXVECTOR3(CameraX,CameraY,CameraZ));

D3DXMatrixInverse( &m_matView, NULL, &m_matOrientation );

Direct3D::D3DDevice->SetTransform(D3DTS_VIEW,&m_matView);


Now it works fine!

Share this post


Link to post
Share on other sites