Sign in to follow this  

OpenGL camera

This topic is 3302 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
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

This topic is 3302 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.

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