Creating a camera's rotation matrix.

Started by
1 comment, last by Enerjak 12 years, 4 months ago
Ok, im having a little problem right now. See I'm trying to build a camera that can rotate but seeing at I'm not that good at Rotation (well, Rotation for models works good so i don't know.) anyways here is my camera update function:







void IrrCamera::draw()
{

// Matrices.
D3DXMATRIX m_View;
D3DXMATRIX m_Proj;
D3DXMATRIX m_World;

IrrRenderSystemD3D9* d9 = reinterpret_cast<IrrRenderSystemD3D9*>(IrrRenderList::getSingletonPtr()->getRenderSystemByName("Direct3D9"));

// set the view matrix.
D3DXMatrixLookAtLH(&m_View,&m_position,&m_lookAt,&D3DXVECTOR3(0,1,0));

d9->getDevice()->SetTransform(D3DTS_VIEW,&m_View);

// set perspective.
D3DXMatrixPerspectiveFovLH(&m_Proj,m_fov,m_AspectRatio,m_near,m_far);

d9->getDevice()->SetTransform(D3DTS_PROJECTION,&m_Proj);

float Y = D3DXToRadian(m_rotation.y);
// set Matrix Rotation.
D3DXMatrixRotationAxis(&m_World,&m_rotation,Y);

float X = D3DXToRadian(m_rotation.x);
D3DXMatrixRotationX(&m_World,X);

d9->getDevice()->SetTransform(D3DTS_WORLD,&m_World);


}






there are helper function to set all the properties of the camera, the look at pos, the position, aspect ratio, ect. I can't get the camera to rotate at all. any advice, code snippet would be welcomed. hell even a tutorial on rotations and how to get them to work would be appreciated.


Advertisement
Your problem is that you're setting the world matrix in the function. It helps me to think of the world matrix as a property of every renderable in your game (ie. every model has one that stores the position, orientation and scale of the entity) and then the camera is responsible for contributing the view and projection matrices (which stores the camera's position and orientation(!) and, in the projection matrix, the aspect ratio, fov and so on).

So, scrap that whole world matrix part in your function and instead rotate your camera by altering the look-at point in your call to D3DXMatrixLookAtLH. If you have problems doing that, google any Direct3D/XNA camera tutorial. I've done the same in the past and there's plenty resources out there that give you the code to implement a standard camera.

Hope this helped!

Your problem is that you're setting the world matrix in the function. It helps me to think of the world matrix as a property of every renderable in your game (ie. every model has one that stores the position, orientation and scale of the entity) and then the camera is responsible for contributing the view and projection matrices (which stores the camera's position and orientation(!) and, in the projection matrix, the aspect ratio, fov and so on).

So, scrap that whole world matrix part in your function and instead rotate your camera by altering the look-at point in your call to D3DXMatrixLookAtLH. If you have problems doing that, google any Direct3D/XNA camera tutorial. I've done the same in the past and there's plenty resources out there that give you the code to implement a standard camera.

Hope this helped!




thank you very much, i'll look into it.

This topic is closed to new replies.

Advertisement