Jump to content
  • Advertisement
Sign in to follow this  
Enerjak

Creating a camera's rotation matrix.

This topic is 2567 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.


Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!