1
我的OpenGl相機似乎有問題。當我第一次創建它時,一切正常。但是,由於導入模型和創建對象,我注意到奇怪的事情發生。我的OpenGL相機機芯問題
首先,我的繼承人爲移動代碼:
float xRot = (Pitch/180 * 3.141592654f),
yRot = (Yaw/180 * 3.141592654f);
float sinX = float(sin(xRot)) * myInput.Sensitivity,
sinY = float(sin(yRot)) * myInput.Sensitivity,
cosY = float(cos(yRot)) * myInput.Sensitivity;
if(myInput.Keys['W']) //Forwards
{
curPos.x += sinY;
curPos.z -= cosY;
curPos.y += sinX;
}
else if(myInput.Keys['S']) //Backwards
{
curPos.x -= sinY;
curPos.z += cosY;
curPos.y -= sinX;
}
if(myInput.Keys['A']) //Left
{
curPos.x -= cosY;
curPos.z -= sinY;
}
else if(myInput.Keys['D']) //Right
{
curPos.x += cosY;
curPos.z += sinY;
}
//Move camera up and down
if(myInput.Keys['Q'])
curPos.y-= myInput.Sensitivity; //up
else if(myInput.Keys['E'])
curPos.y+= myInput.Sensitivity; //down
//Check col
if(curPos.y < 0)
curPos.y = 0;
else if(curPos.y >= 300) //Gimbal lock encountered
curPos.y = 299;
其次,我的繼承人計算gluLookAt運動:
double cosR, cosP, cosY; //temp values for sin/cos from
double sinR, sinP, sinY; //the inputed roll/pitch/yaw
cosY = cosf(Yaw*3.1415/180);
cosP = cosf(Pitch*3.1415/180);
cosR = cosf(Roll*3.1415/180);
sinY = sinf(Yaw*3.1415/180);
sinP = sinf(Pitch*3.1415/180);
sinR = sinf(Roll*3.1415/180);
//forward position
forwardPos.x = sinY * cosP*360;
forwardPos.y = sinP * 360;
forwardPos.z = cosP * -cosY*360;
//up position
upPos.x = -cosY * sinR - sinY * sinP * cosR;
upPos.y = cosP * cosR;
upPos.z = -sinY * sinR - sinP * cosR * -cosY;
基本上我已經注意到,如果相機去上述300在Y是 - Axis然後視圖開始旋轉,如果我在x/z軸上移動得太遠,也會發生同樣的情況。
任何人都可以看到我的代碼有什麼問題嗎?我應該在rad工作嗎?
該死的,我希望不必這樣做。謝謝:) – Split
我明白;-)但是,做了一次,它真的使它在未來變得輕而易舉。通過插入四元數(SLERP),您可以直接向/從保存的位置執行各種不錯的動畫。 –