2012-10-11 4 views
0

로컬 공간에서 카메라를 피치하려면 어떻게해야합니까?월드 스페이스에서 로컬 공간이 아닌 카메라 피치

월드 스페이스의 위치에 관계없이 축에 대해 회전하는 모델이 있습니다. 내가 가지고있는 문제는 모델의 다른 회전 (편주)에 관계없이 카메라가 동일한 피치를 갖도록하는 것입니다. 현재 월드 스페이스에서 모델이 북쪽 또는 남쪽을 향하고 있으면 카메라가 이에 따라 피치를 맞 춥니 다. 그러나 모델이 다른 추기경 방향을 향하고있을 때, 카메라를 투구하려고 시도한 후에 카메라는 모델 뒤의 원 운동으로 위아래로 움직입니다 (모델이 어느 방향으로 향하고 있지 않은지 월드 스페이스 만 인식하기 때문에).

모델이 어떤 방향을 향하고 있어도 피치를 모델과 함께 회전 시키려면 어떻게해야합니까? 내가 카메라를 피킹하려고하면 모델 위로 움직일 것입니까?

// Rotates model and pitches camera on its own axis 
    public void modelRotMovement(GamePadState pController) 
    { 
     /* For rotating the model left or right. 
     * Camera maintains distance from model 
     * throughout rotation and if model moves 
     * to a new position. 
     */ 

     Yaw = pController.ThumbSticks.Right.X * MathHelper.ToRadians(speedAngleMAX); 

     AddRotation = Quaternion.CreateFromYawPitchRoll(Yaw, 0, 0); 
     ModelLoad.MRotation *= AddRotation; 
     MOrientation = Matrix.CreateFromQuaternion(ModelLoad.MRotation); 

     /* Camera pitches vertically around the 
     * model. Problem is that the pitch is 
     * in worldspace and doesn't take into 
     * account if the model is rotated. 
     */ 
     Pitch = pController.ThumbSticks.Right.Y * MathHelper.ToRadians(speedAngleMAX); 
    } 

    // Orbit (yaw) Camera around model 
    public void cameraYaw(Vector3 axisYaw, float yaw) 
    { 
     ModelLoad.CameraPos = Vector3.Transform(ModelLoad.CameraPos - ModelLoad.camTarget, 
      Matrix.CreateFromAxisAngle(axisYaw, yaw)) + ModelLoad.camTarget; 
    } 

    // Pitch Camera around model 
    public void cameraPitch(Vector3 axisPitch, float pitch) 
    { 
     ModelLoad.CameraPos = Vector3.Transform(ModelLoad.CameraPos - ModelLoad.camTarget, 
      Matrix.CreateFromAxisAngle(axisPitch, pitch)) + ModelLoad.camTarget; 
    } 

    public void updateCamera() 
    { 
     cameraPitch(Vector3.Right, Pitch); 
     cameraYaw(Vector3.Up, Yaw); 
    } 

답변

1
> public void cameraPitch(Vector3 axisPitch, float pitch) 
>  { 
>   ModelLoad.CameraPos = Vector3.Transform(ModelLoad.CameraPos - ModelLoad.camTarget, 
>    Matrix.CreateFromAxisAngle(axisPitch, pitch)) + ModelLoad.camTarget; 
>  } 

나는 당신의 마지막 질문이를 볼 수 있어야합니다. 아프다.

axisPitch는 실제로 전역 공간 벡터이므로 로컬 공간에 있어야합니다. 이것은 효과가있다.

public void cameraPitch(float pitch) 
    { 
     Vector3 f = ModelLoad.camTarget - ModelLoad.CameraPos; 
     Vector3 axisPitch = Vector3.Cross(Vector3.Up, f); 
     axisPitch.Normalize(); 
     ModelLoad.CameraPos = Vector3.Transform(ModelLoad.CameraPos - ModelLoad.camTarget, 
      Matrix.CreateFromAxisAngle(axisPitch, pitch)) + ModelLoad.camTarget; 
    }