Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "LeapUtil.h"
00009
00010 namespace LeapUtil {
00011
00012 using namespace Leap;
00013
00017
00018 void Camera::SetPOVLookAt( const Vector& vCameraPosition, const Vector& vTarget, Vector vUp )
00019 {
00020 Vector vZBasis = (vCameraPosition - vTarget).normalized();
00021
00022
00023 if ( vUp == Vector::zero() )
00024 {
00025 vUp = m_mtxPOV.yBasis;
00026 }
00027 else
00028 {
00029 vUp = vUp.normalized();
00030 }
00031
00032
00033
00034 if ( IsNearZero(1.0f - fabs(vZBasis.dot(vUp))) )
00035 {
00036
00037
00038 vUp = vZBasis.cross( m_mtxPOV.xBasis ).normalized();
00039 }
00040
00041 Vector vXBasis = vUp.cross(vZBasis).normalized();
00042 Vector vYBasis = vZBasis.cross( vXBasis ).normalized();
00043
00044 m_mtxPOV.xBasis = vXBasis;
00045 m_mtxPOV.yBasis = vYBasis;
00046 m_mtxPOV.zBasis = vZBasis;
00047 m_mtxPOV.origin = vCameraPosition;
00048
00049 updateOrbitDistance();
00050 }
00051
00052 void Camera::RotateOrbit( float fDeltaMagnitude, float fDeltaLongitude, float fDeltaLatitude )
00053 {
00054 m_fOrbitDistance += fDeltaMagnitude;
00055
00056 Vector vSphereZBasis = CartesianToSpherical( m_mtxPOV.zBasis );
00057 float fNewLatitude = Clamp( vSphereZBasis.z + fDeltaLatitude,
00058 -m_fMaxOrbitLatitude,
00059 m_fMaxOrbitLatitude );
00060
00061 Vector vSphereNewZBasis( 1, vSphereZBasis.y + fDeltaLongitude, fNewLatitude );
00062 Vector vSphereNewYBasis( 1, vSphereNewZBasis.y, vSphereNewZBasis.z + kfHalfPi );
00063
00064 m_mtxPOV.zBasis = SphericalToCartesian( NormalizeSpherical( vSphereNewZBasis ) );
00065 m_mtxPOV.yBasis = SphericalToCartesian( NormalizeSpherical( vSphereNewYBasis ) );
00066 m_mtxPOV.xBasis = m_mtxPOV.yBasis.cross( m_mtxPOV.zBasis ).normalized();
00067 m_mtxPOV.yBasis = m_mtxPOV.zBasis.cross( m_mtxPOV.xBasis ).normalized();
00068 m_mtxPOV.origin = m_mtxPOV.zBasis * m_fOrbitDistance;
00069 }
00070
00071 void Camera::OnMouseWheel( float fDeltaZ )
00072 {
00073 static const float kfZScale = -0.15f;
00074
00075 Move( m_mtxPOV.zBasis * fDeltaZ * kfZScale * m_fOrbitDistance );
00076 updateOrbitDistance();
00077 }
00078
00079 void Camera::OnMouseDown( const Vector& vMousePos )
00080 {
00081 m_vLastMousePos = vMousePos;
00082 updateOrbitDistance();
00083 }
00084
00085 void Camera::OnMouseMoveOrbit( const Vector& vMousePos )
00086 {
00087 static const float kfMouseOrbitAngleScale = 1/1024.0f;
00088
00089 Vector vOrbitDelta = (vMousePos - m_vLastMousePos) * kfMouseOrbitAngleScale * kf2Pi;
00090
00091 RotateOrbit( 0, vOrbitDelta.x, vOrbitDelta.y );
00092
00093 m_vLastMousePos = vMousePos;
00094 }
00095
00096 }