Hi all.
Some of you may have seen my earlier posts about my camera heading in combination with strafe problem.
The problem is that when I rotate my camera around the X_axis (when the heading changes), strafing doesn't work anymore.
When I initalised my scene, strafing works fine, till I rotate the camera using free mouselook.
I've drawn all physics on paper to solve the problem, but I just can't find it.
Here's the code that I use, maybe someone can help me:
Move the camera forward:
scene->cam->pos.x -= (float)sin(scene->cam->heading*piover180) * scene->cam->speed;
scene->cam->pos.z -= (float)cos(scene->cam->heading*piover180) * scene->cam->speed;
Strafe the camera left:
scene->cam->pos.x -= (float)sin(scene->cam->heading+(1*90)*piover180) * scene->cam->speed;
scene->cam->pos.z -= (float)cos(scene->cam->heading+(1*90)*piover180) * scene->cam->speed;
Mouselook:
GetCursorPos(&mpos);
*_camheading += ((float)((screenwidth/2 - mpos.x)) * _speed);
*_camyrot = *_camheading;
*_camxrot -= (float)(mpos.y - screenheight/2) * _speed;
SetCursorPos(screenwidth/2, screenheight/2);
Part of renderscene function:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
for(c=0;c<nr_lights;c++) glLightfv(lights[c].id, GL_POSITION, lights[c].pos);
glLoadIdentity();
xtrans = -cam->pos.x;
ytrans = -cam->pos.y;
ztrans = -cam->pos.z;
sceneroty = 360 - cam->rot.y;
scenerotx = 360 - cam->rot.x;
glRotatef(scenerotx, 1, 0, 0);
glRotatef(sceneroty, 0, 1, 0);
glTranslatef(xtrans, ytrans, ztrans);
// draw all objects with glPushMatrix and glPopMatrix