The near and far planes for gluPerspective are measured from the camera “eye.” So, if I change the direction of the “at” vector for gluLookAt, the two planes will be in the direction of the “at” point and will be measured from the “eye” point, right?
Thank you helping me.

Hum…
gluPerspective(angle of view, h/w ratio, near, far)
gluLookat(eye point, direction to look at, rotation of view)

The view area is a box with near being the face near the camera and far end of box.
Since the view is set by a angle the box on the near end is smaller and gets bigger at the end of the box.

Now what glulookat does is just rotates/translates the view box, based on eye-position, at and camera rotation.

I hope this helps

Originally posted by New kid on the board:
The near and far planes for gluPerspective are measured from the camera “eye.” So, if I change the direction of the “at” vector for gluLookAt, the two planes will be in the direction of the “at” point and will be measured from the “eye” point, right?
Thank you helping me.

Here is my problem: we are supposed to walk around in a 3d work. I’m using gluLookAt to move the camera around. It seems logical to move the camera around. The problem is, when I move towards or the side of the cube, the cube looks distorted. It look longer and just plain messed up. Why is that happening? Is it better to use the gl transformations functions, or can I somehow use gluLookAt?

#include <iostream.h>
#include <GL/glut.h>

// array that holds the position of the camera
GLdouble eye[3];

//array that holds the direction of where the camera is pointing to
GLdouble at[3];

void init();
void display();
void keyboard(unsigned char, int, int);
void arrow_keys(int, int, int);
void orig_camera_vals(void);

int main()
{
orig_camera_vals();
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1024, 768);
glutInitWindowPosition(0, 0);
glutCreateWindow(“Homework 4”);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc(arrow_keys);
init();
glutMainLoop();

``````return 0;
``````

}

void init()
{
GLfloat whiteLight[] = { 0.45f, 0.45f, 0.45f, 1.0f };
GLfloat sourceLight[] = { 0.25f, 0.25f, 0.25f, 1.0f };
GLfloat lightPos[] = { -50.f, 25.0f, 250.0f, 0.0f };

``````glEnable(GL_DEPTH_TEST);	// Hidden surface removal
glFrontFace(GL_CCW);		// Counter clock-wise polygons face out
glEnable(GL_CULL_FACE);		// Do not calculate inside of jet

// Enable lighting
glEnable(GL_LIGHTING);

// Setup and enable light 0
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,whiteLight);
glLightfv(GL_LIGHT0,GL_AMBIENT,sourceLight);
glLightfv(GL_LIGHT0,GL_DIFFUSE,sourceLight);
glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
glEnable(GL_LIGHT0);

// Enable color tracking
glEnable(GL_COLOR_MATERIAL);

// Set Material properties to follow glColor values
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);

glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);

gluPerspective(145.0, 1024.0/768.0, 1.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
``````

}

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
gluLookAt(eye[0], eye[1], eye[2], at[0], at[1], at[2], 0.0, 1.0, 0.0);

``````glTranslatef(100.0, 50.0, 100.0);

glColor3f(1.0, 1.0, 0.0);
glutSolidCube(50.0);

glutSwapBuffers();
``````

}

void orig_camera_vals(void)
{
at[0] = at[1] = eye[0] = 100.0;
eye[1] = 100.0;
eye[2] = 500.0;
at[2] = 100.0;
}

void arrow_keys(int key, int x, int y)
{
// move forward some units
if(key == GLUT_KEY_UP)
eye[2] -= 5.0;

``````// move  backward units
if(key == GLUT_KEY_DOWN)
eye[2] += 5.0;

// move left some units
if(key == GLUT_KEY_LEFT)
at[0] -= 5.0;

// move right some units
if(key == GLUT_KEY_RIGHT)
at[0] += 5.0;

glutPostRedisplay();
``````

}

void keyboard(unsigned char key, int x, int y)
{
// go back to original settings
if(key == ‘c’ | | key == ‘C’)
orig_camera_vals();

``````// quit the programs
if(key == 'q' | | key == 'Q')
exit(1);

glutPostRedisplay();
``````

}

I fixed the distortion problem by changing the field of view to 45. I had it at 120 because that’s our field of vision. But would it be easier to implement the program using the gl transformation functions or using gluLookAt?

that totally depends on how you move… when you use lookat you need an aimpoint which is nice some times but can be a hell in other situations. So i have no real answer

I’m just moving around in a 3D world–kind of a low grade version of Quake, I guess.

You can use transformations in place of gluLookAt.

glTranslatef( ); // move camera
// Rotate camera
glRotatef(rotate_x, 1.0, 0.0, 0.0);
glRotatef(rotate_y, 0.0, 1.0, 0.0);
glRotatef(rotate_z, 0.0, 0.0, 1.0);

glPushMatrix();

// Draw Object here

glPopMatrix();
// Repeat above push/pop for each object.

or with
gluLookAt(player view, direction_lookint_at, rotation of view)

Originally posted by Not very old kid:
I fixed the distortion problem by changing the field of view to 45. I had it at 120 because that’s our field of vision. But would it be easier to implement the program using the gl transformation functions or using gluLookAt?

[This message has been edited by nexusone (edited 10-26-2002).]

[This message has been edited by nexusone (edited 10-27-2002).]

Why do I have to rotate about the x, y, and z axises? If I am moving about the x-z plane, should I rotate only the y-axis?

Is glLookAt similar to gluLookAt? Or is it just a typo?

It’s a typo. Just use gluLookAt if it works for your needs. No need to complicate things if you don’t need it.

Well the player my want to look right or left (x-axis rotation) or maybe up and down (y-axis rotation), or look as if he is standing on his head (z-axis rotation)…

Translate x-axis (move to the right/left, strif(sp) sometimes refered to as, translate y axis, jump, climb. z-axis forward/backwards move.

Originally posted by So confused:
Why do I have to rotate about the x, y, and z axises? If I am moving about the x-z plane, should I rotate only the y-axis?