OpenGL camera problem

Hi all,

Wondering if u can help me out:

I am trying to get the camera to move to a particular location in my scene, but the problem is that it only works if I use gluLookAt with the projection matrix and NOT the modelview matrix.

Isnt this supposed to be bad?

how can i get it to work with modelview matrix.

code shown below…problem is encountered in the normal key method when typing in key “f” as nothing happens!

[b]#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <math.h>

#define ESCAPE 27 //use escape key to exit program

GLint Xsize = 400;
GLint Ysize = 400;
GLint window_name; //name of our window
GLfloat xRot = 10.0f;
GLfloat yRot = 0.0f;
GLfloat zRot1 = -100.0f;
GLfloat yRot1 = 15.0f;
GLfloat Elect, Elect1, Elect2 = 0.0f;
GLfloat xdirection, ydirection;

GLvoid InitWindow(GLfloat Width, GLfloat Height)
    glViewport(0, 0, Width, Height);
    //glOrtho(-100.0, 100.0, -100.0 / (Width / Height), 100.0 / (Width / Height), -1.0, 10.0);    
    gluPerspective(45.0,Width/Height,0.0, 200.0); //push object away ffrom origin
    //gluLookAt(9.0f, 0.0f, -100.0f, 0.0f, 0.0f, -100.0f, 0.0f, 1.0f, 0.0f);

GLvoid ResizeScene(GLint Width, GLint Height)
    if (Height == 0) Height = 1; //prevent division by zero
    if (Width == 0) Width = 1; 
    InitWindow(Width, Height); //reset perspective projection

GLvoid Camera()
    //gluPerspective(45.0, 1.0, 0.0, 100.0);
    gluLookAt(9.0f, 0.0f, 100.0f, 0.0f, 0.0f, 100.0f, 0.0f, 0.0f, 1.0f);

void NormalKey(GLubyte key, GLint x, GLint y)
    switch( key)
        case ESCAPE:
            printf("Escape pressed, exiting..

        case 102: //letter f

int main(int argc, char **argv)
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowSize(Xsize, Ysize);    
    window_name = glutCreateWindow("Model of an ATOM");
    //Initialise window
    InitWindow(Xsize, Ysize);    
    //Callback functions (Resize & Draw screen)
    //Callback function when a key is pressed    
    return 1;

first, you don’t set 0 for the near plane distance, otherwise you will see awful artifacts.
Second, it is not the full code, isn’t it? You set DrawScene as the idle function that looks weird, you should at least set it as the display function with glut.
Finally read about the nature of modelview and projection matrices in the gl spec (“Coordinates transformation” paragraph). You will see that gluLookAt is related to the projection matrix, it just change the view. Anyway, what you are doing with gluLookAt in your code looks correct… just check you have something to watch at the location specified in gluLookAt.

problem solved.