2012-08-15 4 views
1

내 Windows phone 응용 프로그램에서 화면 터치 입력을 사용하여 3D 모델을 회전하고 싶습니다.Windows phone 터치로 3D 모델 회전

문제는 다음과 같습니다.

처음에는 모든 것이 괜찮습니다. 터치를 사용하여 모델을 이동할 수 있지만 X 축에서 회전하여 개체를 거꾸로 만들면 Y 축 회전이 반전됩니다. 내 세계 축이 변경 되었기 때문입니다. 나는 많은 방법을 시도했다.

1 : 2

Matrix world = Matrix.Identity *Matrix.CreateRotationY(somerotation); 
world = world * Matrix.CreateRotationX(somerotation); 
world *= Matrix.CreateTranslation(0, 0, 0); 

: 3

Matrix world = Matrix.Identity * Matrix.CreateFromYawPitchRoll(somerotation,somerotation,0); 
world *= Matrix.CreateTranslation(0, 0.0f, zoomXY); 

:

Matrix world = Matrix.Identity *Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0),somerotation)); 
    world *= Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), somerotation)); 
    world *= Matrix.CreateTranslation(0,0,0); 

4

Matrix world = Matrix.Identity; 
      world = Matrix.CreateFromAxisAngle(Vector3.Up,somerotation); 
      world *= Matrix.CreateFromAxisAngle(Vector3.Right,somerotation); 
      world *= Matrix.CreateTranslation(0, 0,0); 

결과는 동일합니다. 지금 내 마음은 통제없이 돌아가고 있습니다.

회전 후에 변경되지 않는 정적 축을 어떻게 사용할 수 있습니까? 아니면 다른 제안?

감사합니다.

답변

1

문제는 수학에 문제가 없다는 것입니다. 두 번째 축의 동작은 다른 축을 회전시켜 발생시킨 반대 방향에서 볼 때 올바른 동작이므로 반전됩니다.

모든 프레임에서 처음부터 고정 축에 대한 회전을 만드는 대신 현재 방향 벡터 (위쪽 및 오른쪽, 앞으로 및 왼쪽)를 저장하고 영구 방향 행렬에 대한 작은 증분 회전을 적용 해보십시오. 물론 오리엔테이션에도 동일한 변경 사항을 적용해야합니다.

그런 식으로 매트릭스가 현재 향하고있는 방향에 상관없이 항상 원하는 방향으로 회전 할 수 있습니다. (코드)

편집 :

class gameclass 
{ 
Vector3 forward = Vector3.UnitZ; //persistent orientation variables 
Vector3 left = -1 * Vector3.UnitX; 
Vector3 up  = Vector3.UnitY 

Matrix world = Matrix.Identitiy; 

InputClass inputputclass;   //something to get your input data 

void Update() 
{ 
Vector3 pitch = inputclass.getpitch();   //vertical swipe 
forward = Vector3.transform(forward, 
    Matrix.CreateFromAxisAngle(left, pitch)); 
up  = Vector3.transform(up, 
    Matrix.CreateFromAxisAngle(left, pitch)); 

Vector3 yaw = inputclass.getyaw();    //horizontal swipe 

forward = Vector3.transform(forward, 
    Matrix.CreateFromAxisAngle(up, yaw)); 
left = Vector3.transform(left, 
    Matrix.CreateFromAxisAngle(up, yaw)); 

forward.Normalize(); left.Normalize(); top.Normalize(); //avoid rounding errors 

world = Matrix.CreateWorld(
    postition      //this isn't defined in my code 
    forward, 
    up); 
} 


} 

은 무료, 구형 순환 게재가 간단하지 않습니다. :)

+0

먼저 답장을 보내 주셔서 감사합니다. 나는 현재 벡터를 지키는 것을 완전히 이해할 수 없었다. 세계의 현재 벡터 또는 단위 행렬? 짧은 의사 코드가 유용 할 수 있습니다. – user1601594

+0

나는 당신의 코드를 연구 중이다. 내 문제는 여전히 존재합니다. 이것은 내 문제를 해결하지 못했습니다. 그러나 당신은 나에게 문제를 해결할 수있는 훌륭한 아이디어를주었습니다. 감사합니다. 문제를 해결할 수 있기를 바랍니다. – user1601594