2012-10-09 2 views
0

간단한 벡터 회전을하고 싶습니다.벡터 회전

목표는 현재 방향 t 인 대상 t를 가리키는 첫 번째 사람 카메라를 새로운 방향 d1의 새로운 대상 t1으로 향하게하는 것입니다.

d와 d1 사이의 전환은 부드럽게 움직여야합니다.

public void FlyLookTo(Vector3 target) { 

     _flyTargetDirection = target - _cameraPosition; 
     _flyTargetDirection.Normalize(); 

     _rotation = new Matrix(); 

     _rotationAxis = Vector3.Cross(Direction, _flyTargetDirection); 

     // This bool tells the Update()-method to trigger the changeDirection() method. 
     _isLooking = true; 
    } 

으로 I는 한 방향의 새로운 매개 변수 변화

// this method gets executed by the Update()-method if the isLooking flag is up. 
private void _changeDirection() { 

     dist = Vector3.Distance(Direction, _flyTargetDirection); 

     // check whether we have reached the desired direction 
     if (dist >= 0.00001f) { 

      _rotationAxis = Vector3.Cross(Direction, _flyTargetDirection); 
      _rotation = Matrix.CreateFromAxisAngle(_rotationAxis, MathHelper.ToRadians(_flyViewingSpeed - Math.ToRadians(rotationSpeed))); 


      // update the cameras direction. 
      Direction = Vector3.TransformNormal(Direction, _rotation); 
     } else { 

      _onDirectionReached(); 
      _isLooking = false; 
     } 
    } 

I 실제 운동을 수행하고으로 개시하고있다.

내 문제 : 실제 움직임은 잘 작동하지만 현재 방향이 원하는 방향에 가까워 질수록 움직임 속도가 느려지므로 여러 번 연속 실행하면 매우 불쾌한 움직임을 만듭니다.

카메라를 움직임이 같은 속도로 d 방향에서 d1 방향으로 움직이게하려면 어떻게해야합니까?

+0

내 대답보기 : http://gamedev.stackexchange.com/questions/38594/rotate-a-vector 여기 : http://stackoverflow.com/questions/12797811/rotation-axis-to-perform- 회전 –

답변

0

코드가 매우 견고합니다. _flyViewingSpeed ​​또는 rotationSpeed가 전혀 변경되지 않습니까?

또 다른 방법은 시도하려는 작업을 정확하게 수행하는 Vector3.Lerp()를 사용하는 것입니다. 그러나 현재 방향이 아닌 초기 시작 및 목표 방향을 사용해야하거나 속도 변화가 다양 할 수 있습니다.

또한 거리 (일반적으로 점에 사용되는)를 사용하는 대신 방향에 대한 거리와 같은 종류의 Vector3.Dot()를 사용합니다. 거리()보다 빠릅니다.

희망이 도움이됩니다.