2013-06-07 1 views
1

현재 X-Plane plugin to add support for the Oculus Rift에서 작업 중이며 순환을 위해 쿼터니언을 사용하는 데 문제가 있습니다. 회전 행렬 또는 오일러 각을 사용하여 이러한 종류의 작업을 수행했지만 쿼터니언이 지금가는 길인 것 같아서 배울 기회가 있습니다. Quaternions는 또한 Oculus SDK가 기본적으로 사용하는 것처럼 보이므로이를 사용하면 저항이 가장 적은 경로가됩니다.쿼터니언을 사용하여 원래 오일러 각으로 표현 된 축 주위로 벡터를 회전하십시오.

내가 해결하려고하는 문제는 평면 자체가 비행 중 방향을 변경하기 때문에 조종사 헤드의 위치에 카메라를 배치하는 위치입니다. 그것은 나에게 꽤 똑바로 보인다. 저는 비행기의 중심에 대한 조종사의 상대적인 위치를 나타내는 벡터를 가지고 있습니다. 비행기를 중심으로 회전하고 싶습니다. z 벡터에 의해 롤로도 벡터가 있습니다.

여기 코드가 있습니다. 나는 이것이 옳다고 생각하지만,이 코드를 실행하면 비행기 지붕 위의 어딘가에있는 비행기가 방향이 바뀌면서 원형 패턴으로 움직인다. 또한, 0도 (예 : phi을 0으로 설정)로 헤드 벡터를 회전 시키면 같은 (또는 비슷한 이상) wierd 결과를 얻게되어 내 quat 또는 잘못된 것을 설정해야합니다.

//get the vector to the players head relative to the plane's center of gravity 
    float headX = XPLMGetDataf(XPLMFindDataRef("sim/aircraft/view/acf_peX")); 
    float headY = XPLMGetDataf(XPLMFindDataRef("sim/aircraft/view/acf_peY")); 
    float headZ = XPLMGetDataf(XPLMFindDataRef("sim/aircraft/view/acf_peZ")); 

    //the planes orientation in euler angles 
    float theta = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/position/theta")) * (M_PI/180.0f); 
    float psi = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/position/psi")) * (M_PI/180.0f); 
    float phi = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/position/phi")) * (M_PI/180.0f); 

    //convert euler angles into a vector for our axis or rotation 
    float planeVecX = cos(psi)*cos(theta); 
    float planeVecY = sin(psi)*cos(theta); 
    float planeVecZ = sin(theta); 

    //make some vectors 
    Vector3<float> *headVector = new Vector3<float>(headX, headY, headZ); 
    headVector->Normalize(); 
    Vector3<float> *planeVector = new Vector3<float>(planeVecX, planeVecY, planeVecZ); 
    planeVector->Normalize(); 


    //Make a quaternion for our rotation 
    Quat<float> *planeQuat = new Quat<float>(*planeVector, phi); 

    planeQuat->Normalize(); 

    //rotate headVector by plane quat 
    Vector3<float> rotatedHeadVec = planeQuat->Rotate(*headVector); 

    //output our final camera position and orientation 
    outCameraPosition->x = planeX + rotatedHeadVec.x; 
    outCameraPosition->y = planeY + rotatedHeadVec.y; 
    outCameraPosition->z = planeZ + rotatedHeadVec.z; 
    outCameraPosition->pitch = theta * (180.0f/M_PI); 
    outCameraPosition->heading = psi * (180.0f/M_PI); 
    outCameraPosition->roll = phi * (180.0f/M_PI); 

TIA를 참조하십시오.

답변

0

x- 평면은 좌표계 방향과 그다지 일치하지 않습니다. 이 코드는 올바른 생각 이었지만 X-Plane에서 얻은 데이터를 잘못된 방식으로 사용했습니다.