0
0
Fork 0
mirror of https://github.com/id-Software/DOOM-3-BFG.git synced 2024-12-13 22:11:15 +00:00
doom3-bfg/neo/d3xp/physics/Physics_Static.cpp

1048 lines
20 KiB
C++
Raw Normal View History

2012-11-26 18:58:24 +00:00
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
2012-11-26 18:58:24 +00:00
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
2012-11-26 18:58:24 +00:00
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#pragma hdrstop
#include "precompiled.h"
2012-11-26 18:58:24 +00:00
#include "../Game_local.h"
CLASS_DECLARATION( idPhysics, idPhysics_Static )
END_CLASS
/*
================
idPhysics_Static::idPhysics_Static
================
*/
idPhysics_Static::idPhysics_Static()
{
2012-11-26 18:58:24 +00:00
self = NULL;
clipModel = NULL;
current.origin.Zero();
current.axis.Identity();
current.localOrigin.Zero();
current.localAxis.Identity();
2012-11-26 18:58:24 +00:00
next = ConvertPStateToInterpolateState( current );
previous = next;
2012-11-26 18:58:24 +00:00
hasMaster = false;
isOrientated = false;
}
/*
================
idPhysics_Static::~idPhysics_Static
================
*/
idPhysics_Static::~idPhysics_Static()
{
if( self && self->GetPhysics() == this )
{
2012-11-26 18:58:24 +00:00
self->SetPhysics( NULL );
}
idForce::DeletePhysics( this );
if( clipModel )
{
2012-11-26 18:58:24 +00:00
delete clipModel;
}
}
/*
================
idPhysics_Static::Save
================
*/
void idPhysics_Static::Save( idSaveGame* savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile->WriteObject( self );
2012-11-26 18:58:24 +00:00
savefile->WriteVec3( current.origin );
savefile->WriteMat3( current.axis );
savefile->WriteVec3( current.localOrigin );
savefile->WriteMat3( current.localAxis );
savefile->WriteClipModel( clipModel );
2012-11-26 18:58:24 +00:00
savefile->WriteBool( hasMaster );
savefile->WriteBool( isOrientated );
}
/*
================
idPhysics_Static::Restore
================
*/
void idPhysics_Static::Restore( idRestoreGame* savefile )
{
savefile->ReadObject( reinterpret_cast<idClass*&>( self ) );
2012-11-26 18:58:24 +00:00
savefile->ReadVec3( current.origin );
savefile->ReadMat3( current.axis );
savefile->ReadVec3( current.localOrigin );
savefile->ReadMat3( current.localAxis );
savefile->ReadClipModel( clipModel );
2012-11-26 18:58:24 +00:00
savefile->ReadBool( hasMaster );
savefile->ReadBool( isOrientated );
}
/*
================
idPhysics_Static::SetSelf
================
*/
void idPhysics_Static::SetSelf( idEntity* e )
{
2012-11-26 18:58:24 +00:00
assert( e );
self = e;
}
/*
================
idPhysics_Static::SetClipModel
================
*/
void idPhysics_Static::SetClipModel( idClipModel* model, float density, int id, bool freeOld )
{
2012-11-26 18:58:24 +00:00
assert( self );
if( clipModel && clipModel != model && freeOld )
{
2012-11-26 18:58:24 +00:00
delete clipModel;
}
clipModel = model;
if( clipModel )
{
2012-11-26 18:58:24 +00:00
clipModel->Link( gameLocal.clip, self, 0, current.origin, current.axis );
}
}
/*
================
idPhysics_Static::GetClipModel
================
*/
idClipModel* idPhysics_Static::GetClipModel( int id ) const
{
if( clipModel )
{
2012-11-26 18:58:24 +00:00
return clipModel;
}
return gameLocal.clip.DefaultClipModel();
}
/*
================
idPhysics_Static::GetNumClipModels
================
*/
int idPhysics_Static::GetNumClipModels() const
{
2012-11-26 18:58:24 +00:00
return ( clipModel != NULL );
}
/*
================
idPhysics_Static::SetMass
================
*/
void idPhysics_Static::SetMass( float mass, int id )
{
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::GetMass
================
*/
float idPhysics_Static::GetMass( int id ) const
{
2012-11-26 18:58:24 +00:00
return 0.0f;
}
/*
================
idPhysics_Static::SetContents
================
*/
void idPhysics_Static::SetContents( int contents, int id )
{
if( clipModel )
{
2012-11-26 18:58:24 +00:00
clipModel->SetContents( contents );
}
}
/*
================
idPhysics_Static::GetContents
================
*/
int idPhysics_Static::GetContents( int id ) const
{
if( clipModel )
{
2012-11-26 18:58:24 +00:00
return clipModel->GetContents();
}
return 0;
}
/*
================
idPhysics_Static::SetClipMask
================
*/
void idPhysics_Static::SetClipMask( int mask, int id )
{
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::GetClipMask
================
*/
int idPhysics_Static::GetClipMask( int id ) const
{
2012-11-26 18:58:24 +00:00
return 0;
}
/*
================
idPhysics_Static::GetBounds
================
*/
const idBounds& idPhysics_Static::GetBounds( int id ) const
{
if( clipModel )
{
2012-11-26 18:58:24 +00:00
return clipModel->GetBounds();
}
return bounds_zero;
}
/*
================
idPhysics_Static::GetAbsBounds
================
*/
const idBounds& idPhysics_Static::GetAbsBounds( int id ) const
{
2012-11-26 18:58:24 +00:00
static idBounds absBounds;
if( clipModel )
{
2012-11-26 18:58:24 +00:00
return clipModel->GetAbsBounds();
}
absBounds[0] = absBounds[1] = current.origin;
return absBounds;
}
/*
================
idPhysics_Static::Evaluate
================
*/
bool idPhysics_Static::Evaluate( int timeStepMSec, int endTimeMSec )
{
2012-11-26 18:58:24 +00:00
idVec3 masterOrigin, oldOrigin;
idMat3 masterAxis, oldAxis;
if( hasMaster )
{
2012-11-26 18:58:24 +00:00
oldOrigin = current.origin;
oldAxis = current.axis;
2012-11-26 18:58:24 +00:00
self->GetMasterPosition( masterOrigin, masterAxis );
current.origin = masterOrigin + current.localOrigin * masterAxis;
if( isOrientated )
{
2012-11-26 18:58:24 +00:00
current.axis = current.localAxis * masterAxis;
}
else
{
2012-11-26 18:58:24 +00:00
current.axis = current.localAxis;
}
if( clipModel )
{
2012-11-26 18:58:24 +00:00
clipModel->Link( gameLocal.clip, self, 0, current.origin, current.axis );
}
2012-11-26 18:58:24 +00:00
return ( current.origin != oldOrigin || current.axis != oldAxis );
}
return false;
}
/*
================
idPhysics_Static::Interpolate
================
*/
bool idPhysics_Static::Interpolate( const float fraction )
{
2012-11-26 18:58:24 +00:00
// We only interpolate if we actually get snapshots.
if( self->GetNumSnapshotsReceived() >= 1 )
{
2012-11-26 18:58:24 +00:00
current = InterpolateStaticPState( previous, next, fraction );
}
2012-11-26 18:58:24 +00:00
return true;
}
/*
================
idPhysics_Static::UpdateTime
================
*/
void idPhysics_Static::UpdateTime( int endTimeMSec )
{
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::GetTime
================
*/
int idPhysics_Static::GetTime() const
{
2012-11-26 18:58:24 +00:00
return 0;
}
/*
================
idPhysics_Static::GetImpactInfo
================
*/
void idPhysics_Static::GetImpactInfo( const int id, const idVec3& point, impactInfo_t* info ) const
{
2012-11-26 18:58:24 +00:00
memset( info, 0, sizeof( *info ) );
}
/*
================
idPhysics_Static::ApplyImpulse
================
*/
void idPhysics_Static::ApplyImpulse( const int id, const idVec3& point, const idVec3& impulse )
{
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::AddForce
================
*/
void idPhysics_Static::AddForce( const int id, const idVec3& point, const idVec3& force )
{
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::Activate
================
*/
void idPhysics_Static::Activate()
{
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::PutToRest
================
*/
void idPhysics_Static::PutToRest()
{
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::IsAtRest
================
*/
bool idPhysics_Static::IsAtRest() const
{
2012-11-26 18:58:24 +00:00
return true;
}
/*
================
idPhysics_Static::GetRestStartTime
================
*/
int idPhysics_Static::GetRestStartTime() const
{
2012-11-26 18:58:24 +00:00
return 0;
}
/*
================
idPhysics_Static::IsPushable
================
*/
bool idPhysics_Static::IsPushable() const
{
2012-11-26 18:58:24 +00:00
return false;
}
/*
================
idPhysics_Static::SaveState
================
*/
void idPhysics_Static::SaveState()
{
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::RestoreState
================
*/
void idPhysics_Static::RestoreState()
{
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::SetOrigin
================
*/
void idPhysics_Static::SetOrigin( const idVec3& newOrigin, int id )
{
2012-11-26 18:58:24 +00:00
idVec3 masterOrigin;
idMat3 masterAxis;
2012-11-26 18:58:24 +00:00
current.localOrigin = newOrigin;
if( hasMaster )
{
2012-11-26 18:58:24 +00:00
self->GetMasterPosition( masterOrigin, masterAxis );
current.origin = masterOrigin + newOrigin * masterAxis;
}
else
{
2012-11-26 18:58:24 +00:00
current.origin = newOrigin;
}
if( clipModel )
{
2012-11-26 18:58:24 +00:00
clipModel->Link( gameLocal.clip, self, 0, current.origin, current.axis );
}
2012-11-26 18:58:24 +00:00
next = ConvertPStateToInterpolateState( current );
previous = next;
}
/*
================
idPhysics_Static::SetAxis
================
*/
void idPhysics_Static::SetAxis( const idMat3& newAxis, int id )
{
2012-11-26 18:58:24 +00:00
idVec3 masterOrigin;
idMat3 masterAxis;
2012-11-26 18:58:24 +00:00
current.localAxis = newAxis;
if( hasMaster && isOrientated )
{
2012-11-26 18:58:24 +00:00
self->GetMasterPosition( masterOrigin, masterAxis );
current.axis = newAxis * masterAxis;
}
else
{
2012-11-26 18:58:24 +00:00
current.axis = newAxis;
}
if( clipModel )
{
2012-11-26 18:58:24 +00:00
clipModel->Link( gameLocal.clip, self, 0, current.origin, current.axis );
}
2012-11-26 18:58:24 +00:00
next = ConvertPStateToInterpolateState( current );
previous = next;
}
/*
================
idPhysics_Static::Translate
================
*/
void idPhysics_Static::Translate( const idVec3& translation, int id )
{
2012-11-26 18:58:24 +00:00
current.localOrigin += translation;
current.origin += translation;
if( clipModel )
{
2012-11-26 18:58:24 +00:00
clipModel->Link( gameLocal.clip, self, 0, current.origin, current.axis );
}
}
/*
================
idPhysics_Static::Rotate
================
*/
void idPhysics_Static::Rotate( const idRotation& rotation, int id )
{
2012-11-26 18:58:24 +00:00
idVec3 masterOrigin;
idMat3 masterAxis;
2012-11-26 18:58:24 +00:00
current.origin *= rotation;
current.axis *= rotation.ToMat3();
if( hasMaster )
{
2012-11-26 18:58:24 +00:00
self->GetMasterPosition( masterOrigin, masterAxis );
current.localAxis *= rotation.ToMat3();
current.localOrigin = ( current.origin - masterOrigin ) * masterAxis.Transpose();
}
else
{
2012-11-26 18:58:24 +00:00
current.localAxis = current.axis;
current.localOrigin = current.origin;
}
if( clipModel )
{
2012-11-26 18:58:24 +00:00
clipModel->Link( gameLocal.clip, self, 0, current.origin, current.axis );
}
}
/*
================
idPhysics_Static::GetOrigin
================
*/
const idVec3& idPhysics_Static::GetOrigin( int id ) const
{
2012-11-26 18:58:24 +00:00
return current.origin;
}
/*
================
idPhysics_Static::GetAxis
================
*/
const idMat3& idPhysics_Static::GetAxis( int id ) const
{
2012-11-26 18:58:24 +00:00
return current.axis;
}
/*
================
idPhysics_Static::SetLinearVelocity
================
*/
void idPhysics_Static::SetLinearVelocity( const idVec3& newLinearVelocity, int id )
{
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::SetAngularVelocity
================
*/
void idPhysics_Static::SetAngularVelocity( const idVec3& newAngularVelocity, int id )
{
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::GetLinearVelocity
================
*/
const idVec3& idPhysics_Static::GetLinearVelocity( int id ) const
{
2012-11-26 18:58:24 +00:00
return vec3_origin;
}
/*
================
idPhysics_Static::GetAngularVelocity
================
*/
const idVec3& idPhysics_Static::GetAngularVelocity( int id ) const
{
2012-11-26 18:58:24 +00:00
return vec3_origin;
}
/*
================
idPhysics_Static::SetGravity
================
*/
void idPhysics_Static::SetGravity( const idVec3& newGravity )
{
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::GetGravity
================
*/
const idVec3& idPhysics_Static::GetGravity() const
{
2012-11-26 18:58:24 +00:00
static idVec3 gravity( 0, 0, -g_gravity.GetFloat() );
return gravity;
}
/*
================
idPhysics_Static::GetGravityNormal
================
*/
const idVec3& idPhysics_Static::GetGravityNormal() const
{
2012-11-26 18:58:24 +00:00
static idVec3 gravity( 0, 0, -1 );
return gravity;
}
/*
================
idPhysics_Static::ClipTranslation
================
*/
void idPhysics_Static::ClipTranslation( trace_t& results, const idVec3& translation, const idClipModel* model ) const
{
if( model )
{
2012-11-26 18:58:24 +00:00
gameLocal.clip.TranslationModel( results, current.origin, current.origin + translation,
clipModel, current.axis, MASK_SOLID, model->Handle(), model->GetOrigin(), model->GetAxis() );
}
else
{
2012-11-26 18:58:24 +00:00
gameLocal.clip.Translation( results, current.origin, current.origin + translation,
clipModel, current.axis, MASK_SOLID, self );
}
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::ClipRotation
================
*/
void idPhysics_Static::ClipRotation( trace_t& results, const idRotation& rotation, const idClipModel* model ) const
{
if( model )
{
2012-11-26 18:58:24 +00:00
gameLocal.clip.RotationModel( results, current.origin, rotation,
clipModel, current.axis, MASK_SOLID, model->Handle(), model->GetOrigin(), model->GetAxis() );
}
else
{
2012-11-26 18:58:24 +00:00
gameLocal.clip.Rotation( results, current.origin, rotation, clipModel, current.axis, MASK_SOLID, self );
}
}
/*
================
idPhysics_Static::ClipContents
================
*/
int idPhysics_Static::ClipContents( const idClipModel* model ) const
{
if( clipModel )
{
if( model )
{
2012-11-26 18:58:24 +00:00
return gameLocal.clip.ContentsModel( clipModel->GetOrigin(), clipModel, clipModel->GetAxis(), -1,
model->Handle(), model->GetOrigin(), model->GetAxis() );
}
else
{
2012-11-26 18:58:24 +00:00
return gameLocal.clip.Contents( clipModel->GetOrigin(), clipModel, clipModel->GetAxis(), -1, NULL );
}
}
return 0;
}
/*
================
idPhysics_Static::DisableClip
================
*/
void idPhysics_Static::DisableClip()
{
if( clipModel )
{
2012-11-26 18:58:24 +00:00
clipModel->Disable();
}
}
/*
================
idPhysics_Static::EnableClip
================
*/
void idPhysics_Static::EnableClip()
{
if( clipModel )
{
2012-11-26 18:58:24 +00:00
clipModel->Enable();
}
}
/*
================
idPhysics_Static::UnlinkClip
================
*/
void idPhysics_Static::UnlinkClip()
{
if( clipModel )
{
2012-11-26 18:58:24 +00:00
clipModel->Unlink();
}
}
/*
================
idPhysics_Static::LinkClip
================
*/
void idPhysics_Static::LinkClip()
{
if( clipModel )
{
2012-11-26 18:58:24 +00:00
clipModel->Link( gameLocal.clip, self, 0, current.origin, current.axis );
}
}
/*
================
idPhysics_Static::EvaluateContacts
================
*/
bool idPhysics_Static::EvaluateContacts()
{
2012-11-26 18:58:24 +00:00
return false;
}
/*
================
idPhysics_Static::GetNumContacts
================
*/
int idPhysics_Static::GetNumContacts() const
{
2012-11-26 18:58:24 +00:00
return 0;
}
/*
================
idPhysics_Static::GetContact
================
*/
const contactInfo_t& idPhysics_Static::GetContact( int num ) const
{
2012-11-26 18:58:24 +00:00
static contactInfo_t info;
memset( &info, 0, sizeof( info ) );
return info;
}
/*
================
idPhysics_Static::ClearContacts
================
*/
void idPhysics_Static::ClearContacts()
{
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::AddContactEntity
================
*/
void idPhysics_Static::AddContactEntity( idEntity* e )
{
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::RemoveContactEntity
================
*/
void idPhysics_Static::RemoveContactEntity( idEntity* e )
{
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::HasGroundContacts
================
*/
bool idPhysics_Static::HasGroundContacts() const
{
2012-11-26 18:58:24 +00:00
return false;
}
/*
================
idPhysics_Static::IsGroundEntity
================
*/
bool idPhysics_Static::IsGroundEntity( int entityNum ) const
{
2012-11-26 18:58:24 +00:00
return false;
}
/*
================
idPhysics_Static::IsGroundClipModel
================
*/
bool idPhysics_Static::IsGroundClipModel( int entityNum, int id ) const
{
2012-11-26 18:58:24 +00:00
return false;
}
/*
================
idPhysics_Static::SetPushed
================
*/
void idPhysics_Static::SetPushed( int deltaTime )
{
2012-11-26 18:58:24 +00:00
}
/*
================
idPhysics_Static::GetPushedLinearVelocity
================
*/
const idVec3& idPhysics_Static::GetPushedLinearVelocity( const int id ) const
{
2012-11-26 18:58:24 +00:00
return vec3_origin;
}
/*
================
idPhysics_Static::GetPushedAngularVelocity
================
*/
const idVec3& idPhysics_Static::GetPushedAngularVelocity( const int id ) const
{
2012-11-26 18:58:24 +00:00
return vec3_origin;
}
/*
================
idPhysics_Static::SetMaster
================
*/
void idPhysics_Static::SetMaster( idEntity* master, const bool orientated )
{
2012-11-26 18:58:24 +00:00
idVec3 masterOrigin;
idMat3 masterAxis;
if( master )
{
if( !hasMaster )
{
2012-11-26 18:58:24 +00:00
// transform from world space to master space
self->GetMasterPosition( masterOrigin, masterAxis );
current.localOrigin = ( current.origin - masterOrigin ) * masterAxis.Transpose();
if( orientated )
{
2012-11-26 18:58:24 +00:00
current.localAxis = current.axis * masterAxis.Transpose();
}
else
{
2012-11-26 18:58:24 +00:00
current.localAxis = current.axis;
}
hasMaster = true;
isOrientated = orientated;
}
}
else
{
if( hasMaster )
{
2012-11-26 18:58:24 +00:00
hasMaster = false;
}
}
}
/*
================
idPhysics_Static::GetBlockingInfo
================
*/
const trace_t* idPhysics_Static::GetBlockingInfo() const
{
2012-11-26 18:58:24 +00:00
return NULL;
}
/*
================
idPhysics_Static::GetBlockingEntity
================
*/
idEntity* idPhysics_Static::GetBlockingEntity() const
{
2012-11-26 18:58:24 +00:00
return NULL;
}
/*
================
idPhysics_Static::GetLinearEndTime
================
*/
int idPhysics_Static::GetLinearEndTime() const
{
2012-11-26 18:58:24 +00:00
return 0;
}
/*
================
idPhysics_Static::GetAngularEndTime
================
*/
int idPhysics_Static::GetAngularEndTime() const
{
2012-11-26 18:58:24 +00:00
return 0;
}
/*
================
idPhysics_Static::WriteToSnapshot
================
*/
void idPhysics_Static::WriteToSnapshot( idBitMsg& msg ) const
{
2012-11-26 18:58:24 +00:00
idCQuat quat, localQuat;
2012-11-26 18:58:24 +00:00
quat = current.axis.ToCQuat();
localQuat = current.localAxis.ToCQuat();
2012-11-26 18:58:24 +00:00
msg.WriteFloat( current.origin[0] );
msg.WriteFloat( current.origin[1] );
msg.WriteFloat( current.origin[2] );
msg.WriteFloat( quat.x );
msg.WriteFloat( quat.y );
msg.WriteFloat( quat.z );
msg.WriteDeltaFloat( current.origin[0], current.localOrigin[0] );
msg.WriteDeltaFloat( current.origin[1], current.localOrigin[1] );
msg.WriteDeltaFloat( current.origin[2], current.localOrigin[2] );
msg.WriteDeltaFloat( quat.x, localQuat.x );
msg.WriteDeltaFloat( quat.y, localQuat.y );
msg.WriteDeltaFloat( quat.z, localQuat.z );
}
/*
================
idPhysics_Base::ReadFromSnapshot
================
*/
void idPhysics_Static::ReadFromSnapshot( const idBitMsg& msg )
{
2012-11-26 18:58:24 +00:00
idCQuat quat, localQuat;
2012-11-26 18:58:24 +00:00
previous = next;
2012-11-26 18:58:24 +00:00
next = ReadStaticInterpolatePStateFromSnapshot( msg );
}
/*
================
ConvertInterpolateStateToPState
================
*/
staticPState_s ConvertInterpolateStateToPState( const staticInterpolatePState_t& interpolateState )
{
2012-11-26 18:58:24 +00:00
staticPState_s state;
state.origin = interpolateState.origin;
state.localOrigin = interpolateState.localOrigin;
state.localAxis = interpolateState.localAxis.ToMat3();
state.axis = interpolateState.axis.ToMat3();
2012-11-26 18:58:24 +00:00
return state;
}
/*
================
ConvertPStateToInterpolateState
================
*/
staticInterpolatePState_t ConvertPStateToInterpolateState( const staticPState_t& state )
{
2012-11-26 18:58:24 +00:00
staticInterpolatePState_t interpolateState;
interpolateState.origin = state.origin;
interpolateState.localOrigin = state.localOrigin;
interpolateState.localAxis = state.localAxis.ToQuat();
interpolateState.axis = state.axis.ToQuat();
2012-11-26 18:58:24 +00:00
return interpolateState;
}
/*
================
ReadStaticInterpolatePStateFromSnapshot
================
*/
staticInterpolatePState_t ReadStaticInterpolatePStateFromSnapshot( const idBitMsg& msg )
{
2012-11-26 18:58:24 +00:00
staticInterpolatePState_t state;
2012-11-26 18:58:24 +00:00
state.origin = ReadFloatArray< idVec3 >( msg );
const idCQuat cAxis = ReadFloatArray< idCQuat >( msg );
state.localOrigin = ReadDeltaFloatArray( msg, state.origin );
state.localAxis = ReadDeltaFloatArray( msg, cAxis ).ToQuat();
2012-11-26 18:58:24 +00:00
state.axis = cAxis.ToQuat();
2012-11-26 18:58:24 +00:00
return state;
}
/*
================
InterpolateStaticPState
================
*/
staticPState_t InterpolateStaticPState( const staticInterpolatePState_t& previous, const staticInterpolatePState_t& next, float fraction )
{
2012-11-26 18:58:24 +00:00
staticPState_t result;
result.origin = Lerp( previous.origin, next.origin, fraction );
result.axis = idQuat().Slerp( previous.axis, next.axis, fraction ).ToMat3();
2012-11-26 18:58:24 +00:00
result.localOrigin = Lerp( previous.localOrigin, next.localOrigin, fraction );
result.localAxis = idQuat().Slerp( previous.localAxis, next.localAxis, fraction ).ToMat3();
2012-11-26 18:58:24 +00:00
return result;
}