Some fixes and traps

This commit is contained in:
Dander7BD 2014-02-19 15:47:43 +01:00
parent c2226fa9d1
commit 908d52020a
2 changed files with 24 additions and 7 deletions

View File

@ -4,6 +4,12 @@
using namespace ::Oyster::Math3D;
using namespace ::Utility::Value;
inline Quaternion Transform( const Quaternion &transformer, const Quaternion &transformee )
{
// return transformer * transformee;
return transformee * transformer;
}
Camera_FPSV2::Camera_FPSV2()
{ // this->head is default set to identity uniformprojection at origo
this->pitchUp = 0.0f;
@ -46,7 +52,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->head.SetRotation( Transform(rotation, Rotation(this->pitchUp, WorldAxisOf(rotation, Float3::standard_unit_x))) );
this->pitchHaveChanged = false;
}
@ -74,7 +80,7 @@ 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->head.SetRotation( Transform(this->body.rotation, Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x))) );
this->pitchHaveChanged = false;
}
@ -87,7 +93,7 @@ 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, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) );
this->head.SetRotation( Transform(this->body.rotation, Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x))) );
this->pitchHaveChanged = false;
}
@ -130,6 +136,11 @@ void Camera_FPSV2::StrafeLeft( Float distance )
void Camera_FPSV2::PitchUp( Float radian )
{
if( radian >= 0.5f )
{ // HACK: debugging
const char *breakPoint = "";
}
this->pitchUp = Clamp( this->pitchUp + radian, -0.48f * pi, 0.48f * pi );
this->pitchHaveChanged = true;
}
@ -164,7 +175,7 @@ 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->head.SetRotation( Transform(this->body.rotation, Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x))) );
this->pitchHaveChanged = false;
}
@ -180,7 +191,7 @@ 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->head.SetRotation( Transform(this->body.rotation, Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x))) );
this->pitchHaveChanged = false;
}
@ -191,7 +202,7 @@ 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->head.SetRotation( Transform(this->body.rotation, Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x))) );
this->pitchHaveChanged = false;
}
@ -212,7 +223,7 @@ 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->head.SetRotation( Transform(this->body.rotation, Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x))) );
this->pitchHaveChanged = false;
}

View File

@ -480,6 +480,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
// if is this player. Remember to change camera
if( this->privData->myId == decoded.object_ID )
{
if( !Within(position.Dot(position), 2500.0f, 90000.0f) )
{ // HACK: bug trap
const char *breakPoint = "Something is wrong.";
//position = Float3( 0.0f, 160.0f, 0.0f );
}
this->privData->camera.SetPosition( position );
this->privData->camera.SetRotation( rotation );
this->privData->player.setPos( position );