Sign in to follow this  
Maverick Programmer

Camera needs another variable?

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);
	glLoadIdentity();
	gluLookAt(x, y, z, x + _lookX, y + _lookY, z + _lookZ, 0.0f,1.0f,0.0f);
}

void LookCamera(float newAngle) {

	_lookY = -sin(newAngle);

	glLoadIdentity();
    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 this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this