From 77eceaf285e172d174b00b61c4426c1cf2c947a3 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 10 Feb 2014 15:19:42 +0100 Subject: [PATCH] Camera_Basic edits --- .../DanBiasGame/GameClientState/Camera_Basic.cpp | 16 ++++++++++++++-- .../DanBiasGame/GameClientState/Camera_Basic.h | 7 +++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/Camera_Basic.cpp b/Code/Game/DanBiasGame/GameClientState/Camera_Basic.cpp index 6c79fe6a..4878f3c4 100644 --- a/Code/Game/DanBiasGame/GameClientState/Camera_Basic.cpp +++ b/Code/Game/DanBiasGame/GameClientState/Camera_Basic.cpp @@ -68,6 +68,16 @@ void Camera_Basic::Rotate( const Float3 &deltaAngularAxis ) this->rotationIsOutOfDate = true; } +const Float3 & Camera_Basic::GetPosition() const +{ + return this->translation; +} + +const Float3 & Camera_Basic::GetAngularAxis() const +{ + return this->angularAxis; +} + Float3 Camera_Basic::GetNormalOf( const Float3 &axis ) const { return WorldAxisOf( this->GetRotation(), axis ); @@ -77,8 +87,10 @@ const Quaternion & Camera_Basic::GetRotation() const { if( this->rotationIsOutOfDate ) { - /*Float4 temp; - ::std::fmod( Float4(this->angularAxis, 0.0f) );*/ + // Maintain rotation resolution by keeping axis within [0, 2pi] (trigonometric methods gets faster too) + Float4 numerator; + ::std::modf( this->angularAxis * (0.5f / pi), numerator.xyz ); + this->angularAxis -= ((2.0f * pi) * numerator).xyz; this->rotation = Rotation( this->angularAxis ); this->rotationIsOutOfDate = false; diff --git a/Code/Game/DanBiasGame/GameClientState/Camera_Basic.h b/Code/Game/DanBiasGame/GameClientState/Camera_Basic.h index ca317db0..c2a65e14 100644 --- a/Code/Game/DanBiasGame/GameClientState/Camera_Basic.h +++ b/Code/Game/DanBiasGame/GameClientState/Camera_Basic.h @@ -21,6 +21,8 @@ public: void Move( const ::Oyster::Math::Float3 &deltaPosition ); void Rotate( const ::Oyster::Math::Float3 &deltaAngularAxis ); + const ::Oyster::Math::Float3 & GetPosition() const; + const ::Oyster::Math::Float3 & GetAngularAxis() const; ::Oyster::Math::Float3 GetNormalOf( const ::Oyster::Math::Float3 &axis ) const; const ::Oyster::Math::Quaternion & GetRotation() const; ::Oyster::Math::Float3x3 & GetRotationMatrix( ::Oyster::Math::Float3x3 &targetMem ) const; @@ -30,8 +32,9 @@ public: ::Oyster::Math::Float4x4 & GetViewsProjMatrix( Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const; private: - ::Oyster::Math::Float3 translation, angularAxis; - ::Oyster::Math::Float4x4 projection; + ::Oyster::Math::Float3 translation; + mutable ::Oyster::Math::Float3 angularAxis; + ::Oyster::Math::Float4x4 projection; mutable ::Oyster::Math::Quaternion rotation; mutable bool rotationIsOutOfDate; };