Jump to content
  • Advertisement
Sign in to follow this  
lord_balron

OpenGL camera

This topic is 3608 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 stuck trying to find how to implement a camera in opengl. As it stands I have a function to translate it to the coordinates I give, but it doesn't do anything.
void Camera::moveCamera()
{
	glTranslatef(xlocation, ylocation, zlocation);
}

I don't really know what to do...
class Camera
{
public:
	GLfloat xlocation;
	GLfloat ylocation;
	GLfloat zlocation;

	void moveLeft(GLfloat factor);
	void moveRight(GLfloat factor);
	void moveDown(GLfloat factor);
	void moveUp(GLfloat factor);
	void moveCamera();
}camera;

void Camera::moveLeft(GLfloat factor)
{
	xlocation = xlocation - factor;
}

void Camera::moveRight(GLfloat factor)
{
	xlocation = xlocation + factor;
}

void Camera::moveDown(GLfloat factor)
{
	ylocation = ylocation - factor;
}

void Camera::moveUp(GLfloat factor)
{
	ylocation = ylocation + factor;
}

Share this post


Link to post
Share on other sites
Advertisement
If you do glTranslatef when trying to move the camera, the camera is staying in the same place, you are moving everything else....

Search gluLookAt (http://www.opengl.org/sdk/docs/man/)

If you want to have multiple cameras, simply have a camera class similar to the one you have now, and load the values into gluLookAt:


gluLookAt(currentCamera.x, currentCamera.y, currentCamera.z,
currentCamera.LAx, currentCamera.LAy, currentCamera.LAz,
currentCamera.UPx, currentCamera.UPy, currentCamera.UPz);




The values are akl straightforward, except possibly the up vector. That just defines which was is "up". Imagine that your head is in a certain position, and you are looking at something in the distance. If you hang on some monkey bars, with your head in the same position looking at the same point, everything will look reversed. That's all the up vector does. Usually it will be either 0,1,0 or 0,0,1. I tend to prefer 0,1,0 (the y axis being up).

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!