View Full Version : I need help with some FPS camera control code

09-02-2009, 12:43 AM
I'm currently using this code:

There seems to be a bug in the code, but I cannot locate it. You can replicate the bug by holding the mouse button down in the window and moving the mouse up and down rapidly. What should happen is the view shakes, but the overall orientation stays the same. What actually happens is the camera slowly rolls and pans to the right.

I've commented out the code responsible for panning (rotating around the up vector), thereby only allowing for up and down camera movements and it is definitely in the portion of code that rotates the camera along the x axis.

There is something very wrong here, but I am at a loss as to what. I tried the DirectX version of the same code and this problem does not show up. I don't know if this is a driver issue (doubtful), a bug in GL (VERY doubtful) or a problem with some part of this code. If it is a bug in the code, and it really only can be, I cannot find it.

I really need to implement this in my game engine and I know it can be done in GL. Just cannot seem to get it to work...

09-02-2009, 01:37 AM
"holding the mouse button down in the window and moving the mouse up and down rapidly"
how rapidly do you move your mouse? i can't reproduce anything. just a shaking view here.

09-02-2009, 11:58 AM
Very rapidly. I did this because I started noticing the view drifting off after a period of time and tried to speed it up. It worked.

Here is the code and binary that shows where I'm at:

I've changed very little. What I've done is made the window full screen (1920x1080), eliminated the need to hold down the mouse button and to demonstrate the problems, commented out the code that allows the camera to pan. The camera can only move up and down with the mouse. Shaking the camera in this will clearly demonstrate the problem.

09-02-2009, 08:22 PM
Well, I narrowed the problem down to the matrix4x4f::rotate function.

I changed it to this:

void matrix4x4f::rotate( const float &angle, vector3f &axis )

glMatrixMode( GL_MODELVIEW );



and it now works. Of course, this solution is not optimal, but at least I know where to go from here. Obviously, there is a problem with the rotation matrix.