#### Archived

This topic is now archived and is closed to further replies.

# Still having trouble with gluLookAt

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

## Recommended Posts

Hi, About a month ago a posted a question about having trouble rotating the camera with gluLookAt(); And I am still having trouble Can someone please explain to me how to accomplish this?... i thought i read somewhere that you add cos(anangle) to your Lookat.x ,and sin(anangle) to lookat.z, but i have yet to get this to work Thanks, Jack

##### Share on other sites
You can do this with gluLookAt but it seems like glRotate/glTranslate would be easier here.

##### Share on other sites
Im going to try and help, but bear with me, i lost all my code a while back, and havent got around to makeing my camera class a while back.

first we need a matrix that denotes the cameras transformed positioning.

struct cams{
float m[16];
};

then we need some variables that hold the camreras rotation around the x and y axis.

struct cams{
float m[16];
float x;
float y;
};

then we will need a speed rateing, which will determine how far to move the camera forward.

struct cams{
float m[16];
float x;
float y;
float speed;
};

then we need an update function that we will call every frame.

struct cams{
float m[16];
float x;
float y;
float speed;
virtual void update();
};

now declare the camera class

cams cam;

Now in the function we need to first load the identity matrix, then multiply by the old camera matrix, then rotate around the two axis, then move forward.

void cams::update() {
//first push the current matrix so you can come back to it
glPushMatrix();
glMultMatrix(cam.m);
glRotatef(cam.x,1,0,0);
glRotatef(cam.y,0,1,0);
glTranslatef(0,0,cam.speed);
//new we save the new matrix
glGetFloatv(GL_MODELVIEW,cam.m);
//then lets pop the matrix back to where we were
glPopMatrix();
}

Now all we need to do to draw an object relatave to the camera is call

glMultMatrix(cam.m);
move_to_and_draw_object();

Now all we need is some keyboard commands that will modify the x y and z values.

Working from memory, i think this is how i used to work a camera. it will be fine as long as you dont try and rotate around the z axis. It may be missing something though.