# Camera needs another variable?

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

## Recommended Posts

I'm trying to get my 'camera' to be able to in in a circle, up-to-down, when my mouse keeps going up or down, and for my camera to go in a circle ,left-to-right, when my mouse moves left or right.
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);

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

}

void MoveCamera(int newDir) {
/*Not the problem*/
}

void StrafeCamera(int newDir)
{
/*Not the problem*/
}

void HandleMouse(int x, int y)
{
/*Not the problem*/
}


So far my program works fine, I have strafing, moving, and I can go in a 'circle' when my mouse moves from left to right. When I try to do this going up, my camera goes upward, but then reverses and goes down, then reverses and goes up, etc... I know it has to be something with the LookCamera(... ) function. At first, I had _lookZ = cos(newAngle) in the LookCamera(... ) function, but that confused the variable since it was being used in two places. Since I removed it, the program has worked fine. What should I do to get my camera to be able to look upward 'forever' like my camera can look sideways 'forever'? I know it has something to do with the math (thus why I put it here). Thanks in advanced.

##### Share on other sites
I suspect LookCamera to be correct without the cos term, since it alters just _one_ co-ordinate due to an angle. Rotations should ever affect 2 co-ordinates (see the definition of rotation matrices).

Probably your problem arises from the fact that you compute 2 absolute and concurrent look-at positions. From the OP I assume that you control in any way the main direction along which the camera looks, and want to alter that main direction slightly by a "look around"? So you have to to treat the second look as a _local_ transformation.

You should consider to maintain the camera transformation yourself instead of using gluLookAt in this situation.

##### Share on other sites

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

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628710
• Total Posts
2984325

• 23
• 11
• 9
• 13
• 14