• 13
• 18
• 19
• 27
• 10

Why is my camera all jumpy? What can I do to fix it?

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

Recommended Posts

Hi, I have a strange problem. My code for my camera works fine, but after a while, it 'jumps' around when I try to move the view. Here is are the primary functions:
void RotateCamera(float newAngle) {

_lookX = -sin(newAngle);
_lookZ = cos(newAngle);
gluLookAt(x, y, z, x + _lookX, y + _lookY, z + _lookZ, 0.0f,1.0f,0.0f);
}

void LookCamera(float newAngle) {

_lookY = -sin(newAngle);
_lookZ = cos(newAngle);

gluLookAt(x, y, z, x + _lookX, y + _lookY, z + _lookZ, 0.0f,1.0f,0.0f);

}

void MoveCamera(int newDir) {

x = x + newDir*(_lookX)*SPEED_AMOUNT;
z = z + newDir*(_lookZ)*SPEED_AMOUNT;
gluLookAt(x, y, z, x + _lookX, y + _lookY, z + _lookZ, 0.0f,1.0f,0.0f);
}

void StrafeCamera(int newDir)
{
x = x + newDir*(-_lookZ)*SPEED_AMOUNT;
z = z + newDir*(_lookX)*SPEED_AMOUNT;
gluLookAt(x, y, z, x + _lookX, y + _lookY, z + _lookZ, 0.0f,1.0f,0.0f);
}

void HandleMouse(int x, int y)
{
if(x < mouse_x)
{

Angle=TURN_AMOUNT;
glutWarpPointer(window_w/2, window_h/2);//}
}
else if(x > mouse_x)
{

Angle=-TURN_AMOUNT;
glutWarpPointer(window_w/2, window_h/2);//}
}
if(y < mouse_y)
{
CamRot=TURN_AMOUNT;
glutWarpPointer(window_w/2, window_h/2);//}
}
else if(y > mouse_y)
{
CamRot=-TURN_AMOUNT;
glutWarpPointer(window_w/2, window_h/2);
}

mouse_x =x;
mouse_y =y;

}


Here is the main cycle:
void update(int value) {

if(Angle!=0&&!isStrafing)
{
_angle+=Angle;
RotateCamera(_angle);
Angle=0;
}

if(CamRot!=0)
{
_camRot+=CamRot;
LookCamera(_camRot);
CamRot=0;
}

if(Direction!=0)
{
MoveCamera(Direction);
}

if(StrafeDirection!=0&&isStrafing)
{
StrafeCamera(StrafeDirection);
}

glutPostRedisplay();
glutTimerFunc(25, update, 0);
}


I'm sure it has something to do with the math. Thus, I posted it here. Thanks in advanced.

Share on other sites
Clarify "jumps". A jump could be anything between a twitch and a 180.

Share on other sites
Are the arguments for RotateCamera and LookCamera given in radians?