Jump to content
  • Advertisement
Sign in to follow this  
AmidaBucu

Why my viewpoint does not change?

This topic is 3073 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


void keyboardFunc(unsigned char key, int x, int y)
{
if (key=='w')
{
ypos-=50;
}

if (key==27)
{
exit(0);
}
}

void reshapeFunc(int x, int y)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, width/height, 1.0, 1000.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt (xpos, ypos, zpos,
0, 0, 0,
0, 1, 0);
}

void displayFunc()
{
glClearColor(0,0,1,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

gluLookAt (xpos, ypos, zpos,
0, 0, 0,
0, 1, 0);
glBegin(GL_TRIANGLES);
glColor3f(1,1,1);
for(unsigned int i = 0; i < myMesh.nVertices*3;i+=3)
{
glVertex3f(myMesh.vertices[i+0],
myMesh.vertices[i+1],
myMesh.vertices[i+2]);
}
glEnd();
glutSwapBuffers();
}

void load()
{
//load a mesh
}

int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(width, height);
glutInitWindowPosition(0,0);
glutCreateWindow("openGL");
glutKeyboardFunc(keyboardFunc);
glutReshapeFunc(reshapeFunc);
glutDisplayFunc(displayFunc);

load();

glutMainLoop();
}



If I manually change the ypos, then the viewpoint will change,
but if I press 'w', then nothing happens. Where I am wrong?

Share this post


Link to post
Share on other sites
Advertisement
Looks like 'w' is not what gets sent to the keyboardFunc. Set a breakpoint (or output some debug message) in that function and look at the value for 'key' when you press W. Use that value in your if(key==..) statement.

Share this post


Link to post
Share on other sites
An important thing: gluLookAt calculates a matrix then multiplies the CURRENT modelview matrix with it. So the way you use it now won't work as you expect.
Call glLoadIdentity before gluLookAt in displayFunc too.

And try with capital W instead of w.

Share this post


Link to post
Share on other sites
The display callback isn't called until it has to, which is either when the window needs to be refreshed or when you explicitly ask for it. Call glutPostRedisplay whenever you want to redraw the window, like after pressing the key.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!