Skip to main content
gamedev.net
🔒 Locked

Beginner problem

Started by dpadam450 Jan 25, 2006 at 6:28 PM 3 replies 950+ views
Original Post
dpadam450
dpadam450
Ok I tried a new project with gluLookAt() and it still messes up. Here is my code. If it doesnt make sense copy/paste it and run it. It's hard to explain what happens but when you hit down. You move away from the object. When you hit up, you move closer to the object, then it goes behind me and flips about the y-axis. glEnable(GL_DEPTH_TEST); glClearColor (.4f, 0.0f, .5f, 0.0f); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,1,.1f,50.0f); //move was declared as an int = to 3 gluLookAt(0,0,move, 0,0,-1, 0,1,0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glBegin(GL_QUADS); //front glColor3f(1,0,0); glVertex3f(0,0,0); glVertex3f(1,0,0); glVertex3f(1,1,0); glVertex3f(0,1,0); //top glColor3f(0,1,0); glVertex3f(0,1,0); glVertex3f(0,1,-1); glVertex3f(1,1,-1); glVertex3f(1,1,0); //right glColor3f(1,1,1); glVertex3f(1,0,0); glVertex3f(1,1,0); glVertex3f(1,1,-1); glVertex3f(1,0,-1); //left glColor3f(1,1,1); glVertex3f(0,0,0); glVertex3f(0,1,0); glVertex3f(0,1,-1); glVertex3f(0,0,-1); glEnd(); if(GetAsyncKeyState(VK_DOWN)) { move++; } if(GetAsyncKeyState(VK_UP)) { move--; } SwapBuffers (hDC);
NBA2K, Madden, Maneater, Killing Floor, Sims 
Zakwayda
Zakwayda
Quote:
When you hit up, you move closer to the object, then it goes behind me and flips about the y-axis.
That sounds more or less like what should happen (well, you should flip about the y axis when you go past it). What behavior are you looking for?

[Edit: this may or may not be having an effect, but the gluLookAt() call should go after glMatrixMode(GL_MODELVIEW) and glLoadIdentity().]
dpadam450
dpadam450
Well the camera should only move along the z-axis and for some reason once the camera passes the x-axis it brings the object back on the screen when it should just be farther behind the camera. I did try using modelview but it didnt even move the camera.
NBA2K, Madden, Maneater, Killing Floor, Sims 
dpadam450
dpadam450
Wow, nevermind. I thought the 2nd parameters were the direction you were looking not what vector you were looking at.
NBA2K, Madden, Maneater, Killing Floor, Sims 
dpadam450
dpadam450
Thought that I fixed it but I didn't. I drew the 3 positional vectors and what happens is that I start the camera at (0,0,3). A box is drawn starting at (0,0,0). When I cross over the x-axis, the x and z axis get flipped ( positive x becomes negative x and positive z becomes negative z). If I use glTranslatef(), the everything is good, but it would seem easier to just move the camera so that I dont have to translate every single object in the sceen.

[Edited by - dpadam450 on January 26, 2006 1:30:26 AM]
NBA2K, Madden, Maneater, Killing Floor, Sims 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.