void player_rotate(GLfloat xangle, GLfloat yangle, GLfloat zangle) { GLfloat v[4] = { player.lx - player.x, player.ly - player.y, player.lz - player.z, 1}; GLfloat *c = player.matrix; GLint matrix_mode; glGetIntegerv(GL_MATRIX_MODE, &matrix_mode); /* load the current player transformation matrix on to the model view stack */ glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); debug("xangle: %f yangle: %f zangle: %f", xangle, yangle,zangle); /* perform rotation on it */ //glRotatef(xangle,0,1,0); glRotatef(yangle,1,0,0); //glRotatef(zangle,0,0,1); /* get the matrix back out */ glGetFloatv(GL_MODELVIEW_MATRIX, c); /* restore the previous model view matrix */ glPopMatrix(); /* restore the previous matrix mode */ glMatrixMode(matrix_mode); /* multiply the view vector by the transformation matrix */ v[0] = c[0] * v[0] + c[4] * v[1] + c[8] * v[2] + c[12] * v[3]; v[1] = c[1] * v[0] + c[5] * v[1] + c[9] * v[2] + c[13] * v[3]; v[2] = c[2] * v[0] + c[6] * v[1] + c[10] * v[2] + c[14] * v[3]; /* apply the new view vector */ player.lx = player.x+v[0]; player.ly = player.y+v[1]; player.lz = player.z+v[2]; debug("player @ (%f, %f, %f) looking at (%f, %f, %f)", player.x, player.y, player.z, player.lx, player.ly, player.lz); }