Easy camera? (opengl)

Started by
2 comments, last by hplus0603 18 years ago
Whats the best way to make camera, which can be placed/moved almost freely? I used this functions from Lighthouse's tutorial:

void orientMe(float ang) 
{
    lx = sin(ang);
    lz = -cos(ang);
    glLoadIdentity();
    gluLookAt(x, y, z, 
          x + lx,y + ly,z + lz,
      0.0f,1.0f,0.0f);
}

void moveMeFlat(int direction) 
{
    x = x + direction*(lx)*0.1;
    z = z + direction*(lz)*0.1;
    glLoadIdentity();
    gluLookAt(x, y, z, 
          x + lx,y + ly,z + lz,
      0.0f,1.0f,0.0f);
}


They do fine, but I don't know how to use them to set an TPP-like camera. I think it has something with 3 last parameters of gluLookAt, the tilt ones, but I don't know how to modify it. Also I would like the cam to focus on one point (the main character). thank you EDIT: Could someone move it to the OpenGL forum? [Edited by - Hand_Of_Destruction on April 1, 2006 10:10:37 AM]
Advertisement
I think the easiet way to make a good simple camera(as long as gimble lock won't get in your way) is to use gluLookAt and in the camera class, have a couple of vectors representing UP, RIGHT, and FORWARD. When you need to rotate, you rotate these vectors upon each other. For example, to rotate pitch, you rotate the UP and FORWARD vectors according to the RIGHT vector. Then use these vectors to create the parameters for the gluLookAt function. The only issue is that the forward vector won't go, rather the position+FORWARD because gluLookAt takes the position you are in, the position you are looking at(not forward vector, rather an acual 3d position) and the UP vector. The only reason to have the RIGHT vector is fro strafing and having the vector to pitch around.


You might also look here:
http://www.codecolony.de/opengl.htm

He has two camera examples. One simple and one advanced. I don't know how they compare to the glLookAt() function stuff, but I just finished my camera class, which follows the first example.
Try my simple GL camera example which probably goes well with my simple scene drawing example.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement