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);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//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);
glMatrixMode(GL_MODELVIEW);
}
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()
{
//glMatrixMode(GL_PROJECTION);
//gluPerspective(45.0, 1.0, 0.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
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..
");
glutDestroyWindow(window_name);
exit(0);
break;
case 102: //letter f
Camera();
break;
default:
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(Xsize, Ysize);
glutInitWindowPosition(0,0);
window_name = glutCreateWindow("Model of an ATOM");
//Initialise window
InitWindow(Xsize, Ysize);
//Callback functions (Resize & Draw screen)
glutReshapeFunc(ResizeScene);
glutIdleFunc(DrawScene);
//Callback function when a key is pressed
glutKeyboardFunc(NormalKey);
glutMainLoop();
return 1;
}
[/b]
[/b][/QUOTE]