Can anybody help me with this 3d world navigation problem. I have a 3d world made by the display function:
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ; /* clear the window */
glLoadIdentity() ;
glRotatef(-theta,0,1,0);
glRotatef(-theta2,1,0,0);
glTranslatef(-xpos,-ypos,-zpos);
for(j=0;j < obj;j++)
{
glPushMatrix();
}
for(i=0;i < obj;i++)
{
glPopMatrix();
glTranslatef(array[i][3],((array[i][0] / 50)-1) * 50,array[i][4]);
glScalef(array[i][1] / 50,array[i][0] / 50,array[i][2] / 50);
glTranslatef(0,0,0);
box();
}
glFlush() ;
glutSwapBuffers() ;
}
which gets all the objects and there parameters from an array and then builds a box with hese parameters.
I have the keyboard function :
void keyboardarrow(int key, int x, int y)
{
float xinc,zinc;
if (key == GLUT_KEY_LEFT)
theta = theta + 3 ;
if (key == GLUT_KEY_RIGHT)
theta = theta - 3 ;
if (key == GLUT_KEY_UP)
{
xinc = -sin((6.28/360)theta) step ;
zinc = -cos((6.28/360)theta) step;
xpos = xpos + xinc;
zpos = zpos + zinc;
}
if (key == GLUT_KEY_DOWN)
{
xinc = -sin((6.28/360)*theta)* step ;
zinc = -cos((6.28/360)*theta)* step;
xpos = xpos - xinc;
zpos = zpos - zinc;
}
display() ;
}
and now I need to make it so the user can ‘fly’ through the world. I.e they press an up or down key to chose the angle of flight and then when forward or back arrow key is pressed they move in this direction. I cant seem to get this to work anybody help???
-kebabinho