2013-12-06 09:46:30 +01:00
|
|
|
#ifndef PHYSICS_STRUCTS_IMPL_H
|
|
|
|
#define PHYSICS_STRUCTS_IMPL_H
|
|
|
|
|
|
|
|
#include "PhysicsStructs.h"
|
2014-01-14 10:34:22 +01:00
|
|
|
#include "OysterPhysics3D.h"
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2013-12-19 14:30:16 +01:00
|
|
|
namespace Oyster
|
|
|
|
{
|
|
|
|
namespace Physics
|
2013-12-06 09:46:30 +01:00
|
|
|
{
|
2013-12-19 14:30:16 +01:00
|
|
|
namespace Struct
|
2013-12-06 09:46:30 +01:00
|
|
|
{
|
2013-12-19 14:30:16 +01:00
|
|
|
inline SimpleBodyDescription::SimpleBodyDescription()
|
|
|
|
{
|
2014-02-03 15:48:42 +01:00
|
|
|
this->rotation = ::Oyster::Math::Float3::null;
|
2014-01-28 09:52:58 +01:00
|
|
|
this->centerPosition = ::Oyster::Math::Float3::null;
|
|
|
|
this->size = ::Oyster::Math::Float3( 1.0f );
|
2014-01-29 14:57:39 +01:00
|
|
|
this->mass = 6.0f;
|
2014-01-21 11:48:04 +01:00
|
|
|
this->restitutionCoeff = 1.0f;
|
|
|
|
this->frictionCoeff_Dynamic = 0.5f;
|
|
|
|
this->frictionCoeff_Static = 0.5f;
|
2014-01-23 19:13:02 +01:00
|
|
|
this->inertiaTensor = ::Oyster::Physics3D::MomentOfInertia();
|
2014-01-17 16:07:25 +01:00
|
|
|
this->subscription_onCollision = NULL;
|
2014-01-22 14:09:53 +01:00
|
|
|
this->subscription_onCollisionResponse = NULL;
|
2014-01-17 16:07:25 +01:00
|
|
|
this->subscription_onMovement = NULL;
|
2013-12-19 14:30:16 +01:00
|
|
|
this->ignoreGravity = false;
|
|
|
|
}
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2013-12-19 14:30:16 +01:00
|
|
|
inline SphericalBodyDescription::SphericalBodyDescription()
|
|
|
|
{
|
2014-02-03 15:48:42 +01:00
|
|
|
this->rotation = ::Oyster::Math::Float3::null;
|
2014-01-28 09:52:58 +01:00
|
|
|
this->centerPosition = ::Oyster::Math::Float3::null;
|
2013-12-19 14:30:16 +01:00
|
|
|
this->radius = 0.5f;
|
|
|
|
this->mass = 10.0f;
|
2014-01-21 11:48:04 +01:00
|
|
|
this->restitutionCoeff = 1.0f;
|
|
|
|
this->frictionCoeff_Dynamic = 0.5f;
|
|
|
|
this->frictionCoeff_Static = 0.5f;
|
2014-01-17 16:07:25 +01:00
|
|
|
this->subscription_onCollision = NULL;
|
2014-01-22 14:09:53 +01:00
|
|
|
this->subscription_onCollisionResponse = NULL;
|
2014-01-17 16:07:25 +01:00
|
|
|
this->subscription_onMovement = NULL;
|
2013-12-19 14:30:16 +01:00
|
|
|
this->ignoreGravity = false;
|
|
|
|
}
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline CustomBodyState::CustomBodyState( ::Oyster::Math::Float mass, ::Oyster::Math::Float restitutionCoeff, ::Oyster::Math::Float staticFrictionCoeff, ::Oyster::Math::Float kineticFrictionCoeff, const ::Oyster::Physics3D::MomentOfInertia &inertiaTensor, const ::Oyster::Math::Float3 &reach, const ::Oyster::Math::Float3 ¢erPos, const ::Oyster::Math::Float3 &rotation, const ::Oyster::Math::Float3 &linearMomentum, const ::Oyster::Math::Float3 &angularMomentum, const ::Oyster::Math::Float3 &gravityNormal )
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
2014-01-09 11:36:55 +01:00
|
|
|
this->mass = mass;
|
|
|
|
this->restitutionCoeff = restitutionCoeff;
|
|
|
|
this->staticFrictionCoeff = staticFrictionCoeff;
|
|
|
|
this->kineticFrictionCoeff = kineticFrictionCoeff;
|
|
|
|
this->inertiaTensor = inertiaTensor;
|
|
|
|
this->reach = reach;
|
|
|
|
this->centerPos = centerPos;
|
|
|
|
this->angularAxis = rotation;
|
|
|
|
this->linearMomentum = linearMomentum;
|
|
|
|
this->angularMomentum = angularMomentum;
|
2014-01-28 09:52:58 +01:00
|
|
|
this->linearImpulse = this->angularImpulse = ::Oyster::Math::Float3::null;
|
|
|
|
this->deltaPos = this->deltaAxis = ::Oyster::Math::Float3::null;
|
2014-01-09 11:36:55 +01:00
|
|
|
this->isSpatiallyAltered = this->isDisturbed = this->isForwarded = false;
|
2014-01-21 14:56:34 +01:00
|
|
|
this->gravityNormal = gravityNormal;
|
2013-12-19 14:30:16 +01:00
|
|
|
}
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2013-12-19 14:30:16 +01:00
|
|
|
inline CustomBodyState & CustomBodyState::operator = ( const CustomBodyState &state )
|
|
|
|
{
|
2014-01-09 11:36:55 +01:00
|
|
|
this->mass = state.mass;
|
|
|
|
this->restitutionCoeff = state.restitutionCoeff;
|
|
|
|
this->staticFrictionCoeff = state.staticFrictionCoeff;
|
|
|
|
this->kineticFrictionCoeff = state.kineticFrictionCoeff;
|
|
|
|
this->inertiaTensor = state.inertiaTensor;
|
2013-12-19 14:30:16 +01:00
|
|
|
this->reach = state.reach;
|
|
|
|
this->centerPos = state.centerPos;
|
|
|
|
this->angularAxis = state.angularAxis;
|
2014-01-09 11:36:55 +01:00
|
|
|
this->linearMomentum = state.linearMomentum;
|
|
|
|
this->angularMomentum = state.angularMomentum;
|
|
|
|
this->linearImpulse = state.linearImpulse;
|
|
|
|
this->angularImpulse = state.angularImpulse;
|
|
|
|
this->deltaPos = state.deltaPos;
|
|
|
|
this->deltaAxis = state.deltaAxis;
|
2013-12-19 14:30:16 +01:00
|
|
|
this->isSpatiallyAltered = state.isSpatiallyAltered;
|
|
|
|
this->isDisturbed = state.isDisturbed;
|
2014-01-09 11:36:55 +01:00
|
|
|
this->isForwarded = state.isForwarded;
|
2014-01-21 14:56:34 +01:00
|
|
|
this->gravityNormal = state.gravityNormal;
|
2013-12-19 14:30:16 +01:00
|
|
|
return *this;
|
|
|
|
}
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline const ::Oyster::Math::Float CustomBodyState::GetMass() const
|
|
|
|
{
|
|
|
|
return this->mass;
|
|
|
|
}
|
2013-12-18 14:16:13 +01:00
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline const ::Oyster::Math::Float CustomBodyState::GetRestitutionCoeff() const
|
|
|
|
{
|
|
|
|
return this->restitutionCoeff;
|
|
|
|
}
|
2013-12-18 14:16:13 +01:00
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline const ::Oyster::Math::Float CustomBodyState::GetFrictionCoeff_Static() const
|
|
|
|
{
|
|
|
|
return this->staticFrictionCoeff;
|
|
|
|
}
|
2013-12-19 10:03:56 +01:00
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline const ::Oyster::Math::Float CustomBodyState::GetFrictionCoeff_Kinetic() const
|
|
|
|
{
|
|
|
|
return this->kineticFrictionCoeff;
|
|
|
|
}
|
2013-12-18 14:16:13 +01:00
|
|
|
|
2014-01-23 19:13:02 +01:00
|
|
|
inline const ::Oyster::Physics3D::MomentOfInertia & CustomBodyState::GetMomentOfInertia() const
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
|
|
|
return this->inertiaTensor;
|
|
|
|
}
|
2013-12-18 14:16:13 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline const ::Oyster::Math::Float3 & CustomBodyState::GetReach() const
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
|
|
|
return this->reach;
|
|
|
|
}
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline ::Oyster::Math::Float3 CustomBodyState::GetSize() const
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
|
|
|
return 2.0f * this->GetReach();
|
|
|
|
}
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline const ::Oyster::Math::Float3 & CustomBodyState::GetCenterPosition() const
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
|
|
|
return this->centerPos;
|
|
|
|
}
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline const ::Oyster::Math::Float3 & CustomBodyState::GetAngularAxis() const
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
2014-01-31 15:30:23 +01:00
|
|
|
return this->angularAxis;
|
2013-12-19 14:30:16 +01:00
|
|
|
}
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2013-12-19 14:30:16 +01:00
|
|
|
inline ::Oyster::Math::Float4x4 CustomBodyState::GetRotation() const
|
|
|
|
{
|
2014-01-28 09:52:58 +01:00
|
|
|
return ::Oyster::Math3D::RotationMatrix( this->GetAngularAxis() );
|
2013-12-19 14:30:16 +01:00
|
|
|
}
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline ::Oyster::Math::Float4x4 CustomBodyState::GetOrientation() const
|
|
|
|
{
|
2014-01-28 09:52:58 +01:00
|
|
|
return ::Oyster::Math3D::OrientationMatrix( this->angularAxis, this->centerPos );
|
2014-01-09 11:36:55 +01:00
|
|
|
}
|
2014-01-09 10:42:22 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline ::Oyster::Math::Float4x4 CustomBodyState::GetOrientation( const ::Oyster::Math::Float3 &offset ) const
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
2014-01-28 09:52:58 +01:00
|
|
|
return ::Oyster::Math3D::OrientationMatrix( this->angularAxis, (this->centerPos + offset) );
|
2014-01-09 11:36:55 +01:00
|
|
|
}
|
2013-12-18 08:57:27 +01:00
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline ::Oyster::Math::Float4x4 CustomBodyState::GetView() const
|
|
|
|
{
|
2014-01-28 09:52:58 +01:00
|
|
|
return ::Oyster::Math3D::ViewMatrix( this->angularAxis, this->centerPos );
|
2014-01-09 11:36:55 +01:00
|
|
|
}
|
2014-01-09 10:42:22 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline ::Oyster::Math::Float4x4 CustomBodyState::GetView( const ::Oyster::Math::Float3 &offset ) const
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
2014-01-28 09:52:58 +01:00
|
|
|
return ::Oyster::Math3D::ViewMatrix( this->angularAxis, (this->centerPos + offset) );
|
2014-01-09 11:36:55 +01:00
|
|
|
}
|
2013-12-18 08:57:27 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline const ::Oyster::Math::Float3 & CustomBodyState::GetLinearMomentum() const
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
|
|
|
return this->linearMomentum;
|
|
|
|
}
|
2013-12-18 08:57:27 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline ::Oyster::Math::Float3 CustomBodyState::GetLinearMomentum( const ::Oyster::Math::Float3 &at ) const
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
2014-02-04 15:43:17 +01:00
|
|
|
::Oyster::Math::Float3 offset = at - this->centerPos;
|
|
|
|
if( offset.Dot(offset) > 0.0f )
|
|
|
|
{
|
|
|
|
return this->linearMomentum + ::Oyster::Physics3D::Formula::TangentialLinearMomentum( this->angularMomentum, offset );
|
|
|
|
}
|
|
|
|
return this->linearMomentum;
|
2014-01-09 11:36:55 +01:00
|
|
|
}
|
2013-12-18 08:57:27 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline const ::Oyster::Math::Float3 & CustomBodyState::GetAngularMomentum() const
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
|
|
|
return this->angularMomentum;
|
|
|
|
}
|
2013-12-18 14:16:13 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline const ::Oyster::Math::Float3 & CustomBodyState::GetLinearImpulse() const
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
|
|
|
return this->linearImpulse;
|
|
|
|
}
|
2013-12-18 14:16:13 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline const ::Oyster::Math::Float3 & CustomBodyState::GetAngularImpulse() const
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
|
|
|
return this->angularImpulse;
|
|
|
|
}
|
2013-12-20 11:13:44 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline const ::Oyster::Math::Float3 & CustomBodyState::GetForward_DeltaPos() const
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
|
|
|
return this->deltaPos;
|
|
|
|
}
|
2013-12-20 11:13:44 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline const ::Oyster::Math::Float3 & CustomBodyState::GetForward_DeltaAxis() const
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
|
|
|
return this->deltaAxis;
|
|
|
|
}
|
2013-12-18 14:16:13 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline const ::Oyster::Math::Float3 & CustomBodyState::GetGravityNormal() const
|
2014-01-21 14:56:34 +01:00
|
|
|
{
|
|
|
|
return this->gravityNormal;
|
|
|
|
}
|
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline void CustomBodyState::SetMass_KeepMomentum( ::Oyster::Math::Float m )
|
|
|
|
{
|
2013-12-18 14:16:13 +01:00
|
|
|
this->mass = m;
|
|
|
|
}
|
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline void CustomBodyState::SetMass_KeepVelocity( ::Oyster::Math::Float m )
|
|
|
|
{
|
|
|
|
if( m != 0.0f )
|
|
|
|
{ // sanity block!
|
|
|
|
this->linearMomentum *= (m / this->mass);
|
|
|
|
this->mass = m;
|
|
|
|
}
|
|
|
|
}
|
2013-12-18 14:16:13 +01:00
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline void CustomBodyState::SetRestitutionCoeff( ::Oyster::Math::Float e )
|
|
|
|
{
|
|
|
|
this->restitutionCoeff = e;
|
|
|
|
}
|
2013-12-18 14:16:13 +01:00
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline void CustomBodyState::SetFrictionCoeff( ::Oyster::Math::Float staticU, ::Oyster::Math::Float kineticU )
|
|
|
|
{
|
|
|
|
this->staticFrictionCoeff = staticU;
|
|
|
|
this->kineticFrictionCoeff = kineticU;
|
|
|
|
}
|
2013-12-18 14:16:13 +01:00
|
|
|
|
2014-01-23 19:13:02 +01:00
|
|
|
inline void CustomBodyState::SetMomentOfInertia_KeepMomentum( const ::Oyster::Physics3D::MomentOfInertia &tensor )
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
2013-12-18 14:16:13 +01:00
|
|
|
this->inertiaTensor = tensor;
|
|
|
|
}
|
2014-01-09 11:36:55 +01:00
|
|
|
|
2014-01-23 19:13:02 +01:00
|
|
|
inline void CustomBodyState::SetMomentOfInertia_KeepVelocity( const ::Oyster::Physics3D::MomentOfInertia &tensor )
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
2014-01-23 19:13:02 +01:00
|
|
|
::Oyster::Math::Quaternion rotation = ::Oyster::Math3D::Rotation(this->angularAxis);
|
2014-01-28 09:52:58 +01:00
|
|
|
::Oyster::Math::Float3 w = this->inertiaTensor.CalculateAngularVelocity( rotation, this->angularMomentum );
|
2014-01-23 19:13:02 +01:00
|
|
|
this->inertiaTensor = tensor;
|
|
|
|
this->angularMomentum = this->inertiaTensor.CalculateAngularMomentum( rotation, w );
|
2014-01-09 11:36:55 +01:00
|
|
|
}
|
2013-12-18 14:16:13 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline void CustomBodyState::SetSize( const ::Oyster::Math::Float3 &size )
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
|
|
|
this->SetReach( 0.5f * size );
|
|
|
|
}
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline void CustomBodyState::SetReach( const ::Oyster::Math::Float3 &halfSize )
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
2014-01-28 09:52:58 +01:00
|
|
|
this->reach = halfSize;
|
|
|
|
this->reach = ::Utility::Value::Max( this->reach, ::Oyster::Math::Float3::null );
|
2013-12-19 14:30:16 +01:00
|
|
|
this->isSpatiallyAltered = this->isDisturbed = true;
|
|
|
|
}
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline void CustomBodyState::SetCenterPosition( const ::Oyster::Math::Float3 ¢erPos )
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
2014-01-28 09:52:58 +01:00
|
|
|
this->centerPos = centerPos;
|
2013-12-19 14:30:16 +01:00
|
|
|
this->isSpatiallyAltered = this->isDisturbed = true;
|
|
|
|
}
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline void CustomBodyState::SetRotation( const ::Oyster::Math::Float3 &angularAxis )
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
2014-01-28 09:52:58 +01:00
|
|
|
this->angularAxis = angularAxis;
|
2013-12-19 14:30:16 +01:00
|
|
|
this->isSpatiallyAltered = this->isDisturbed = true;
|
|
|
|
}
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2014-01-28 09:24:51 +01:00
|
|
|
inline void CustomBodyState::SetOrientation( const ::Oyster::Math::Float3 &angularAxis, const ::Oyster::Math::Float3 &translation )
|
|
|
|
{
|
2014-01-28 09:52:58 +01:00
|
|
|
this->angularAxis = angularAxis ;
|
|
|
|
this->centerPos = translation;
|
2014-01-28 09:24:51 +01:00
|
|
|
this->isSpatiallyAltered = this->isDisturbed = true;
|
|
|
|
}
|
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline void CustomBodyState::SetLinearMomentum( const ::Oyster::Math::Float3 &g )
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
2014-01-28 09:52:58 +01:00
|
|
|
this->linearMomentum = g;
|
2014-01-09 11:36:55 +01:00
|
|
|
this->isDisturbed = true;
|
|
|
|
}
|
2013-12-18 08:57:27 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline void CustomBodyState::SetAngularMomentum( const ::Oyster::Math::Float3 &h )
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
2014-01-28 09:52:58 +01:00
|
|
|
this->angularMomentum = h;
|
2014-01-09 11:36:55 +01:00
|
|
|
this->isDisturbed = true;
|
|
|
|
}
|
2013-12-18 08:57:27 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline void CustomBodyState::SetLinearImpulse( const ::Oyster::Math::Float3 &j )
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
2014-01-28 09:52:58 +01:00
|
|
|
this->linearImpulse = j;
|
2014-01-09 11:36:55 +01:00
|
|
|
this->isDisturbed = true;
|
|
|
|
}
|
2013-12-18 08:57:27 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline void CustomBodyState::SetAngularImpulse( const ::Oyster::Math::Float3 &j )
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
2014-01-28 09:52:58 +01:00
|
|
|
this->angularImpulse = j;
|
2014-01-09 11:36:55 +01:00
|
|
|
this->isDisturbed = true;
|
|
|
|
}
|
2013-12-18 08:57:27 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline void CustomBodyState::SetGravityNormal( const ::Oyster::Math::Float3 &gravityNormal )
|
2014-01-21 14:56:34 +01:00
|
|
|
{
|
|
|
|
this->gravityNormal = gravityNormal;
|
|
|
|
}
|
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline void CustomBodyState::AddRotation( const ::Oyster::Math::Float3 &angularAxis )
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
|
|
|
this->angularAxis += angularAxis;
|
|
|
|
this->isSpatiallyAltered = this->isDisturbed = true;
|
|
|
|
}
|
2013-12-18 14:16:13 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline void CustomBodyState::AddTranslation( const ::Oyster::Math::Float3 &deltaPos )
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
|
|
|
this->centerPos += deltaPos;
|
|
|
|
this->isSpatiallyAltered = this->isDisturbed = true;
|
|
|
|
}
|
2013-12-18 08:57:27 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline void CustomBodyState::ApplyLinearImpulse( const ::Oyster::Math::Float3 &j )
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
|
|
|
this->linearImpulse += j;
|
|
|
|
this->isDisturbed = true;
|
|
|
|
}
|
2013-12-18 14:16:13 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline void CustomBodyState::ApplyAngularImpulse( const ::Oyster::Math::Float3 &j )
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
|
|
|
this->angularImpulse += j;
|
|
|
|
this->isDisturbed = true;
|
|
|
|
}
|
2013-12-18 14:16:13 +01:00
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline void CustomBodyState::ApplyImpulse( const ::Oyster::Math::Float3 &j, const ::Oyster::Math::Float3 &at, const ::Oyster::Math::Float3 &normal )
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
2014-01-28 09:52:58 +01:00
|
|
|
::Oyster::Math::Float3 offset = at - this->centerPos;
|
2014-02-04 16:56:31 +01:00
|
|
|
if( offset.Dot(offset) > 0.0f )
|
|
|
|
{
|
|
|
|
::Oyster::Math::Float3 deltaAngularImpulse = ::Oyster::Physics3D::Formula::AngularMomentum( j, offset );
|
2013-12-18 08:57:27 +01:00
|
|
|
|
2014-02-04 16:56:31 +01:00
|
|
|
this->linearImpulse -= ::Oyster::Physics3D::Formula::TangentialLinearMomentum( deltaAngularImpulse, offset );
|
|
|
|
this->angularImpulse += deltaAngularImpulse;
|
|
|
|
}
|
|
|
|
this->linearImpulse += j;
|
2014-01-09 11:36:55 +01:00
|
|
|
this->isDisturbed = true;
|
|
|
|
}
|
2013-12-18 08:57:27 +01:00
|
|
|
|
2014-02-09 16:42:26 +01:00
|
|
|
inline void CustomBodyState::ApplyFriction( const ::Oyster::Math::Float3 &j )
|
|
|
|
{
|
|
|
|
this->linearImpulse += j;
|
|
|
|
this->isDisturbed = true;
|
|
|
|
}
|
|
|
|
|
2014-01-28 09:52:58 +01:00
|
|
|
inline void CustomBodyState::ApplyForwarding( const ::Oyster::Math::Float3 &deltaPos, const ::Oyster::Math::Float3 &deltaAxis )
|
2014-01-09 11:36:55 +01:00
|
|
|
{
|
|
|
|
this->deltaPos += deltaPos;
|
|
|
|
this->deltaAxis += deltaAxis;
|
|
|
|
this->isDisturbed = this->isForwarded = true;
|
2013-12-19 14:30:16 +01:00
|
|
|
}
|
2013-12-20 11:13:44 +01:00
|
|
|
|
2013-12-19 14:30:16 +01:00
|
|
|
inline bool CustomBodyState::IsSpatiallyAltered() const
|
|
|
|
{
|
|
|
|
return this->isSpatiallyAltered;
|
|
|
|
}
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2013-12-19 14:30:16 +01:00
|
|
|
inline bool CustomBodyState::IsDisturbed() const
|
|
|
|
{
|
|
|
|
return this->isDisturbed;
|
2014-01-09 11:36:55 +01:00
|
|
|
}
|
2013-12-20 11:13:44 +01:00
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline bool CustomBodyState::IsForwarded() const
|
|
|
|
{
|
|
|
|
return this->isForwarded;
|
2013-12-19 14:30:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline GravityWell::GravityWell( )
|
|
|
|
{
|
|
|
|
this->position = ::Oyster::Math::Float3::null;
|
|
|
|
this->mass = 0.0f;
|
|
|
|
}
|
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline GravityWell::GravityWell( const GravityWell &gravityWell )
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
|
|
|
this->position = gravityWell.position;
|
|
|
|
this->mass = gravityWell.mass;
|
|
|
|
}
|
|
|
|
|
2014-01-09 11:48:21 +01:00
|
|
|
inline GravityWell & GravityWell::operator = ( const GravityWell &gravityWell )
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
|
|
|
this->position = gravityWell.position;
|
|
|
|
this->mass = gravityWell.mass;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-01-15 10:44:20 +01:00
|
|
|
inline bool GravityWell::operator == ( const GravityWell &gravity ) const
|
|
|
|
{
|
|
|
|
if( this->position == gravity.position )
|
|
|
|
if( this->mass == gravity.mass )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool GravityWell::operator != ( const GravityWell &gravity ) const
|
|
|
|
{
|
|
|
|
if( this->position == gravity.position )
|
|
|
|
if( this->mass == gravity.mass )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-19 14:30:16 +01:00
|
|
|
inline GravityDirected::GravityDirected( )
|
|
|
|
{
|
|
|
|
this->impulse = ::Oyster::Math::Float3::null;
|
|
|
|
}
|
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline GravityDirected::GravityDirected( const GravityDirected &gravityDirected )
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
|
|
|
this->impulse = gravityDirected.impulse;
|
|
|
|
}
|
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline GravityDirected & GravityDirected::operator = ( const GravityDirected &gravityDirected )
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
|
|
|
this->impulse = gravityDirected.impulse;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-01-15 10:44:20 +01:00
|
|
|
inline bool GravityDirected::operator == ( const GravityDirected &gravity ) const
|
|
|
|
{
|
|
|
|
return this->impulse == gravity.impulse;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool GravityDirected::operator != ( const GravityDirected &gravity ) const
|
|
|
|
{
|
|
|
|
return this->impulse != gravity.impulse;
|
|
|
|
}
|
|
|
|
|
2013-12-19 14:30:16 +01:00
|
|
|
inline GravityDirectedField::GravityDirectedField( )
|
|
|
|
{
|
|
|
|
this->normalizedDirection = ::Oyster::Math::Float3::null;
|
|
|
|
this->mass = 0.0f;
|
|
|
|
this->magnitude = 0.0f;
|
|
|
|
}
|
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline GravityDirectedField::GravityDirectedField( const GravityDirectedField &gravityDirectedField )
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
|
|
|
this->normalizedDirection = gravityDirectedField.normalizedDirection;
|
|
|
|
this->mass = gravityDirectedField.mass;
|
|
|
|
this->magnitude = gravityDirectedField.magnitude;
|
|
|
|
}
|
2014-01-09 11:36:55 +01:00
|
|
|
|
2014-01-09 11:48:21 +01:00
|
|
|
inline GravityDirectedField & GravityDirectedField::operator = ( const GravityDirectedField &gravityDirectedField )
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
|
|
|
this->normalizedDirection = gravityDirectedField.normalizedDirection;
|
|
|
|
this->mass = gravityDirectedField.mass;
|
|
|
|
this->magnitude = gravityDirectedField.magnitude;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-01-15 10:44:20 +01:00
|
|
|
inline bool GravityDirectedField::operator == ( const GravityDirectedField &gravity ) const
|
|
|
|
{
|
|
|
|
if( this->normalizedDirection == gravity.normalizedDirection )
|
|
|
|
if( this->mass == gravity.mass )
|
|
|
|
if( this->magnitude == gravity.magnitude )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool GravityDirectedField::operator != ( const GravityDirectedField &gravity ) const
|
|
|
|
{
|
|
|
|
if( this->normalizedDirection == gravity.normalizedDirection )
|
|
|
|
if( this->mass == gravity.mass )
|
|
|
|
if( this->magnitude == gravity.magnitude )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-19 14:30:16 +01:00
|
|
|
inline Gravity::Gravity()
|
|
|
|
{
|
|
|
|
this->gravityType = GravityType_Undefined;
|
|
|
|
}
|
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline Gravity::Gravity( const Gravity &gravity )
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
2014-01-09 11:48:21 +01:00
|
|
|
this->gravityType = gravity.gravityType;
|
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
switch( gravity.gravityType )
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
|
|
|
case GravityType_Well:
|
2014-01-09 11:36:55 +01:00
|
|
|
this->well = gravity.well;
|
2013-12-19 14:30:16 +01:00
|
|
|
break;
|
|
|
|
case GravityType_Directed:
|
2014-01-09 11:36:55 +01:00
|
|
|
this->directed = gravity.directed;
|
2013-12-19 14:30:16 +01:00
|
|
|
break;
|
|
|
|
case GravityType_DirectedField:
|
2014-01-09 11:36:55 +01:00
|
|
|
this->directedField = gravity.directedField;
|
2013-12-19 14:30:16 +01:00
|
|
|
break;
|
2014-01-09 11:48:21 +01:00
|
|
|
default: break;
|
2013-12-19 14:30:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
inline Gravity & Gravity::operator = ( const Gravity &gravity )
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
2014-01-09 11:48:21 +01:00
|
|
|
this->gravityType = gravity.gravityType;
|
|
|
|
|
2014-01-09 11:36:55 +01:00
|
|
|
switch( gravity.gravityType )
|
2013-12-19 14:30:16 +01:00
|
|
|
{
|
|
|
|
case GravityType_Well:
|
2014-01-09 11:36:55 +01:00
|
|
|
this->well = gravity.well;
|
2013-12-19 14:30:16 +01:00
|
|
|
break;
|
|
|
|
case GravityType_Directed:
|
2014-01-09 11:36:55 +01:00
|
|
|
this->directed = gravity.directed;
|
2013-12-19 14:30:16 +01:00
|
|
|
break;
|
|
|
|
case GravityType_DirectedField:
|
2014-01-09 11:36:55 +01:00
|
|
|
this->directedField = gravity.directedField;
|
2013-12-19 14:30:16 +01:00
|
|
|
break;
|
2014-01-09 11:48:21 +01:00
|
|
|
default: break;
|
2013-12-19 14:30:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
2014-01-15 10:44:20 +01:00
|
|
|
|
|
|
|
inline bool Gravity::operator == ( const Gravity &gravity ) const
|
|
|
|
{
|
|
|
|
if( this->gravityType == gravity.gravityType )
|
|
|
|
{
|
|
|
|
switch( this->gravityType )
|
|
|
|
{
|
|
|
|
case GravityType_Well: return this->well == gravity.well;
|
|
|
|
case GravityType_Directed: return this->directed == gravity.directed;
|
|
|
|
case GravityType_DirectedField: return this->directedField == gravity.directedField;
|
|
|
|
default: return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool Gravity::operator != ( const Gravity &gravity ) const
|
|
|
|
{
|
|
|
|
if( this->gravityType == gravity.gravityType )
|
|
|
|
{
|
|
|
|
switch( this->gravityType )
|
|
|
|
{
|
|
|
|
case GravityType_Well: return this->well != gravity.well;
|
|
|
|
case GravityType_Directed: return this->directed != gravity.directed;
|
|
|
|
case GravityType_DirectedField: return this->directedField != gravity.directedField;
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-12-20 11:13:44 +01:00
|
|
|
}
|
2013-12-19 14:30:16 +01:00
|
|
|
}
|
|
|
|
}
|
2013-12-06 09:46:30 +01:00
|
|
|
|
|
|
|
#endif
|