Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

gluLookAt problem

This topic is 5710 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to move forward when the w key is pressed. Can someone tell me what is not working here?
    
#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;
}
    
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]

Share this post


Link to post
Share on other sites
Advertisement
xg0blin-

1. Make sure that the three lines of code in the ''w'' case are actually being called. (Just a printf would do).

2. Why is the eye giong one way and the focus the other?? they should both be += or -=.

That is about all I can see that should need changing.


Doolwind

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!