2011-08-02 3 views
1

XNA에서 비행 시뮬레이터 프로그램 (Star Fox 64와 유사)을 쓰고 있습니다. 회전에 문제가 있습니다. 내 생각은 위치에 대한 속도와 벡터에 대한 벡터를 갖는 것입니다. 내가 허용하는 컨트롤은 오일러의 각도가 문제를 일으킬 수 있도록 쿼터니언을 사용하려고합니다.XNA Quaternion.createFromAxisAngle

아직 그래픽 렌더링에 익숙하지 않지만 Quaternion.createFromAxisAngle (벡터, 롤) (롤은 내 속도 벡터 주위로 회전 함)를 사용할 수 있다고 생각했지만 제대로 작동하지 않습니다. 기본적으로 피치 또는 요를 회전하려고 할 때마다 아무 일도 일어나지 않습니다. 롤 때, 그것은 작동하지만 예상했던대로하지 않습니다. createFromAxisAngle 메서드를 적절하게 사용합니까? 감사. 당신이 요, 피치, & 롤 변수로 배의 방향을 저장에 대한 단호

public override void UpdatePositions() 
    { 
     float sinRoll = (float)Math.Sin(roll); 
     float cosRoll = (float)Math.Cos(roll); 
     float sinPitch = (float)Math.Sin(pitch); 
     float cosPitch = (float)Math.Cos(pitch); 
     float sinYaw = (float)Math.Sin(yaw); 
     float cosYaw = (float)Math.Cos(yaw); 

     m_Velocity.X = (sinRoll * sinPitch - sinRoll * sinYaw * cosPitch - sinYaw * cosPitch); 
     m_Velocity.Y = sinPitch * cosRoll; 
     m_Velocity.Z = (sinRoll * sinPitch + sinRoll * cosYaw * cosPitch + cosYaw * cosPitch); 
     if (m_Velocity.X == 0 && m_Velocity.Y == 0 && m_Velocity.Z == 0) 
      m_Velocity = new Vector3(0f,0f,1f); 
     m_Rotation = new Vector3((float)pitch, (float)yaw, (float)roll); 

     m_Velocity.Normalize(); 
     //m_QRotation = Quaternion.CreateFromYawPitchRoll((float)yaw,(float)pitch,(float)roll); This line works for the most part but doesn't allow you to pitch up correctly while banking. 
     m_QRotation = Quaternion.CreateFromAxisAngle(m_Velocity,(float)roll); 
     m_Velocity = Vector3.Multiply(m_Velocity, shipSpeed); 

     m_Position += m_Velocity; 
    } 

답변

2

위치 : 여기

내 선박에 대한 업데이트 위치 코드? 그렇지 않은 경우 쿼터니언 또는 행렬에 방향을 저장하면 여기에 도전 과제가 크게 단순화됩니다.

프레임의 끝 부분에서 우주의 세계 공간 방향 & 위치를 나타내는 행렬을 effect.World로 보냅니다. 그 행렬의 앞으로 속성은 당신이 여기 속도로 계산 한 것과 같은 벡터입니다. 왜 효과에서 그 행렬을 저장하지 않습니까? 세계, 다음 프레임은 그 행렬에 대해 단순히 전진 벡터 (롤)에 대한 행렬을 회전시키고 자신의 전진 속성 (forward 속성 * shipSpeed)에 기반한 변환 속성을 전진시키고 다음 프레임에 대한 효과. 이것은 실제 요, 피치, 당신의 배의 롤 각도를 & "알"못하게합니다. 그러나 대부분의 경우 3D 프로그래밍에서 뭔가의 각도를 알아야한다고 생각하면 틀린 방식 일 것입니다.

원한다면 매트릭스를 사용하여이 방향으로가는 발췌 문장입니다.

//class scope field 
Matrix orientation = Matrix.Identity; 


//in the update 
Matrix changesThisFrame = Matrix.Identity; 

//for yaw 
changesThisFrame *= Matrix.CreatFromAxisAngle(orientation.Up, inputtedYawAmount);//consider tempering the inputted amounts by time since last update. 

//for pitch 
changesThisFrame *= Matrix.CreateFromAxisAngle(orientation.Right, inputtedPitchAmount); 

//for roll 
changesThisFrame *= Matrix.CreateFromAxisAngle(orientation.Forward, inputtedRollAmount); 

orientation *= changesThisFrame; 

orientation.Translation += orientation.Forward * shipSpeed; 


//then, somewhere in the ship's draw call 

effect.World = orientation; 
1

3D로 XNA 및 회전 작업을 원하십니까? 그런 다음 이것을 읽으십시오 : http://stevehazen.wordpress.com/2010/02/15/matrix-basics-how-to-step-away-from-storing-an-orientation-as-3-angles/

충분히 권장 할 수 없습니다.

+2

감사합니다. Seb, 내 블로그입니다! =) 나는 언젠가 그것을 썼다. 얼마나 많은 사람들이 유용하다고 생각하는지 알고 놀랐다. thattolleyguy의 질문에 대한 나의 대답은 블로그 본질의 미니 버전이었습니다. –