Original Post
Hi all: I drawed two objects in the scene. I want a rectangle to be ground which can't move. And another object can move and rotate. And I want the camera to be able to zoom in, zoom out and rotate etc. My code is like following: But when I press the up and down key, it doesn't work. It seems that the camera doesn't move at all. Could anybody tell me how to solve this please??? Thanks very much!!! [Edited by - Asuralm on April 12, 2006 2:12:06 PM]
float objectX = 0;
float objectY = 0;
float objectZ = 0;
float cameraX = 0;
float cameraY = 0;
float cameraZ = 100;
float lookAtX = 0;
float lookAtY = 0;
float lookAtZ = -1;
float xangle, yangle, zangle;
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0); // Set display-window color to white.
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor4f(1.0, 1.0, 0.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(objectX, objectY, objectZ);
glRotatef(xangle, 1, 0, 0);
glRotatef(yangle, 0, 1, 0);
glRotatef(zangle, 0, 0, 1);
DrawObject1();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
DrawGround();
glFlush();
glutSwapBuffers();
glutPostRedisplay();
}
void reshapeFcn(GLint newWidth, GLint newHeight)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, newWidth, newHeight);
if (newHeight == 0)
newHeight = 1;
gluPerspective(120.0, newWidth / newHeight, 1, 1000);
gluLookAt(cameraX, cameraY, cameraZ,
lookAtX, lookAtY, lookAtZ,
0, 1, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
winWidth = newWidth;
winHeight = newHeight;
}
void moveMeFlat(int i) {
cameraX += i * lookAtX;
cameraZ += i * lookAtZ;
glLoadIdentity();
gluLookAt(cameraX, cameraY, cameraZ,
cameraX + lookAtX, cameraY + lookAtY, cameraZ + lookAtZ,
0.0f,1.0f,0.0f);
}
void SpecialKeyFunc(int key, int x, int y){
switch (key) {
case GLUT_KEY_UP : moveMeFlat(-1);break;
case GLUT_KEY_DOWN : moveMeFlat(1);break;
}
}