PDA

View Full Version : Need Help With Basic Camera



Chris2404
04-13-2011, 05:00 AM
Hi, I am having some serious issues with a camera in opengl and I am hoping someone can help. Here is my code for the camera


//W
if(camInput->DigitalControlMap[6])
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180.0f * M3D_PI);
xrotrad = (xrot / 180.0f * M3D_PI);
xpos += float(sin(yrotrad)) ;
zpos -= float(cos(yrotrad)) ;
ypos -= float(sin(xrotrad)) ;

camInput->DigitalControlMap[6] =false;
}
//S
if(camInput->DigitalControlMap[7])
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * M3D_PI);
xrotrad = (xrot / 180 * M3D_PI);
xpos -= float(sin(yrotrad));
zpos += float(cos(yrotrad)) ;
ypos += float(sin(xrotrad));
camInput->DigitalControlMap[7] =false;
}
//A
if (camInput->DigitalControlMap[8])
{
yrot -= 0.01;
if (yrot < -360)yrot += 360;
camInput->DigitalControlMap[8] =false;
}
//D
if (camInput->DigitalControlMap[9])
{
yrot += 0.01;
if (yrot >360) yrot -= 360;
camInput->DigitalControlMap[9] =false;
}
M3DMatrix44f testx, testy, trans, cam,test3;

m3dRotationMatrix44(testx, xrot, 1.0, 0.0,0.0);
m3dRotationMatrix44(testy, -yrot, 0.0, 1.0,0.0);

m3dTranslationMatrix44(trans, -xpos, -ypos, -zpos); //Create A Translation Matrix

m3dMatrixMultiply44(test3, testx, testy); //Multiply The Two Rotations Together

m3dMatrixMultiply44(mCamera, test3, trans); //Now Multiply the translation and rotation

I am trying to move away for glRotatef and such like but the problem with this code it you never really move forward. Instead you move along the same axis no matter which way the camera is facing. The rotation works fine, I just cant figure out why I wont walk in the direction that you are facing.

EDIT: if the test3 and trans are transposed to give "m3dMatrixMultiply44(mCamera, trans, test3)" then you move forward in the right direction, the only problem now is it always seems to rotate around a certain point and not where you are currently standing