As for why the x and y rotations are negative, it simply changes the direction you rotate. The z axis maybe could be negative. In my program I do not use a z rotation (this could have been entered as the integer constant 0) so I am not sure how making that negative would effect movement. A z axis rotation would be the same as a roll in a flight simulation. An x rotation would be like looking up/down. A y rotation is the same as looking right or left.
Here is an example of how you can place objects:
void setCamera()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(CAMERA_X.orientation[0], 1,0,0);
glRotatef(CAMERA_X.orientation[1], 0,1,0);
glRotatef(CAMERA_X.orientation[2], 0,0,1);
glTranslatef(-CAMERA_X.position[0],
-CAMERA_X.position[1],
CAMERA_X.position[2]);
}
void checkKeyPresses()
{
if (GetAsyncKeyState(VK_LEFT) )
{
CAMERA_X.position[0] += sin(DEGTORAD(CAMERA_X.orientation[1]-90)) * linearSpeed;
CAMERA_X.position[2] += cos(DEGTORAD(CAMERA_X.orientation[1]-90)) * linearSpeed;
}
if (GetAsyncKeyState(VK_RIGHT))
{
CAMERA_X.position[0] += sin(DEGTORAD(CAMERA_X.orientation[1]+90)) * linearSpeed;
CAMERA_X.position[2] += cos(DEGTORAD(CAMERA_X.orientation[1]+90)) * linearSpeed;
}
if (GetAsyncKeyState(VK_UP))
{
CAMERA_X.position[0] += sin(DEGTORAD(CAMERA_X.orientation[1])) * linearSpeed;
CAMERA_X.position[2] += cos(DEGTORAD(CAMERA_X.orientation[1])) * linearSpeed;
}
if (GetAsyncKeyState(VK_DOWN) )
{
CAMERA_X.position[0] -= sin(DEGTORAD(CAMERA_X.orientation[1])) * linearSpeed;
CAMERA_X.position[2] -= cos(DEGTORAD(CAMERA_X.orientation[1])) * linearSpeed;
}
if (GetAsyncKeyState(VK_INSERT))
{
linearSpeed += .1;
angularSpeed += .1;
}
if (GetAsyncKeyState(VK_DELETE))
{
if (!(linearSpeed < 0)) linearSpeed -= .1;
if (!(angularSpeed < 0)) angularSpeed -= .1;
}
}
void RenderScene(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
checkKeyPresses();
setCamera();
glBegin(GL_LINES);
glColor3f(1,0,0);
glVertex3f(-100,0,0);
glVertex3f(100,0,0);
glColor3f(0,1,0);
glVertex3f(0,-100,0);
glVertex3f(0,100,0);
glColor3f(0,0,1);
glVertex3f(0,0,-100);
glVertex3f(0,0,100);
glEnd();
The render code first clears the screen. Then I call code to check for key presses (this moves the camera by changing the camera struct data). Then I set where the camera is supposed to be. Then I place the primitives. I know many programmers will often create an object at the origin and then translate/rotate the object to its place. I have not tested this method with my camera model although I do not see why it would not work. It is a method I am not to familiar with although I am studying it. Up till now I have been simply placeing objects at their absolute location.
glBegin(GL_POINTS);
glVertex3f(10,0,0);
glEnd();
will place a point 10 units out on the x axis. If you are oriented to look out from the origin along the positive x axis you will see the point directly in front of you. If you move to orient yourself to look down the negative z axis from the origin the point will be to your right. Hope this helps. Let me know if you have success with the other method (placing at center and then translating out).