Jump to content
  • Advertisement
Sign in to follow this  
Maverick Programmer

Camera needs another variable?

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

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!