Original Post
Ok ive been raging over this code for a couple of days now.. and im starting to get sick of it. So here i go asking for help. ive got a camera class which takes in a position matrix and then does the following to it before senting it to my graphics component.
void FpsCamera::drawCamera(Graphics *g)
{
VTfloat const offset = 12.f;//given it a default offset...the user cannot chnage this
m_CameraTarget = m_CameraPosition.matrix[3] + m_CameraPosition.matrix[2] * offset;
VTVector4 m_Look = VTVector4::normal( m_CameraTarget - m_CameraPosition.matrix[3] );
VTVector4 m_Right = VTVector4::normal( VTVector4::crossProduct(m_CameraPosition.matrix[1],m_Look));
VTVector4 m_Up = VTVector4::crossProduct(m_Look,m_Right);
m_CameraMatrix.matrix[0].x = m_Right.x; m_CameraMatrix.matrix[0].y = m_Up.x; m_CameraMatrix.matrix[0].z = m_Look.x;
m_CameraMatrix.matrix[1].x = m_Right.y; m_CameraMatrix.matrix[1].y = m_Up.y; m_CameraMatrix.matrix[1].z = m_Look.y;
m_CameraMatrix.matrix[2].x = m_Right.z; m_CameraMatrix.matrix[2].y = m_Up.z; m_CameraMatrix.matrix[2].z = m_Look.z;
m_CameraMatrix.matrix[3].x = -VTVector4::dotProduct3( m_Right, m_CameraPosition.matrix[3]);
m_CameraMatrix.matrix[3].y = -VTVector4::dotProduct3( m_Up, m_CameraPosition.matrix[3]);
m_CameraMatrix.matrix[3].z = -VTVector4::dotProduct3( m_Look, m_CameraPosition.matrix[3]);
g->updateViewMatrix(m_CameraMatrix);
g->updateFOV(m_CurrentFOV);
}
that takes the matrix and creates a lookat matrix from it. to move the camera i use the follow peices of code.
//moving forwards
if(input->checkForIdIsHeld(0))
{
////move forwards
m_Player.matrix[3] += m_Player.matrix[2] * (1.f / m_UpdateRate);
}
//rotating the camera
m_Player *= VTMatrix4x4::rotateAroundAxis(m_Player.matrix[0] ,input->getChangeInMouseY() * ( 1.0f / m_UpdateRate ) );
m_Player *= VTMatrix4x4::rotateAroundAxis(m_Player.matrix[1] , input->getChangeInMouseX() * ( 1.0f / m_UpdateRate ) );
here is also the code for my rotate around a axis
VTMatrix4x4 VTMatrix4x4::rotateAroundAxis(VTVector4 axis, VTfloat angle)
{
//#ifdef _SWFLOAT
// #else
// VTfloat sine = (VTfloat)sin(angle);
// VTfloat cosine = (VTfloat)cos(angle);
// #endif
VTMatrix4x4 temp;
VTfloat cosine( (VTfloat) cos(angle) );
VTfloat sine( (VTfloat) sin(angle) );
VTfloat t = 1.0f - cosine;
temp.matrix[0].x = (t * axis.x * axis.x) + (cosine);
temp.matrix[0].y = (t * axis.x * axis.y) - (axis.z * sine);
temp.matrix[0].z = (t * axis.x * axis.z) + (axis.y * sine);
temp.matrix[1].x = (t * axis.x * axis.y) + (axis.z * sine);
temp.matrix[1].y = (t * axis.y * axis.y) + (cosine);
temp.matrix[1].z = (t * axis.y * axis.z) - (axis.x * sine);
temp.matrix[2].x = (t * axis.x * axis.z) - (axis.y * sine);
temp.matrix[2].y = (t * axis.y * axis.z) + (axis.x * sine);
temp.matrix[2].z = (t * axis.z * axis.z) + (cosine);
return temp;
}
the code works fine...when only one rotation is used, in either x or y but when other are put together the camera goes mad.. see If anyone could point me in the right direct i would be very happy