Alright seems to be working like it should. Though after following the FAQ it seemed like I got the inversion of the rotation. Might be that I handle camera space wrong or something, or since it is camera space I have to invert it to get it right. Anyway I just inverted the vector before setting it and it worked just fine.
void GGE::Graphics::Camera::SetRotationMatrix( const Matrix33f &aRotation )
{
Vector3f angles = Vector3f::Zero;
angles.y = asin( aRotation.myData[ INDEX3( 2, 0 ) ] );
float c = cos( angles.y );
if( fabs( c ) > 0.005f )
{
float tempX = aRotation.myData[ INDEX3( 2, 2 ) ] / c;
float tempY = -aRotation.myData[ INDEX3( 2, 1 ) ] / c;
angles.x = atan2( tempY, tempX );
tempX = aRotation.myData[ INDEX3( 0, 0 ) ] / c;
tempY = -aRotation.myData[ INDEX3( 1, 0 ) ] / c;
angles.z = atan2( tempY, tempX );
}
else
{
angles.x = 0;
float tempX = aRotation.myData[ INDEX3( 1, 1 ) ];
float tempY = aRotation.myData[ INDEX3( 0, 1 ) ];
angles.z = atan2( tempY, tempX );
}
SetRotation( angles * -1 );
}
void GGE::Graphics::Camera::LookAt( const Vector3f aCenter, const Vector3f aUp )
{
Vector3f forward = (aCenter - myPosition).Normalize();
Vector3f side = forward.Cross( aUp.Normalize() );
Vector3f up = side.Cross( forward );
Matrix33f rotation;
rotation.myData[ INDEX3( 0, 0 ) ] = side.x;
rotation.myData[ INDEX3( 1, 0 ) ] = side.y;
rotation.myData[ INDEX3( 2, 0 ) ] = side.z;
rotation.myData[ INDEX3( 0, 1 ) ] = up.x;
rotation.myData[ INDEX3( 1, 1 ) ] = up.y;
rotation.myData[ INDEX3( 2, 1 ) ] = up.z;
rotation.myData[ INDEX3( 0, 2 ) ] = -forward.x;
rotation.myData[ INDEX3( 1, 2 ) ] = -forward.y;
rotation.myData[ INDEX3( 2, 2 ) ] = -forward.z;
SetRotationMatrix( rotation );
}
Do you see anything Laurent you think should be improved? Maybe even know why the vector is inverted. Also if you see anything in my interface/API you feel should be changed then just let me know. My engine is still in alpha stage so I love any comments I can get.