Merge branch 'GameClient' of https://github.com/dean11/Danbias into GameClient

This commit is contained in:
Pontus Fransson 2014-02-19 15:40:23 +01:00
commit f69f3af23d
2 changed files with 39 additions and 4 deletions

View File

@ -10,6 +10,7 @@ Camera_FPSV2::Camera_FPSV2()
this->headOffset = this->headOffset =
this->body.translation = Float3::null; this->body.translation = Float3::null;
this->body.rotation = Quaternion::identity; this->body.rotation = Quaternion::identity;
this->pitchHaveChanged = false;
} }
Camera_FPSV2::~Camera_FPSV2() {} Camera_FPSV2::~Camera_FPSV2() {}
@ -21,6 +22,7 @@ Camera_FPSV2 & Camera_FPSV2::operator = ( const Camera_FPSV2 &camera )
this->headOffset = camera.headOffset; this->headOffset = camera.headOffset;
this->body.translation = camera.body.translation; this->body.translation = camera.body.translation;
this->body.rotation = camera.body.rotation; this->body.rotation = camera.body.rotation;
this->pitchHaveChanged = camera.pitchHaveChanged;
return *this; return *this;
} }
@ -45,6 +47,7 @@ void Camera_FPSV2::SetRotation( const Quaternion &rotation )
this->body.rotation = rotation; this->body.rotation = rotation;
this->head.SetRotation( rotation * Rotation(this->pitchUp, WorldAxisOf(rotation, Float3::standard_unit_x) ) ); this->head.SetRotation( rotation * Rotation(this->pitchUp, WorldAxisOf(rotation, Float3::standard_unit_x) ) );
this->pitchHaveChanged = false;
} }
void Camera_FPSV2::SetAngular( const Float3 &axis ) void Camera_FPSV2::SetAngular( const Float3 &axis )
@ -69,6 +72,12 @@ void Camera_FPSV2::SetPerspectiveProjection( Float verticalFoV, Float aspectRati
void Camera_FPSV2::UpdateOrientation() void Camera_FPSV2::UpdateOrientation()
{ {
if( this->pitchHaveChanged )
{
this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) );
this->pitchHaveChanged = false;
}
Float4x4 orientation; Float4x4 orientation;
OrientationMatrix( this->body.rotation, this->body.translation, orientation ); OrientationMatrix( this->body.rotation, this->body.translation, orientation );
@ -78,7 +87,8 @@ void Camera_FPSV2::UpdateOrientation()
void Camera_FPSV2::SnapUpToNormal( const Float3 &normal ) void Camera_FPSV2::SnapUpToNormal( const Float3 &normal )
{ {
this->body.rotation = Rotation( SnapAngularAxis(AngularAxis(this->body.rotation), WorldAxisOf(this->body.rotation, Float3::standard_unit_y), normal) ); this->body.rotation = Rotation( SnapAngularAxis(AngularAxis(this->body.rotation), WorldAxisOf(this->body.rotation, Float3::standard_unit_y), normal) );
this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp * Float3::standard_unit_x) ); this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) );
this->pitchHaveChanged = false;
} }
void Camera_FPSV2::Move( const Float3 &deltaPosition ) void Camera_FPSV2::Move( const Float3 &deltaPosition )
@ -89,8 +99,8 @@ void Camera_FPSV2::Move( const Float3 &deltaPosition )
void Camera_FPSV2::Rotate( const Quaternion &deltaRotation ) void Camera_FPSV2::Rotate( const Quaternion &deltaRotation )
{ {
this->head.Rotate( deltaRotation );
this->body.rotation *= deltaRotation; this->body.rotation *= deltaRotation;
this->pitchHaveChanged = true;
} }
void Camera_FPSV2::Rotate( const Float3 &deltaAngularAxis ) void Camera_FPSV2::Rotate( const Float3 &deltaAngularAxis )
@ -121,7 +131,7 @@ void Camera_FPSV2::StrafeLeft( Float distance )
void Camera_FPSV2::PitchUp( Float radian ) void Camera_FPSV2::PitchUp( Float radian )
{ {
this->pitchUp = Clamp( this->pitchUp + radian, -0.48f * pi, 0.48f * pi ); this->pitchUp = Clamp( this->pitchUp + radian, -0.48f * pi, 0.48f * pi );
// this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, Float3::standard_unit_x) ); this->pitchHaveChanged = true;
} }
void Camera_FPSV2::PitchDown( Float radian ) void Camera_FPSV2::PitchDown( Float radian )
@ -152,6 +162,12 @@ const Float3 & Camera_FPSV2::GetPosition() const
Float4x4 & Camera_FPSV2::GetViewMatrix( Float4x4 &targetMem ) const Float4x4 & Camera_FPSV2::GetViewMatrix( Float4x4 &targetMem ) const
{ {
if( this->pitchHaveChanged )
{
this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) );
this->pitchHaveChanged = false;
}
return this->head.GetViewMatrix( targetMem ); return this->head.GetViewMatrix( targetMem );
} }
@ -162,11 +178,23 @@ const Float4x4 & Camera_FPSV2::GetProjectionMatrix() const
Float4x4 & Camera_FPSV2::GetViewsProjMatrix( Float4x4 &targetMem ) const Float4x4 & Camera_FPSV2::GetViewsProjMatrix( Float4x4 &targetMem ) const
{ {
if( this->pitchHaveChanged )
{
this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) );
this->pitchHaveChanged = false;
}
return this->head.GetViewsProjMatrix( targetMem ); return this->head.GetViewsProjMatrix( targetMem );
} }
Float3 Camera_FPSV2::GetNormalOf( const Float3 &axis ) const Float3 Camera_FPSV2::GetNormalOf( const Float3 &axis ) const
{ {
if( this->pitchHaveChanged )
{
this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) );
this->pitchHaveChanged = false;
}
return this->head.GetNormalOf( axis ); return this->head.GetNormalOf( axis );
} }
@ -182,6 +210,12 @@ Float3 Camera_FPSV2::GetUp() const
Float3 Camera_FPSV2::GetLook() const Float3 Camera_FPSV2::GetLook() const
{ {
if( this->pitchHaveChanged )
{
this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) );
this->pitchHaveChanged = false;
}
return this->head.GetNormalOf( -Float3::standard_unit_z ); return this->head.GetNormalOf( -Float3::standard_unit_z );
} }

View File

@ -50,7 +50,7 @@ public:
::Oyster::Math::Float3 GetForward() const; ::Oyster::Math::Float3 GetForward() const;
private: private:
Camera_BasicV2 head; mutable Camera_BasicV2 head;
::Oyster::Math::Float pitchUp; ::Oyster::Math::Float pitchUp;
::Oyster::Math::Float3 headOffset; ::Oyster::Math::Float3 headOffset;
struct struct
@ -58,6 +58,7 @@ private:
::Oyster::Math::Float3 translation; ::Oyster::Math::Float3 translation;
::Oyster::Math::Quaternion rotation; ::Oyster::Math::Quaternion rotation;
} body; } body;
mutable bool pitchHaveChanged;
}; };
#endif #endif