I (reluctantly) copied the code from the main site to turn the camera on the x and y axes and from there also built a couple more commands that made the camera strafe left and right. The forward, back, left, right, and 360 degree turning via the mouse worked perfectly. Then I decided to add the z axis rotation to roll the camera and now when I move left or right, there is an unwanted transformation in there.
The following code is all in the main loop with all the fCameraAngle floats initialized before the main loop.
if ( dbKeyState ( DIK_W ) )
dbMoveCamera ( 0.5 );
// move the camera backwards
if ( dbKeyState ( DIK_S ) )
dbMoveCamera ( -0.5 );
//move the camera left
if ( dbKeyState ( DIK_A ) )
{
dbYRotateCamera ( dbWrapValue ( fCameraAngleY - 90 ) );
dbMoveCamera ( 1 );
dbYRotateCamera ( dbWrapValue ( fCameraAngleY + 90 ) );
}
//move the camera right
if ( dbKeyState ( DIK_D ) )
{
dbYRotateCamera ( dbWrapValue ( fCameraAngleY + 90 ) );
dbMoveCamera ( 1 );
dbYRotateCamera ( dbWrapValue ( fCameraAngleY - 90 ) );
}
//roll the camera right
if ( dbKeyState ( DIK_E ) )
fCameraAngleZ = dbWrapValue ( fCameraAngleZ - 1 );
//roll the camera left
if ( dbKeyState ( DIK_Q ) )
fCameraAngleZ = dbWrapValue ( fCameraAngleZ + 1 );
// create a rotation axis based on mouse movement
fCameraAngleX = dbWrapValue ( fCameraAngleX + dbMouseMoveY ( ) * 0.1f );
fCameraAngleY = dbWrapValue ( fCameraAngleY + dbMouseMoveX ( ) * 0.1f );
// rotate camera
dbXRotateCamera ( fCameraAngleX );
dbYRotateCamera ( fCameraAngleY );
dbZRotateCamera ( fCameraAngleZ );
I'm fairly certain I will have to code in 3D math functions to handle the relationship between the 3 axes as the camera is manipulated past simple left / right transformations. Since I've never done anything like that before, any tips on where to start? Or whether or not I'm on to the right idea at all?