some edits in Camera_FPSV2

This commit is contained in:
Dander7BD 2014-02-19 15:20:50 +01:00
parent 4104ae8df7
commit a9f554448c
2 changed files with 39 additions and 4 deletions

View File

@ -10,6 +10,7 @@ Camera_FPSV2::Camera_FPSV2()
this->headOffset =
this->body.translation = Float3::null;
this->body.rotation = Quaternion::identity;
this->pitchHaveChanged = false;
}
Camera_FPSV2::~Camera_FPSV2() {}
@ -21,6 +22,7 @@ Camera_FPSV2 & Camera_FPSV2::operator = ( const Camera_FPSV2 &camera )
this->headOffset = camera.headOffset;
this->body.translation = camera.body.translation;
this->body.rotation = camera.body.rotation;
this->pitchHaveChanged = camera.pitchHaveChanged;
return *this;
}
@ -45,6 +47,7 @@ void Camera_FPSV2::SetRotation( const Quaternion &rotation )
this->body.rotation = rotation;
this->head.SetRotation( rotation * Rotation(this->pitchUp, WorldAxisOf(rotation, Float3::standard_unit_x) ) );
this->pitchHaveChanged = false;
}
void Camera_FPSV2::SetAngular( const Float3 &axis )
@ -69,6 +72,12 @@ void Camera_FPSV2::SetPerspectiveProjection( Float verticalFoV, Float aspectRati
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;
OrientationMatrix( this->body.rotation, this->body.translation, orientation );
@ -78,7 +87,8 @@ void Camera_FPSV2::UpdateOrientation()
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->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 )
@ -89,8 +99,8 @@ void Camera_FPSV2::Move( const Float3 &deltaPosition )
void Camera_FPSV2::Rotate( const Quaternion &deltaRotation )
{
this->head.Rotate( deltaRotation );
this->body.rotation *= deltaRotation;
this->pitchHaveChanged = true;
}
void Camera_FPSV2::Rotate( const Float3 &deltaAngularAxis )
@ -121,7 +131,7 @@ void Camera_FPSV2::StrafeLeft( Float distance )
void Camera_FPSV2::PitchUp( Float radian )
{
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 )
@ -152,6 +162,12 @@ const Float3 & Camera_FPSV2::GetPosition() 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 );
}
@ -162,11 +178,23 @@ const Float4x4 & Camera_FPSV2::GetProjectionMatrix() 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 );
}
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 );
}
@ -182,6 +210,12 @@ Float3 Camera_FPSV2::GetUp() 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 );
}

View File

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