Original Post
I am trying to move forward when the w key is pressed. Can someone tell me what is not working here?
my display is ok, but for some reason, when I hit w, my position isn't changing. Any suggestions?
[edited by - xg0blin on October 2, 2002 11:37:48 PM]
#include <stdlib.h>
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <glut.h>
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glut32.lib")
struct Vertex3d
{
GLdouble x, y, z;
}Eye, Focus, Up;
void Init(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f);
Eye.x = 0.0f, Eye.y = 0.0f, Eye.z = 1.0f;
Focus.x = 0.0f, Focus.y = 0.0f, Focus.z = -15.0f;
Up.x = 0.0f, Up.y = 1.0f, Up.z = 0.0f;
glViewport(0, 0, 1024, 768);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0f, 3/4, 1, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void MyDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(Eye.x, Eye.y, Eye.z, Focus.x, Focus.y, Focus.z, Up.x, Up.y, Up.z);
glBegin(GL_TRIANGLES);
glVertex3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, 0.0f, 0.0f);
glEnd();
glutSwapBuffers();
}
void MyKeyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 'w':
Eye.z += 5;
Focus.z -= 5;
break;
case 's':
break;
case 'q':
case 'Q':
exit(0);
break;
default:
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("Cameron");
glutFullScreen();
Init();
glutKeyboardFunc(MyKeyboard);
glutDisplayFunc(MyDisplay);
glutMainLoop();
return EXIT_SUCCESS;
}