Major StateStruct and API update

This commit is contained in:
Dander7BD 2013-12-18 14:16:13 +01:00
parent 96bf20e5ae
commit 5051a9e767
18 changed files with 724 additions and 490 deletions

Binary file not shown.

View File

@ -171,91 +171,91 @@ void API_Impl::DestroyObject( const ICustomBody* objRef )
}
}
void API_Impl::ApplyForceAt( const ICustomBody* objRef, const Float3 &worldPos, const Float3 &worldF )
{
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
if( tempRef != this->worldScene.invalid_ref )
{
//this->worldScene.GetCustomBody( tempRef )->Apply //!< @todo TODO: need function
this->worldScene.SetAsAltered( tempRef );
}
}
void API_Impl::SetMomentOfInertiaTensor_KeepVelocity( const ICustomBody* objRef, const Float4x4 &localI )
{ // deprecated
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
if( tempRef != this->worldScene.invalid_ref )
{
this->worldScene.GetCustomBody( tempRef )->SetMomentOfInertiaTensor_KeepVelocity( localI );
}
}
void API_Impl::SetMomentOfInertiaTensor_KeepMomentum( const ICustomBody* objRef, const Float4x4 &localI )
{ // deprecated
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
if( tempRef != this->worldScene.invalid_ref )
{
this->worldScene.GetCustomBody( tempRef )->SetMomentOfInertiaTensor_KeepMomentum( localI );
}
}
void API_Impl::SetMass_KeepVelocity( const ICustomBody* objRef, Float m )
{ // deprecated
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
if( tempRef != this->worldScene.invalid_ref )
{
this->worldScene.GetCustomBody( tempRef )->SetMass_KeepVelocity( m );
}
}
void API_Impl::SetMass_KeepMomentum( const ICustomBody* objRef, Float m )
{ // deprecated
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
if( tempRef != this->worldScene.invalid_ref )
{
this->worldScene.GetCustomBody( tempRef )->SetMass_KeepMomentum( m );
}
}
void API_Impl::SetCenter( const ICustomBody* objRef, const Float3 &worldPos )
{
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
if( tempRef != this->worldScene.invalid_ref )
{
//this->worldScene.GetCustomBody( tempRef )->Set //!< @todo TODO: need function
this->worldScene.EvaluatePosition( tempRef );
}
}
void API_Impl::SetRotation( const ICustomBody* objRef, const Float4x4 &rotation )
{
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
if( tempRef != this->worldScene.invalid_ref )
{
this->worldScene.GetCustomBody( tempRef )->SetRotation( rotation );
this->worldScene.EvaluatePosition( tempRef );
}
}
void API_Impl::SetOrientation( const ICustomBody* objRef, const Float4x4 &orientation )
{
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
if( tempRef != this->worldScene.invalid_ref )
{
this->worldScene.GetCustomBody( tempRef )->SetOrientation( orientation );
this->worldScene.EvaluatePosition( tempRef );
}
}
void API_Impl::SetSize( const ICustomBody* objRef, const Float3 &size )
{
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
if( tempRef != this->worldScene.invalid_ref )
{
this->worldScene.GetCustomBody( tempRef )->SetSize( size );
this->worldScene.EvaluatePosition( tempRef );
}
}
//void API_Impl::ApplyForceAt( const ICustomBody* objRef, const Float3 &worldPos, const Float3 &worldF )
//{
// unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
// if( tempRef != this->worldScene.invalid_ref )
// {
// //this->worldScene.GetCustomBody( tempRef )->Apply //!< @todo TODO: need function
// this->worldScene.SetAsAltered( tempRef );
// }
//}
//
//void API_Impl::SetMomentOfInertiaTensor_KeepVelocity( const ICustomBody* objRef, const Float4x4 &localI )
//{ // deprecated
// unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
// if( tempRef != this->worldScene.invalid_ref )
// {
// this->worldScene.GetCustomBody( tempRef )->SetMomentOfInertiaTensor_KeepVelocity( localI );
// }
//}
//
//void API_Impl::SetMomentOfInertiaTensor_KeepMomentum( const ICustomBody* objRef, const Float4x4 &localI )
//{ // deprecated
// unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
// if( tempRef != this->worldScene.invalid_ref )
// {
// this->worldScene.GetCustomBody( tempRef )->SetMomentOfInertiaTensor_KeepMomentum( localI );
// }
//}
//
//void API_Impl::SetMass_KeepVelocity( const ICustomBody* objRef, Float m )
//{ // deprecated
// unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
// if( tempRef != this->worldScene.invalid_ref )
// {
// this->worldScene.GetCustomBody( tempRef )->SetMass_KeepVelocity( m );
// }
//}
//
//void API_Impl::SetMass_KeepMomentum( const ICustomBody* objRef, Float m )
//{ // deprecated
// unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
// if( tempRef != this->worldScene.invalid_ref )
// {
// this->worldScene.GetCustomBody( tempRef )->SetMass_KeepMomentum( m );
// }
//}
//
//void API_Impl::SetCenter( const ICustomBody* objRef, const Float3 &worldPos )
//{
// unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
// if( tempRef != this->worldScene.invalid_ref )
// {
// //this->worldScene.GetCustomBody( tempRef )->Set //!< @todo TODO: need function
// this->worldScene.EvaluatePosition( tempRef );
// }
//}
//
//void API_Impl::SetRotation( const ICustomBody* objRef, const Float4x4 &rotation )
//{
// unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
// if( tempRef != this->worldScene.invalid_ref )
// {
// this->worldScene.GetCustomBody( tempRef )->SetRotation( rotation );
// this->worldScene.EvaluatePosition( tempRef );
// }
//}
//
//void API_Impl::SetOrientation( const ICustomBody* objRef, const Float4x4 &orientation )
//{
// unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
// if( tempRef != this->worldScene.invalid_ref )
// {
// this->worldScene.GetCustomBody( tempRef )->SetOrientation( orientation );
// this->worldScene.EvaluatePosition( tempRef );
// }
//}
//
//void API_Impl::SetSize( const ICustomBody* objRef, const Float3 &size )
//{
// unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
// if( tempRef != this->worldScene.invalid_ref )
// {
// this->worldScene.GetCustomBody( tempRef )->SetSize( size );
// this->worldScene.EvaluatePosition( tempRef );
// }
//}
UniquePointer<ICustomBody> API_Impl::CreateRigidBody( const API::SimpleBodyDescription &desc ) const
{

View File

@ -30,16 +30,16 @@ namespace Oyster
::Utility::DynamicMemory::UniquePointer<ICustomBody> ExtractObject( const ICustomBody* objRef );
void DestroyObject( const ICustomBody* objRef );
void ApplyForceAt( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &worldF );
//void ApplyForceAt( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &worldF );
void SetMomentOfInertiaTensor_KeepVelocity( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &localI );
void SetMomentOfInertiaTensor_KeepMomentum( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &localI );
void SetMass_KeepVelocity( const ICustomBody* objRef, ::Oyster::Math::Float m );
void SetMass_KeepMomentum( const ICustomBody* objRef, ::Oyster::Math::Float m );
void SetCenter( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos );
void SetRotation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &rotation );
void SetOrientation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &orientation );
void SetSize( const ICustomBody* objRef, const ::Oyster::Math::Float3 &size );
//void SetMomentOfInertiaTensor_KeepVelocity( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &localI );
//void SetMomentOfInertiaTensor_KeepMomentum( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &localI );
//void SetMass_KeepVelocity( const ICustomBody* objRef, ::Oyster::Math::Float m );
//void SetMass_KeepMomentum( const ICustomBody* objRef, ::Oyster::Math::Float m );
//void SetCenter( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos );
//void SetRotation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &rotation );
//void SetOrientation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &orientation );
//void SetSize( const ICustomBody* objRef, const ::Oyster::Math::Float3 &size );
::Utility::DynamicMemory::UniquePointer<ICustomBody> CreateRigidBody( const SimpleBodyDescription &desc ) const;
::Utility::DynamicMemory::UniquePointer<ICustomBody> CreateRigidBody( const SphericalBodyDescription &desc ) const;

View File

@ -18,7 +18,7 @@ SimpleRigidBody::SimpleRigidBody()
SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc )
{
this->rigid = RigidBody( Box( desc.rotation, desc.centerPosition, desc.size ),
this->rigid = RigidBody( Box( desc.rotation, desc.centerPosition.xyz, desc.size.xyz ),
desc.mass,
desc.inertiaTensor );
this->gravityNormal = Float3::null;
@ -44,12 +44,18 @@ UniquePointer<ICustomBody> SimpleRigidBody::Clone() const
SimpleRigidBody::State SimpleRigidBody::GetState() const
{
return State( this->rigid.box.boundingOffset.xyz, this->rigid.box.center.xyz, AngularAxis(this->rigid.box.rotation).xyz, this->rigid.linearMomentum, this->rigid.angularMomentum );
return State( this->rigid.GetMass(), this->rigid.restitutionCoeff, this->rigid.frictionCoeff,
this->rigid.GetMomentOfInertia(), this->rigid.box.boundingOffset,
this->rigid.box.center, AngularAxis(this->rigid.box.rotation),
Float4(this->rigid.linearMomentum, 0.0f), Float4(this->rigid.angularMomentum, 0.0f) );
}
SimpleRigidBody::State & SimpleRigidBody::GetState( SimpleRigidBody::State &targetMem ) const
{
return targetMem = State( this->rigid.box.boundingOffset.xyz, this->rigid.box.center.xyz, AngularAxis(this->rigid.box.rotation).xyz, this->rigid.linearMomentum, this->rigid.angularMomentum );
return targetMem = State( this->rigid.GetMass(), this->rigid.restitutionCoeff, this->rigid.frictionCoeff,
this->rigid.GetMomentOfInertia(), this->rigid.box.boundingOffset,
this->rigid.box.center, AngularAxis(this->rigid.box.rotation),
Float4(this->rigid.linearMomentum, 0.0f), Float4(this->rigid.angularMomentum, 0.0f) );
}
void SimpleRigidBody::SetState( const SimpleRigidBody::State &state )
@ -100,25 +106,25 @@ Float3 & SimpleRigidBody::GetGravityNormal( Float3 &targetMem ) const
return targetMem = this->gravityNormal;
}
Float3 & SimpleRigidBody::GetCenter( Float3 &targetMem ) const
{
return targetMem = this->rigid.box.center;
}
Float4x4 & SimpleRigidBody::GetRotation( Float4x4 &targetMem ) const
{
return targetMem = this->rigid.box.rotation;
}
Float4x4 & SimpleRigidBody::GetOrientation( Float4x4 &targetMem ) const
{
return targetMem = this->rigid.GetOrientation();
}
Float4x4 & SimpleRigidBody::GetView( Float4x4 &targetMem ) const
{
return targetMem = this->rigid.GetView();
}
//Float3 & SimpleRigidBody::GetCenter( Float3 &targetMem ) const
//{
// return targetMem = this->rigid.box.center;
//}
//
//Float4x4 & SimpleRigidBody::GetRotation( Float4x4 &targetMem ) const
//{
// return targetMem = this->rigid.box.rotation;
//}
//
//Float4x4 & SimpleRigidBody::GetOrientation( Float4x4 &targetMem ) const
//{
// return targetMem = this->rigid.GetOrientation();
//}
//
//Float4x4 & SimpleRigidBody::GetView( Float4x4 &targetMem ) const
//{
// return targetMem = this->rigid.GetView();
//}
Float3 SimpleRigidBody::GetRigidLinearVelocity() const
{
@ -158,47 +164,47 @@ void SimpleRigidBody::SetGravityNormal( const Float3 &normalizedVector )
this->gravityNormal = normalizedVector;
}
void SimpleRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI )
{
this->rigid.SetMomentOfInertia_KeepVelocity( localI );
}
void SimpleRigidBody::SetMomentOfInertiaTensor_KeepMomentum( const Float4x4 &localI )
{
this->rigid.SetMomentOfInertia_KeepMomentum( localI );
}
void SimpleRigidBody::SetMass_KeepVelocity( Float m )
{
this->rigid.SetMass_KeepVelocity( m );
}
void SimpleRigidBody::SetMass_KeepMomentum( Float m )
{
this->rigid.SetMass_KeepMomentum( m );
}
void SimpleRigidBody::SetCenter( const Float3 &worldPos )
{
this->rigid.SetCenter( worldPos );
}
void SimpleRigidBody::SetRotation( const Float4x4 &rotation )
{
this->rigid.SetRotation( rotation );
}
void SimpleRigidBody::SetOrientation( const Float4x4 &orientation )
{
this->rigid.SetOrientation( orientation );
}
void SimpleRigidBody::SetSize( const Float3 &size )
{
this->rigid.SetSize( size );
}
void SimpleRigidBody::SetMomentum( const Float3 &worldG )
{
this->rigid.SetLinearMomentum( worldG );
}
//void SimpleRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI )
//{
// this->rigid.SetMomentOfInertia_KeepVelocity( localI );
//}
//
//void SimpleRigidBody::SetMomentOfInertiaTensor_KeepMomentum( const Float4x4 &localI )
//{
// this->rigid.SetMomentOfInertia_KeepMomentum( localI );
//}
//
//void SimpleRigidBody::SetMass_KeepVelocity( Float m )
//{
// this->rigid.SetMass_KeepVelocity( m );
//}
//
//void SimpleRigidBody::SetMass_KeepMomentum( Float m )
//{
// this->rigid.SetMass_KeepMomentum( m );
//}
//
//void SimpleRigidBody::SetCenter( const Float3 &worldPos )
//{
// this->rigid.SetCenter( worldPos );
//}
//
//void SimpleRigidBody::SetRotation( const Float4x4 &rotation )
//{
// this->rigid.SetRotation( rotation );
//}
//
//void SimpleRigidBody::SetOrientation( const Float4x4 &orientation )
//{
// this->rigid.SetOrientation( orientation );
//}
//
//void SimpleRigidBody::SetSize( const Float3 &size )
//{
// this->rigid.SetSize( size );
//}
//
//void SimpleRigidBody::SetMomentum( const Float3 &worldG )
//{
// this->rigid.SetLinearMomentum( worldG );
//}

View File

@ -29,25 +29,25 @@ namespace Oyster { namespace Physics
::Oyster::Collision3D::Sphere & GetBoundingSphere( ::Oyster::Collision3D::Sphere &targetMem = ::Oyster::Collision3D::Sphere() ) const;
::Oyster::Math::Float4 & GetNormalAt( const ::Oyster::Math::Float4 &worldPos, ::Oyster::Math::Float4 &targetMem = ::Oyster::Math::Float4() ) const;
::Oyster::Math::Float3 & GetGravityNormal( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
::Oyster::Math::Float3 & GetCenter( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
::Oyster::Math::Float4x4 & GetRotation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
::Oyster::Math::Float4x4 & GetOrientation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
::Oyster::Math::Float4x4 & GetView( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
//::Oyster::Math::Float3 & GetCenter( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
//::Oyster::Math::Float4x4 & GetRotation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
//::Oyster::Math::Float4x4 & GetOrientation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
//::Oyster::Math::Float4x4 & GetView( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
UpdateState Update( ::Oyster::Math::Float timeStepLength );
void SetSubscription( EventAction_Collision functionPointer );
void SetGravity( bool ignore);
void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector );
void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI );
void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI );
void SetMass_KeepVelocity( ::Oyster::Math::Float m );
void SetMass_KeepMomentum( ::Oyster::Math::Float m );
void SetCenter( const ::Oyster::Math::Float3 &worldPos );
void SetRotation( const ::Oyster::Math::Float4x4 &rotation );
void SetOrientation( const ::Oyster::Math::Float4x4 &orientation );
void SetSize( const ::Oyster::Math::Float3 &size );
void SetMomentum( const ::Oyster::Math::Float3 &worldG );
//void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI );
//void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI );
//void SetMass_KeepVelocity( ::Oyster::Math::Float m );
//void SetMass_KeepMomentum( ::Oyster::Math::Float m );
//void SetCenter( const ::Oyster::Math::Float3 &worldPos );
//void SetRotation( const ::Oyster::Math::Float4x4 &rotation );
//void SetOrientation( const ::Oyster::Math::Float4x4 &orientation );
//void SetSize( const ::Oyster::Math::Float3 &size );
//void SetMomentum( const ::Oyster::Math::Float3 &worldG );
private:
::Oyster::Physics3D::RigidBody rigid;

View File

@ -19,7 +19,7 @@ SphericalRigidBody::SphericalRigidBody()
SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &desc )
{
this->rigid = RigidBody( Box( desc.rotation, desc.centerPosition, Float3(2.0f * desc.radius) ),
this->rigid = RigidBody( Box( desc.rotation, desc.centerPosition.xyz, Float3(2.0f * desc.radius) ),
desc.mass,
Formula::MomentOfInertia::CreateSphereMatrix( desc.mass, desc.radius ) );
this->gravityNormal = Float3::null;
@ -46,12 +46,18 @@ UniquePointer<ICustomBody> SphericalRigidBody::Clone() const
SphericalRigidBody::State SphericalRigidBody::GetState() const
{
return State( this->rigid.box.boundingOffset.xyz, this->rigid.box.center.xyz, AngularAxis(this->rigid.box.rotation).xyz, this->rigid.linearMomentum, this->rigid.angularMomentum );
return State( this->rigid.GetMass(), this->rigid.restitutionCoeff, this->rigid.frictionCoeff,
this->rigid.GetMomentOfInertia(), this->rigid.box.boundingOffset,
this->rigid.box.center, AngularAxis(this->rigid.box.rotation),
Float4(this->rigid.linearMomentum, 0.0f), Float4(this->rigid.angularMomentum, 0.0f) );
}
SphericalRigidBody::State & SphericalRigidBody::GetState( SphericalRigidBody::State &targetMem ) const
{
return targetMem = State( this->rigid.box.boundingOffset.xyz, this->rigid.box.center.xyz, AngularAxis(this->rigid.box.rotation).xyz, this->rigid.linearMomentum, this->rigid.angularMomentum );
return targetMem = State( this->rigid.GetMass(), this->rigid.restitutionCoeff, this->rigid.frictionCoeff,
this->rigid.GetMomentOfInertia(), this->rigid.box.boundingOffset,
this->rigid.box.center, AngularAxis(this->rigid.box.rotation),
Float4(this->rigid.linearMomentum, 0.0f), Float4(this->rigid.angularMomentum, 0.0f) );
}
void SphericalRigidBody::SetState( const SphericalRigidBody::State &state )
@ -93,7 +99,6 @@ Sphere & SphericalRigidBody::GetBoundingSphere( Sphere &targetMem ) const
Float4 & SphericalRigidBody::GetNormalAt( const Float4 &worldPos, Float4 &targetMem ) const
{
//! @todo TODO: better implementation needed
return targetMem = (worldPos - this->rigid.box.center).GetNormalized();
}
@ -102,25 +107,25 @@ Float3 & SphericalRigidBody::GetGravityNormal( Float3 &targetMem ) const
return targetMem = this->gravityNormal;
}
Float3 & SphericalRigidBody::GetCenter( Float3 &targetMem ) const
{
return targetMem = this->rigid.box.center;
}
Float4x4 & SphericalRigidBody::GetRotation( Float4x4 &targetMem ) const
{
return targetMem = this->rigid.box.rotation;
}
Float4x4 & SphericalRigidBody::GetOrientation( Float4x4 &targetMem ) const
{
return targetMem = this->rigid.GetOrientation();
}
Float4x4 & SphericalRigidBody::GetView( Float4x4 &targetMem ) const
{
return targetMem = this->rigid.GetView();
}
//Float3 & SphericalRigidBody::GetCenter( Float3 &targetMem ) const
//{
// return targetMem = this->rigid.box.center;
//}
//
//Float4x4 & SphericalRigidBody::GetRotation( Float4x4 &targetMem ) const
//{
// return targetMem = this->rigid.box.rotation;
//}
//
//Float4x4 & SphericalRigidBody::GetOrientation( Float4x4 &targetMem ) const
//{
// return targetMem = this->rigid.GetOrientation();
//}
//
//Float4x4 & SphericalRigidBody::GetView( Float4x4 &targetMem ) const
//{
// return targetMem = this->rigid.GetView();
//}
Float3 SphericalRigidBody::GetRigidLinearVelocity() const
{
@ -160,50 +165,50 @@ void SphericalRigidBody::SetGravityNormal( const Float3 &normalizedVector )
this->gravityNormal = normalizedVector;
}
void SphericalRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI )
{
this->rigid.SetMomentOfInertia_KeepVelocity( localI );
}
void SphericalRigidBody::SetMomentOfInertiaTensor_KeepMomentum( const Float4x4 &localI )
{
this->rigid.SetMomentOfInertia_KeepMomentum( localI );
}
void SphericalRigidBody::SetMass_KeepVelocity( Float m )
{
this->rigid.SetMass_KeepVelocity( m );
}
void SphericalRigidBody::SetMass_KeepMomentum( Float m )
{
this->rigid.SetMass_KeepMomentum( m );
}
void SphericalRigidBody::SetCenter( const Float3 &worldPos )
{
this->rigid.SetCenter( worldPos );
this->body.center = worldPos;
}
void SphericalRigidBody::SetRotation( const Float4x4 &rotation )
{
this->rigid.SetRotation( rotation );
}
void SphericalRigidBody::SetOrientation( const Float4x4 &orientation )
{
this->rigid.SetOrientation( orientation );
this->body.center = orientation.v[3].xyz;
}
void SphericalRigidBody::SetSize( const Float3 &size )
{
this->rigid.SetSize( size );
this->body.radius = 0.5f * Min( Min( size.x, size.y ), size.z ); // inline Min( FloatN )?
}
void SphericalRigidBody::SetMomentum( const Float3 &worldG )
{
this->rigid.SetLinearMomentum( worldG );
}
//void SphericalRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI )
//{
// this->rigid.SetMomentOfInertia_KeepVelocity( localI );
//}
//
//void SphericalRigidBody::SetMomentOfInertiaTensor_KeepMomentum( const Float4x4 &localI )
//{
// this->rigid.SetMomentOfInertia_KeepMomentum( localI );
//}
//
//void SphericalRigidBody::SetMass_KeepVelocity( Float m )
//{
// this->rigid.SetMass_KeepVelocity( m );
//}
//
//void SphericalRigidBody::SetMass_KeepMomentum( Float m )
//{
// this->rigid.SetMass_KeepMomentum( m );
//}
//
//void SphericalRigidBody::SetCenter( const Float3 &worldPos )
//{
// this->rigid.SetCenter( worldPos );
// this->body.center = worldPos;
//}
//
//void SphericalRigidBody::SetRotation( const Float4x4 &rotation )
//{
// this->rigid.SetRotation( rotation );
//}
//
//void SphericalRigidBody::SetOrientation( const Float4x4 &orientation )
//{
// this->rigid.SetOrientation( orientation );
// this->body.center = orientation.v[3].xyz;
//}
//
//void SphericalRigidBody::SetSize( const Float3 &size )
//{
// this->rigid.SetSize( size );
// this->body.radius = 0.5f * Min( Min( size.x, size.y ), size.z ); // inline Min( FloatN )?
//}
//
//void SphericalRigidBody::SetMomentum( const Float3 &worldG )
//{
// this->rigid.SetLinearMomentum( worldG );
//}

View File

@ -30,25 +30,25 @@ namespace Oyster { namespace Physics
::Oyster::Collision3D::Sphere & GetBoundingSphere( ::Oyster::Collision3D::Sphere &targetMem = ::Oyster::Collision3D::Sphere() ) const;
::Oyster::Math::Float4 & GetNormalAt( const ::Oyster::Math::Float4 &worldPos, ::Oyster::Math::Float4 &targetMem = ::Oyster::Math::Float4() ) const;
::Oyster::Math::Float3 & GetGravityNormal( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
::Oyster::Math::Float3 & GetCenter( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
::Oyster::Math::Float4x4 & GetRotation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
::Oyster::Math::Float4x4 & GetOrientation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
::Oyster::Math::Float4x4 & GetView( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
//::Oyster::Math::Float3 & GetCenter( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
//::Oyster::Math::Float4x4 & GetRotation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
//::Oyster::Math::Float4x4 & GetOrientation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
//::Oyster::Math::Float4x4 & GetView( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
UpdateState Update( ::Oyster::Math::Float timeStepLength );
void SetSubscription( EventAction_Collision functionPointer );
void SetGravity( bool ignore);
void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector );
void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI );
void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI );
void SetMass_KeepVelocity( ::Oyster::Math::Float m );
void SetMass_KeepMomentum( ::Oyster::Math::Float m );
void SetCenter( const ::Oyster::Math::Float3 &worldPos );
void SetRotation( const ::Oyster::Math::Float4x4 &rotation );
void SetOrientation( const ::Oyster::Math::Float4x4 &orientation );
void SetSize( const ::Oyster::Math::Float3 &size );
void SetMomentum( const ::Oyster::Math::Float3 &worldG );
//void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI );
//void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI );
//void SetMass_KeepVelocity( ::Oyster::Math::Float m );
//void SetMass_KeepMomentum( ::Oyster::Math::Float m );
//void SetCenter( const ::Oyster::Math::Float3 &worldPos );
//void SetRotation( const ::Oyster::Math::Float4x4 &rotation );
//void SetOrientation( const ::Oyster::Math::Float4x4 &orientation );
//void SetSize( const ::Oyster::Math::Float3 &size );
//void SetMomentum( const ::Oyster::Math::Float3 &worldG );
private:
::Oyster::Physics3D::RigidBody rigid;

View File

@ -124,73 +124,73 @@ namespace Oyster
********************************************************/
virtual void DestroyObject( const ICustomBody* objRef ) = 0;
/********************************************************
* Apply force on an object.
* @param objRef: A pointer to the ICustomBody representing a physical object.
* @param worldPos: Relative to the world origo. (Not relative to object) [m]
* @param worldF: Vector with the direction and magnitude of the force. [N]
********************************************************/
virtual void ApplyForceAt( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &worldF ) = 0;
///********************************************************
// * Apply force on an object.
// * @param objRef: A pointer to the ICustomBody representing a physical object.
// * @param worldPos: Relative to the world origo. (Not relative to object) [m]
// * @param worldF: Vector with the direction and magnitude of the force. [N]
// ********************************************************/
//virtual void ApplyForceAt( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &worldF ) = 0;
/********************************************************
* Sets the MomentOfInertia tensor matrix of an object without changing it's angular velocity.
* Noticeable effect: The angular momentum will change. Changing the amount of kinetic energy.
* @param objRef: A pointer to the ICustomBody representing a physical object.
* @param localI: The tensor matrix relative to the axises of the object. @see MomentOfInertia namespace.
********************************************************/
virtual void SetMomentOfInertiaTensor_KeepVelocity( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &localI ) = 0;
/********************************************************
* Sets the MomentOfInertia tensor matrix of an object without changing it's angular momentum.
* Noticeable effect: The angular velocity will change. Can be used to create slow effects.
* @param objRef: A pointer to the ICustomBody representing a physical object.
* @param localI: The tensor matrix relative to the axises of the object. @see MomentOfInertia namespace.
********************************************************/
virtual void SetMomentOfInertiaTensor_KeepMomentum( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &localI ) = 0;
/********************************************************
* Sets the mass of an object without changing it's linear velocity.
* Noticeable effect: The linear momentum will change. Changing the amount of kinetic energy.
* @param objRef: A pointer to the ICustomBody representing a physical object.
* @param m: [kg]
********************************************************/
virtual void SetMass_KeepVelocity( const ICustomBody* objRef, ::Oyster::Math::Float m ) = 0;
/********************************************************
* Sets the mass of an object without changing it's linear velocity.
* Noticeable effect: The linear velocity will change. Can be used to create slow effects.
* @param objRef: A pointer to the ICustomBody representing a physical object.
* @param m: [kg]
********************************************************/
virtual void SetMass_KeepMomentum( const ICustomBody* objRef, ::Oyster::Math::Float m ) = 0;
/********************************************************
* Instantly moves an object.
* @param objRef: A pointer to the ICustomBody representing a physical object.
* @param worldPos: Relative to the world origo. (Not relative to object) [m]
********************************************************/
virtual void SetCenter( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos ) = 0;
/********************************************************
* Instantly redirects object.
* @param objRef: A pointer to the ICustomBody representing a physical object.
* @param rotation: New rotation.
********************************************************/
virtual void SetRotation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &rotation ) = 0;
/********************************************************
* Instantly moves and redirects object.
* @param objRef: A pointer to the ICustomBody representing a physical object.
* @param orientation: New orientation.
********************************************************/
virtual void SetOrientation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &orientation ) = 0;
/********************************************************
* Resizes the boundingBox.
* @param objRef: A pointer to the ICustomBody representing a physical object.
* @param size: New size of this [m]
********************************************************/
virtual void SetSize( const ICustomBody* objRef, const ::Oyster::Math::Float3 &size ) = 0;
///********************************************************
// * Sets the MomentOfInertia tensor matrix of an object without changing it's angular velocity.
// * Noticeable effect: The angular momentum will change. Changing the amount of kinetic energy.
// * @param objRef: A pointer to the ICustomBody representing a physical object.
// * @param localI: The tensor matrix relative to the axises of the object. @see MomentOfInertia namespace.
// ********************************************************/
//virtual void SetMomentOfInertiaTensor_KeepVelocity( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &localI ) = 0;
//
///********************************************************
// * Sets the MomentOfInertia tensor matrix of an object without changing it's angular momentum.
// * Noticeable effect: The angular velocity will change. Can be used to create slow effects.
// * @param objRef: A pointer to the ICustomBody representing a physical object.
// * @param localI: The tensor matrix relative to the axises of the object. @see MomentOfInertia namespace.
// ********************************************************/
//virtual void SetMomentOfInertiaTensor_KeepMomentum( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &localI ) = 0;
//
///********************************************************
// * Sets the mass of an object without changing it's linear velocity.
// * Noticeable effect: The linear momentum will change. Changing the amount of kinetic energy.
// * @param objRef: A pointer to the ICustomBody representing a physical object.
// * @param m: [kg]
// ********************************************************/
//virtual void SetMass_KeepVelocity( const ICustomBody* objRef, ::Oyster::Math::Float m ) = 0;
//
///********************************************************
// * Sets the mass of an object without changing it's linear velocity.
// * Noticeable effect: The linear velocity will change. Can be used to create slow effects.
// * @param objRef: A pointer to the ICustomBody representing a physical object.
// * @param m: [kg]
// ********************************************************/
//virtual void SetMass_KeepMomentum( const ICustomBody* objRef, ::Oyster::Math::Float m ) = 0;
//
///********************************************************
// * Instantly moves an object.
// * @param objRef: A pointer to the ICustomBody representing a physical object.
// * @param worldPos: Relative to the world origo. (Not relative to object) [m]
// ********************************************************/
//virtual void SetCenter( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos ) = 0;
//
///********************************************************
// * Instantly redirects object.
// * @param objRef: A pointer to the ICustomBody representing a physical object.
// * @param rotation: New rotation.
// ********************************************************/
//virtual void SetRotation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &rotation ) = 0;
//
///********************************************************
// * Instantly moves and redirects object.
// * @param objRef: A pointer to the ICustomBody representing a physical object.
// * @param orientation: New orientation.
// ********************************************************/
//virtual void SetOrientation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &orientation ) = 0;
//
///********************************************************
// * Resizes the boundingBox.
// * @param objRef: A pointer to the ICustomBody representing a physical object.
// * @param size: New size of this [m]
// ********************************************************/
//virtual void SetSize( const ICustomBody* objRef, const ::Oyster::Math::Float3 &size ) = 0;
/********************************************************
* Creates a new dynamically allocated object that can be used as a component for more complex ICustomBodies.
@ -307,30 +307,30 @@ namespace Oyster
********************************************************/
virtual ::Oyster::Math::Float3 & GetGravityNormal( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const = 0;
/********************************************************
* The world position of this center of gravity.
* @param targetMem: Provided memory that written into and then returned.
* @return a position in worldSpace.
********************************************************/
virtual ::Oyster::Math::Float3 & GetCenter( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const = 0;
/********************************************************
* @param targetMem: Provided memory that written into and then returned.
* @return a copy of this's rotation matrix.
********************************************************/
virtual ::Oyster::Math::Float4x4 & GetRotation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const = 0;
/********************************************************
* @param targetMem: Provided memory that written into and then returned.
* @return a copy of this's orientation matrix.
********************************************************/
virtual ::Oyster::Math::Float4x4 & GetOrientation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const = 0;
/********************************************************
* @param targetMem: Provided memory that written into and then returned.
* @return a copy of this's view matrix.
********************************************************/
virtual ::Oyster::Math::Float4x4 & GetView( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const = 0;
///********************************************************
// * The world position of this center of gravity.
// * @param targetMem: Provided memory that written into and then returned.
// * @return a position in worldSpace.
// ********************************************************/
//virtual ::Oyster::Math::Float3 & GetCenter( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const = 0;
//
///********************************************************
// * @param targetMem: Provided memory that written into and then returned.
// * @return a copy of this's rotation matrix.
// ********************************************************/
//virtual ::Oyster::Math::Float4x4 & GetRotation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const = 0;
//
///********************************************************
// * @param targetMem: Provided memory that written into and then returned.
// * @return a copy of this's orientation matrix.
// ********************************************************/
//virtual ::Oyster::Math::Float4x4 & GetOrientation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const = 0;
//
///********************************************************
// * @param targetMem: Provided memory that written into and then returned.
// * @return a copy of this's view matrix.
// ********************************************************/
//virtual ::Oyster::Math::Float4x4 & GetView( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const = 0;
/********************************************************
* To not be called if is in Engine
@ -356,59 +356,59 @@ namespace Oyster
********************************************************/
virtual void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector ) = 0;
/********************************************************
* To not be called if is in Engine
* Use API::SetMomentOfInertiaTensor_KeepVelocity(...) instead
********************************************************/
virtual void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI ) = 0;
/********************************************************
* To not be called if is in Engine
* Use API::SetMomentOfInertiaTensor_KeepMomentum(...)
********************************************************/
virtual void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI ) = 0;
/********************************************************
* To not be called if is in Engine
* Use API::SetMass_KeepVelocity(...)
********************************************************/
virtual void SetMass_KeepVelocity( ::Oyster::Math::Float m ) = 0;
/********************************************************
* To not be called if is in Engine
* Use API::SetMass_KeepMomentum(...)
********************************************************/
virtual void SetMass_KeepMomentum( ::Oyster::Math::Float m ) = 0;
/********************************************************
* To not be called if is in Engine
* Use API::SetCenter(...)
********************************************************/
virtual void SetCenter( const ::Oyster::Math::Float3 &worldPos ) = 0;
/********************************************************
* To not be called if is in Engine
* Use API::SetRotation(...)
********************************************************/
virtual void SetRotation( const ::Oyster::Math::Float4x4 &rotation ) = 0;
/********************************************************
* To not be called if is in Engine
* Use API::SetOrientation(...)
********************************************************/
virtual void SetOrientation( const ::Oyster::Math::Float4x4 &orientation ) = 0;
///********************************************************
// * To not be called if is in Engine
// * Use API::SetMomentOfInertiaTensor_KeepVelocity(...) instead
// ********************************************************/
//virtual void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI ) = 0;
//
///********************************************************
// * To not be called if is in Engine
// * Use API::SetMomentOfInertiaTensor_KeepMomentum(...)
// ********************************************************/
//virtual void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI ) = 0;
//
///********************************************************
// * To not be called if is in Engine
// * Use API::SetMass_KeepVelocity(...)
// ********************************************************/
//virtual void SetMass_KeepVelocity( ::Oyster::Math::Float m ) = 0;
//
///********************************************************
// * To not be called if is in Engine
// * Use API::SetMass_KeepMomentum(...)
// ********************************************************/
//virtual void SetMass_KeepMomentum( ::Oyster::Math::Float m ) = 0;
//
///********************************************************
// * To not be called if is in Engine
// * Use API::SetCenter(...)
// ********************************************************/
//virtual void SetCenter( const ::Oyster::Math::Float3 &worldPos ) = 0;
//
///********************************************************
// * To not be called if is in Engine
// * Use API::SetRotation(...)
// ********************************************************/
//virtual void SetRotation( const ::Oyster::Math::Float4x4 &rotation ) = 0;
//
///********************************************************
// * To not be called if is in Engine
// * Use API::SetOrientation(...)
// ********************************************************/
//virtual void SetOrientation( const ::Oyster::Math::Float4x4 &orientation ) = 0;
/********************************************************
* To not be called if is in Engine
* Use API::SetSize(...)
********************************************************/
virtual void SetSize( const ::Oyster::Math::Float3 &size ) = 0;
///********************************************************
// * To not be called if is in Engine
// * Use API::SetSize(...)
// ********************************************************/
//virtual void SetSize( const ::Oyster::Math::Float3 &size ) = 0;
/********************************************************
* To not be called if is in Engine
* Use API::?? @todo TODO:
********************************************************/
virtual void SetMomentum( const ::Oyster::Math::Float3 &worldG ) = 0;
///********************************************************
// * To not be called if is in Engine
// * Use API::?? @todo TODO:
// ********************************************************/
//virtual void SetMomentum( const ::Oyster::Math::Float3 &worldG ) = 0;
};
}
}

View File

@ -38,9 +38,10 @@ namespace Oyster { namespace Physics { namespace Formula
{
inline ::Oyster::Math::Float Impulse( ::Oyster::Math::Float e, ::Oyster::Math::Float mA, ::Oyster::Math::Float gA, ::Oyster::Math::Float mB, ::Oyster::Math::Float gB )
{
return (e+1) * (mB*gA - mA*gB) / (mA + mB);
return (e + 1) * (mB*gA - mA*gB) / (mA + mB);
}
}
} } }
#endif

View File

@ -2,6 +2,7 @@
#define PHYSICS_FORMULA_H
#include "OysterMath.h"
#include "OysterPhysics3D.h"
namespace Oyster { namespace Physics { namespace Formula
{

View File

@ -10,8 +10,8 @@ namespace Oyster { namespace Physics
inline SimpleBodyDescription::SimpleBodyDescription()
{
this->rotation = ::Oyster::Math::Float4x4::identity;
this->centerPosition = ::Oyster::Math::Float3::null;
this->size = ::Oyster::Math::Float3( 1.0f );
this->centerPosition = ::Oyster::Math::Float4::null;
this->size = ::Oyster::Math::Float4( 1.0f );
this->mass = 12.0f;
this->inertiaTensor = ::Oyster::Math::Float4x4::identity;
this->subscription = NULL;
@ -21,36 +21,66 @@ namespace Oyster { namespace Physics
inline SphericalBodyDescription::SphericalBodyDescription()
{
this->rotation = ::Oyster::Math::Float4x4::identity;
this->centerPosition = ::Oyster::Math::Float3::null;
this->centerPosition = ::Oyster::Math::Float4::null;
this->radius = 0.5f;
this->mass = 10.0f;
this->subscription = NULL;
this->ignoreGravity = false;
}
inline CustomBodyState::CustomBodyState( const ::Oyster::Math::Float3 &reach, const ::Oyster::Math::Float3 &centerPos, const ::Oyster::Math::Float3 &rotation, const ::Oyster::Math::Float3 &linearMomentum, const ::Oyster::Math::Float3 &angularMomentum )
inline CustomBodyState::CustomBodyState( ::Oyster::Math::Float mass, ::Oyster::Math::Float restitutionCoeff, ::Oyster::Math::Float frictionCoeff, const ::Oyster::Math::Float4x4 &inertiaTensor, const ::Oyster::Math::Float4 &reach, const ::Oyster::Math::Float4 &centerPos, const ::Oyster::Math::Float4 &rotation, const ::Oyster::Math::Float4 &linearMomentum, const ::Oyster::Math::Float4 &angularMomentum )
{
this->reach = ::Oyster::Math::Float4( reach, 0.0f );
this->centerPos = ::Oyster::Math::Float4( centerPos, 1.0f );
this->angularAxis = ::Oyster::Math::Float4( rotation, 0.0f );
this->linearMomentum = ::Oyster::Math::Float4( linearMomentum, 0.0f );
this->angularMomentum = ::Oyster::Math::Float4( angularMomentum, 0.0f );
this->mass = mass;
this->restitutionCoeff = restitutionCoeff;
this->frictionCoeff = frictionCoeff;
this->inertiaTensor = inertiaTensor;
this->reach = ::Oyster::Math::Float4( reach.xyz, 0.0f );
this->centerPos = ::Oyster::Math::Float4( centerPos.xyz, 1.0f );
this->angularAxis = ::Oyster::Math::Float4( rotation.xyz, 0.0f );
this->linearMomentum = ::Oyster::Math::Float4( linearMomentum.xyz, 0.0f );
this->angularMomentum = ::Oyster::Math::Float4( angularMomentum.xyz, 0.0f );
this->linearImpulse = this->angularImpulse = ::Oyster::Math::Float4::null;
this->isSpatiallyAltered = this->isDisturbed = false;
}
inline CustomBodyState & CustomBodyState::operator = ( const CustomBodyState &state )
{
this->mass = state.mass;
this->restitutionCoeff = state.restitutionCoeff;
this->frictionCoeff = state.frictionCoeff;
this->inertiaTensor = state.inertiaTensor;
this->reach = state.reach;
this->centerPos = state.centerPos;
this->angularAxis = state.angularAxis;
this->linearMomentum = state.linearMomentum;
this->angularMomentum = state.angularMomentum;
this->linearImpulse = state.linearImpulse;
this->angularImpulse = state.angularImpulse;
this->isSpatiallyAltered = state.isSpatiallyAltered;
this->isDisturbed = state.isDisturbed;
return *this;
}
inline const ::Oyster::Math::Float CustomBodyState::GetMass() const
{
return this->mass;
}
inline const ::Oyster::Math::Float CustomBodyState::GetRestitutionCoeff() const
{
return this->restitutionCoeff;
}
inline const ::Oyster::Math::Float CustomBodyState::GetFrictionCoeff() const
{
return this->frictionCoeff;
}
inline const ::Oyster::Math::Float4x4 & CustomBodyState::GetMomentOfInertia() const
{
return this->inertiaTensor;
}
inline const ::Oyster::Math::Float4 & CustomBodyState::GetReach() const
{
return this->reach;
@ -76,16 +106,14 @@ namespace Oyster { namespace Physics
return ::Oyster::Math3D::RotationMatrix( this->GetAngularAxis().xyz );
}
inline const ::Oyster::Math::Float CustomBodyState::GetMass() const
inline ::Oyster::Math::Float4x4 CustomBodyState::GetOrientation() const
{
//! @todo TODO: stub to be implemented (CustomBodyState::GetMass)
return 1.0f;
return ::Oyster::Math3D::OrientationMatrix( this->angularAxis.xyz, this->centerPos.xyz );
}
inline const ::Oyster::Math::Float CustomBodyState::GetRestitutionCoeff() const
inline ::Oyster::Math::Float4x4 CustomBodyState::GetView() const
{
//! @todo TODO: stub to be implemented (CustomBodyState::GetRestitutionCoeff)
return 1.0f;
return ::Oyster::Math3D::ViewMatrix( this->angularAxis.xyz, this->centerPos.xyz );
}
inline const ::Oyster::Math::Float4 & CustomBodyState::GetLinearMomentum() const
@ -93,15 +121,10 @@ namespace Oyster { namespace Physics
return this->linearMomentum;
}
inline ::Oyster::Math::Float4 CustomBodyState::GetLinearMomentum( const ::Oyster::Math::Float3 &at ) const
{
return this->GetLinearMomentum( ::Oyster::Math::Float4(at, 1.0f) );
}
inline ::Oyster::Math::Float4 CustomBodyState::GetLinearMomentum( const ::Oyster::Math::Float4 &at ) const
{
//! @todo TODO: stub to be implemented (CustomBodyState::GetLinearMomentum)
return ::Oyster::Math::Float4::null;
//return this->linearMomentum + ::Oyster::Physics3D::Formula::TangentialLinearMomentum( this->angularMomentum, at - this->centerPos ); // C3083 error?
return this->linearMomentum + ::Oyster::Math::Float4( this->angularMomentum.xyz.Cross((at - this->centerPos).xyz), 0.0f );
}
inline const ::Oyster::Math::Float4 & CustomBodyState::GetAngularMomentum() const
@ -109,25 +132,79 @@ namespace Oyster { namespace Physics
return this->angularMomentum;
}
inline void CustomBodyState::SetSize( const ::Oyster::Math::Float3 &size )
inline const ::Oyster::Math::Float4 & CustomBodyState::GetLinearImpulse() const
{
return this->linearImpulse;
}
inline const ::Oyster::Math::Float4 & CustomBodyState::GetAngularImpulse() const
{
return this->angularImpulse;
}
inline void CustomBodyState::SetMass_KeepMomentum( ::Oyster::Math::Float m )
{
this->mass = m;
}
inline void CustomBodyState::SetMass_KeepVelocity( ::Oyster::Math::Float m )
{
if( m != 0.0f )
{ // sanity block!
// Formula::LinearMomentum( m, Formula::LinearVelocity(this->mass, this->linearMomentum) )
// is the same as (this->linearMomentum / this->mass) * m = (m / this->mass) * this->linearMomentum
this->linearMomentum *= (m / this->mass);
this->mass = m;
}
}
inline void CustomBodyState::SetRestitutionCoeff( ::Oyster::Math::Float e )
{
this->restitutionCoeff = e;
}
inline void CustomBodyState::SetFrictionCoeff( ::Oyster::Math::Float u )
{
this->frictionCoeff = u;
}
inline void CustomBodyState::SetMomentOfInertia_KeepMomentum( const ::Oyster::Math::Float4x4 &tensor )
{
this->inertiaTensor = tensor;
}
inline void CustomBodyState::SetMomentOfInertia_KeepVelocity( const ::Oyster::Math::Float4x4 &tensor )
{
if( tensor.GetDeterminant() != 0.0f )
{ // sanity block!
::Oyster::Math::Float4x4 rotation = ::Oyster::Math3D::RotationMatrix(this->angularAxis.xyz);
//::Oyster::Math::Float4 w = ::Oyster::Physics3D::Formula::AngularVelocity( (rotation * this->inertiaTensor).GetInverse(), this->angularMomentum ); // C3083 error?
::Oyster::Math::Float4 w = (rotation * this->inertiaTensor).GetInverse() * this->angularMomentum;
this->inertiaTensor = tensor;
//this->angularMomentum = ::Oyster::Physics3D::Formula::AngularMomentum( rotation * tensor, w ); // C3083 error?
this->angularMomentum = rotation * tensor * w;
}
}
inline void CustomBodyState::SetSize( const ::Oyster::Math::Float4 &size )
{
this->SetReach( 0.5f * size );
}
inline void CustomBodyState::SetReach( const ::Oyster::Math::Float3 &halfSize )
inline void CustomBodyState::SetReach( const ::Oyster::Math::Float4 &halfSize )
{
this->reach.xyz = halfSize;
this->reach = ::Utility::Value::Max( this->reach, ::Oyster::Math::Float4::null );
this->isSpatiallyAltered = this->isDisturbed = true;
}
inline void CustomBodyState::SetCenterPosition( const ::Oyster::Math::Float3 &centerPos )
inline void CustomBodyState::SetCenterPosition( const ::Oyster::Math::Float4 &centerPos )
{
this->centerPos.xyz = centerPos;
this->isSpatiallyAltered = this->isDisturbed = true;
}
inline void CustomBodyState::SetRotation( const ::Oyster::Math::Float3 &angularAxis )
inline void CustomBodyState::SetRotation( const ::Oyster::Math::Float4 &angularAxis )
{
this->angularAxis.xyz = angularAxis;
this->isSpatiallyAltered = this->isDisturbed = true;
@ -135,43 +212,69 @@ namespace Oyster { namespace Physics
inline void CustomBodyState::SetRotation( const ::Oyster::Math::Float4x4 &rotation )
{
this->SetRotation( ::Oyster::Math3D::AngularAxis(rotation).xyz );
this->SetRotation( ::Oyster::Math3D::AngularAxis(rotation) );
}
inline void CustomBodyState::SetMass( ::Oyster::Math::Float m )
inline void CustomBodyState::SetOrientation( const ::Oyster::Math::Float4x4 &orientation )
{
//! @todo TODO: stub to be implemented (CustomBodyState::SetRestitutionCoeff)
this->SetRotation( ::Oyster::Math3D::ExtractAngularAxis(orientation) );
this->SetCenterPosition( orientation.v[3] );
}
inline void CustomBodyState::SetRestitutionCoeff( ::Oyster::Math::Float e )
inline void CustomBodyState::SetLinearMomentum( const ::Oyster::Math::Float4 &g )
{
//! @todo TODO: stub to be implemented (CustomBodyState::SetRestitutionCoeff)
}
inline void CustomBodyState::SetLinearMomentum( const ::Oyster::Math::Float3 &g )
{
this->linearMomentum = ::Oyster::Math::Float4( g, 0.0f );
this->linearMomentum.xyz = g;
this->isDisturbed = true;
}
inline void CustomBodyState::SetAngularMomentum( const ::Oyster::Math::Float3 &h )
inline void CustomBodyState::SetAngularMomentum( const ::Oyster::Math::Float4 &h )
{
this->angularMomentum = ::Oyster::Math::Float4( h, 0.0f );
this->angularMomentum.xyz = h;
this->isDisturbed = true;
}
inline void CustomBodyState::ApplyImpulse( const ::Oyster::Math::Float4 &j )
inline void CustomBodyState::SetLinearImpulse( const ::Oyster::Math::Float4 &j )
{
this->linearMomentum += j;
this->linearImpulse.xyz = j;
this->isDisturbed = true;
}
inline void CustomBodyState::SetAngularImpulse( const ::Oyster::Math::Float4 &j )
{
this->angularImpulse.xyz = j;
this->isDisturbed = true;
}
inline void CustomBodyState::AddRotation( const ::Oyster::Math::Float4 &angularAxis )
{
this->angularAxis += angularAxis;
this->isSpatiallyAltered = this->isDisturbed = true;
}
inline void CustomBodyState::AddTranslation( const ::Oyster::Math::Float4 &deltaPos )
{
this->centerPos += deltaPos;
this->isSpatiallyAltered = this->isDisturbed = true;
}
inline void CustomBodyState::ApplyLinearImpulse( const ::Oyster::Math::Float4 &j )
{
this->linearImpulse += j;
this->isDisturbed = true;
}
inline void CustomBodyState::ApplyAngularImpulse( const ::Oyster::Math::Float4 &j )
{
this->angularImpulse += j;
this->isDisturbed = true;
}
inline void CustomBodyState::ApplyImpulse( const ::Oyster::Math::Float4 &j, const ::Oyster::Math::Float4 &at, const ::Oyster::Math::Float4 &normal )
{
//! @todo TODO: stub to be implemented (CustomBodyState::ApplyImpulse)
this->linearMomentum += j.Dot( normal ) * normal; // perpendicular impulse component
//this->angularImpulse += Formula:: ...
//::Oyster::Math::Float4 tangentialImpulse = ::Oyster::Physics3D::Formula::AngularMomentum( j, at - this->centerPos ); // C3083 error?
::Oyster::Math::Float4 tangentialImpulse = ::Oyster::Math::Float4( (at - this->centerPos).xyz.Cross(j.xyz), 0.0f );
this->linearImpulse += j - tangentialImpulse;
this->angularImpulse += tangentialImpulse;
this->isDisturbed = true;
}

View File

@ -11,8 +11,8 @@ namespace Oyster { namespace Physics
struct SimpleBodyDescription
{
::Oyster::Math::Float4x4 rotation;
::Oyster::Math::Float3 centerPosition;
::Oyster::Math::Float3 size;
::Oyster::Math::Float4 centerPosition;
::Oyster::Math::Float4 size;
::Oyster::Math::Float mass;
::Oyster::Math::Float4x4 inertiaTensor;
::Oyster::Physics::ICustomBody::EventAction_Collision subscription;
@ -24,7 +24,7 @@ namespace Oyster { namespace Physics
struct SphericalBodyDescription
{
::Oyster::Math::Float4x4 rotation;
::Oyster::Math::Float3 centerPosition;
::Oyster::Math::Float4 centerPosition;
::Oyster::Math::Float radius;
::Oyster::Math::Float mass;
::Oyster::Physics::ICustomBody::EventAction_Collision subscription;
@ -36,46 +36,68 @@ namespace Oyster { namespace Physics
struct CustomBodyState
{
public:
CustomBodyState( const ::Oyster::Math::Float3 &reach = ::Oyster::Math::Float3::null,
const ::Oyster::Math::Float3 &centerPos = ::Oyster::Math::Float3::null,
const ::Oyster::Math::Float3 &rotation = ::Oyster::Math::Float3::null,
const ::Oyster::Math::Float3 &linearMomentum = ::Oyster::Math::Float3::null,
const ::Oyster::Math::Float3 &angularMomentum = ::Oyster::Math::Float3::null );
CustomBodyState( ::Oyster::Math::Float mass = 1.0f,
::Oyster::Math::Float restitutionCoeff = 1.0f,
::Oyster::Math::Float frictionCoeff = 1.0f,
const ::Oyster::Math::Float4x4 &inertiaTensor = ::Oyster::Math::Float4x4::identity,
const ::Oyster::Math::Float4 &reach = ::Oyster::Math::Float4::null,
const ::Oyster::Math::Float4 &centerPos = ::Oyster::Math::Float4::standard_unit_w,
const ::Oyster::Math::Float4 &rotation = ::Oyster::Math::Float4::null,
const ::Oyster::Math::Float4 &linearMomentum = ::Oyster::Math::Float4::null,
const ::Oyster::Math::Float4 &angularMomentum = ::Oyster::Math::Float4::null );
CustomBodyState & operator = ( const CustomBodyState &state );
const ::Oyster::Math::Float4 & GetReach() const;
::Oyster::Math::Float4 GetSize() const;
const ::Oyster::Math::Float4 & GetCenterPosition() const;
const ::Oyster::Math::Float4 & GetAngularAxis() const;
::Oyster::Math::Float4x4 GetRotation() const;
const ::Oyster::Math::Float GetMass() const;
const ::Oyster::Math::Float GetRestitutionCoeff() const;
const ::Oyster::Math::Float4 & GetLinearMomentum() const;
::Oyster::Math::Float4 GetLinearMomentum( const ::Oyster::Math::Float3 &at ) const;
::Oyster::Math::Float4 GetLinearMomentum( const ::Oyster::Math::Float4 &at ) const;
const ::Oyster::Math::Float4 & GetAngularMomentum() const;
const ::Oyster::Math::Float GetMass() const;
const ::Oyster::Math::Float GetRestitutionCoeff() const;
const ::Oyster::Math::Float GetFrictionCoeff() const;
const ::Oyster::Math::Float4x4 & GetMomentOfInertia() const;
const ::Oyster::Math::Float4 & GetReach() const;
::Oyster::Math::Float4 GetSize() const;
const ::Oyster::Math::Float4 & GetCenterPosition() const;
const ::Oyster::Math::Float4 & GetAngularAxis() const;
::Oyster::Math::Float4x4 GetRotation() const;
::Oyster::Math::Float4x4 GetOrientation() const;
::Oyster::Math::Float4x4 GetView() const;
const ::Oyster::Math::Float4 & GetLinearMomentum() const;
::Oyster::Math::Float4 GetLinearMomentum( const ::Oyster::Math::Float4 &at ) const;
const ::Oyster::Math::Float4 & GetAngularMomentum() const;
const ::Oyster::Math::Float4 & GetLinearImpulse() const;
const ::Oyster::Math::Float4 & GetAngularImpulse() const;
void SetSize( const ::Oyster::Math::Float3 &size );
void SetReach( const ::Oyster::Math::Float3 &halfSize );
void SetCenterPosition( const ::Oyster::Math::Float3 &centerPos );
void SetRotation( const ::Oyster::Math::Float3 &angularAxis );
void SetRotation( const ::Oyster::Math::Float4x4 &rotation );
void SetMass( ::Oyster::Math::Float m );
void SetMass_KeepMomentum( ::Oyster::Math::Float m );
void SetMass_KeepVelocity( ::Oyster::Math::Float m );
void SetRestitutionCoeff( ::Oyster::Math::Float e );
void SetLinearMomentum( const ::Oyster::Math::Float3 &g );
void SetAngularMomentum( const ::Oyster::Math::Float3 &h );
void SetFrictionCoeff( ::Oyster::Math::Float u );
void SetMomentOfInertia_KeepMomentum( const ::Oyster::Math::Float4x4 &tensor );
void SetMomentOfInertia_KeepVelocity( const ::Oyster::Math::Float4x4 &tensor );
void SetSize( const ::Oyster::Math::Float4 &size );
void SetReach( const ::Oyster::Math::Float4 &halfSize );
void SetCenterPosition( const ::Oyster::Math::Float4 &centerPos );
void SetRotation( const ::Oyster::Math::Float4 &angularAxis );
void SetRotation( const ::Oyster::Math::Float4x4 &rotation );
void SetOrientation( const ::Oyster::Math::Float4x4 &orientation );
void SetLinearMomentum( const ::Oyster::Math::Float4 &g );
void SetAngularMomentum( const ::Oyster::Math::Float4 &h );
void SetLinearImpulse( const ::Oyster::Math::Float4 &j );
void SetAngularImpulse( const ::Oyster::Math::Float4 &j );
void ApplyImpulse( const ::Oyster::Math::Float4 &j );
void AddRotation( const ::Oyster::Math::Float4 &angularAxis );
void AddTranslation( const ::Oyster::Math::Float4 &deltaPos );
void ApplyLinearImpulse( const ::Oyster::Math::Float4 &j );
void ApplyAngularImpulse( const ::Oyster::Math::Float4 &j );
void ApplyImpulse( const ::Oyster::Math::Float4 &j, const ::Oyster::Math::Float4 &at, const ::Oyster::Math::Float4 &normal );
bool IsSpatiallyAltered() const;
bool IsDisturbed() const;
private:
::Oyster::Math::Float mass, restitutionCoeff, frictionCoeff;
::Oyster::Math::Float4x4 inertiaTensor;
::Oyster::Math::Float4 reach, centerPos, angularAxis;
::Oyster::Math::Float4 linearMomentum, angularMomentum;
::Oyster::Math::Float4 linearImpulse, angularImpulse;
bool isSpatiallyAltered, isDisturbed;
};

View File

@ -266,6 +266,12 @@ namespace LinearAlgebra3D
return ::std::asin( ::LinearAlgebra::Vector4<ScalarType>(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) );
}
template<typename ScalarType>
inline ::LinearAlgebra::Vector4<ScalarType> ExtractAngularAxis( const ::LinearAlgebra::Matrix4x4<ScalarType> &orientationMatrix )
{
return ::std::asin( ::LinearAlgebra::Vector4<ScalarType>(orientationMatrix.v[1].z, orientationMatrix.v[2].x, orientationMatrix.v[0].y, 1) );
}
template<typename ScalarType>
inline ::LinearAlgebra::Matrix4x4<ScalarType> & TranslationMatrix( const ::LinearAlgebra::Vector3<ScalarType> &position, ::LinearAlgebra::Matrix4x4<ScalarType> &targetMem = ::LinearAlgebra::Matrix4x4<ScalarType>() )
{
@ -400,18 +406,35 @@ namespace LinearAlgebra3D
}
template<typename ScalarType>
::LinearAlgebra::Matrix4x4<ScalarType> & OrientationMatrix( const ::LinearAlgebra::Vector3<ScalarType> &sumDeltaAngularAxis, const ::LinearAlgebra::Vector3<ScalarType> &sumTranslation, ::LinearAlgebra::Matrix4x4<ScalarType> &targetMem = ::LinearAlgebra::Matrix4x4<ScalarType>() )
{ /** @todo TODO: not tested */
ScalarType radian = sumDeltaAngularAxis.Dot( sumDeltaAngularAxis );
::LinearAlgebra::Matrix4x4<ScalarType> & OrientationMatrix( const ::LinearAlgebra::Vector3<ScalarType> &angularAxis, const ::LinearAlgebra::Vector3<ScalarType> &translation, ::LinearAlgebra::Matrix4x4<ScalarType> &targetMem = ::LinearAlgebra::Matrix4x4<ScalarType>() )
{
ScalarType radian = angularAxis.Dot( angularAxis );
if( radian > 0 )
{
radian = ::std::sqrt( radian );
return OrientationMatrix( sumDeltaAngularAxis / radian, radian, sumTranslation, targetMem );
return OrientationMatrix( angularAxis / radian, radian, translation, targetMem );
}
else
{
targetMem = ::LinearAlgebra::Matrix4x4<ScalarType>::identity;
targetMem.v[3].xyz = sumTranslation;
targetMem.v[3].xyz = translation;
return targetMem;
}
}
template<typename ScalarType>
::LinearAlgebra::Matrix4x4<ScalarType> & ViewMatrix( const ::LinearAlgebra::Vector3<ScalarType> &angularAxis, const ::LinearAlgebra::Vector3<ScalarType> &translation, ::LinearAlgebra::Matrix4x4<ScalarType> &targetMem = ::LinearAlgebra::Matrix4x4<ScalarType>() )
{
ScalarType radian = angularAxis.Dot( angularAxis );
if( radian > 0 )
{
radian = ::std::sqrt( radian );
return InverseOrientationMatrix( OrientationMatrix(angularAxis / radian, radian, translation, targetMem) );
}
else
{
targetMem = ::LinearAlgebra::Matrix4x4<ScalarType>::identity;
targetMem.v[3].xyz = -translation;
return targetMem;
}
}

View File

@ -91,6 +91,11 @@ namespace Oyster { namespace Math3D
return ::LinearAlgebra3D::AngularAxis( rotationMatrix );
}
Float4 ExtractAngularAxis( const Float4x4 &orientationMatrix )
{
return ::LinearAlgebra3D::ExtractAngularAxis( orientationMatrix );
}
Float4x4 & TranslationMatrix( const Float3 &position, Float4x4 &targetMem )
{
return ::LinearAlgebra3D::TranslationMatrix( position, targetMem );
@ -147,9 +152,14 @@ namespace Oyster { namespace Math3D
return ::LinearAlgebra3D::OrientationMatrix( normalizedAxis, deltaRadian, sumTranslation, targetMem );
}
Float4x4 & OrientationMatrix( const Float3 &sumDeltaAngularAxis, const Float3 &sumTranslation, Float4x4 &targetMem )
Float4x4 & OrientationMatrix( const Float3 &angularAxis, const Float3 &translation, Float4x4 &targetMem )
{
return ::LinearAlgebra3D::OrientationMatrix( sumDeltaAngularAxis, sumTranslation, targetMem );
return ::LinearAlgebra3D::OrientationMatrix( angularAxis, translation, targetMem );
}
Float4x4 & ViewMatrix( const Float3 &angularAxis, const Float3 &translation, Float4x4 &targetMem )
{
return ::LinearAlgebra3D::ViewMatrix( angularAxis, translation, targetMem );
}
Float4x4 & OrientationMatrix( const Float3 &sumDeltaAngularAxis, const Float3 &sumTranslation, const Float3 &centerOfMass, Float4x4 &targetMem )

View File

@ -153,6 +153,9 @@ namespace Oyster { namespace Math3D /// Oyster's native math library specialized
//! Extracts the angularAxis from rotationMatrix
Float4 AngularAxis( const Float4x4 &rotationMatrix );
//! Extracts the angularAxis from orientationMatrix
Float4 ExtractAngularAxis( const Float4x4 &orientationMatrix );
/// Sets and returns targetMem to a translationMatrix with position as translation.
Float4x4 & TranslationMatrix( const Float3 &position, Float4x4 &targetMem = Float4x4() );
@ -191,19 +194,26 @@ namespace Oyster { namespace Math3D /// Oyster's native math library specialized
* @param sumTranslation: sum of all the translation vectors.
* @param targetMem: is set to a rigibody matrix that rotate counterclockwise and then translates.
* @return targetMem
* @todo TODO: not tested
*******************************************************************/
Float4x4 & OrientationMatrix( const Float3 &normalizedAxis, const Float & deltaRadian, const Float3 &sumTranslation, Float4x4 &targetMem = Float4x4() );
/*******************************************************************
* Sets and returns targetMem as an orientation Matrix
* @param sumDeltaAngularAxis: sum of all ( (1/I) * ( L x D ) )-vectorproducts. There I is known as "moment of inertia", L as "angular momentum vector" and D the "lever vector".
* @param sumTranslation: sum of all the translation vectors.
* @param angularAxis: sum of all ( (1/I) * ( L x D ) )-vectorproducts. There I is known as "moment of inertia", L as "angular momentum vector" and D the "lever vector".
* @param translation: sum of all the translation vectors.
* @param targetMem: is set to a rigibody matrix that rotate counterclockwise and then translates.
* @return targetMem
* @todo TODO: not tested
*******************************************************************/
Float4x4 & OrientationMatrix( const Float3 &sumDeltaAngularAxis, const Float3 &sumTranslation, Float4x4 &targetMem = Float4x4() );
Float4x4 & OrientationMatrix( const Float3 &angularAxis, const Float3 &translation, Float4x4 &targetMem = Float4x4() );
/*******************************************************************
* Sets and returns targetMem as a view Matrix
* @param angularAxis: sum of all ( (1/I) * ( L x D ) )-vectorproducts. There I is known as "moment of inertia", L as "angular momentum vector" and D the "lever vector".
* @param translation: sum of all the translation vectors.
* @param targetMem: is set to a rigibody matrix that rotate counterclockwise and then translates.
* @return targetMem
*******************************************************************/
Float4x4 & ViewMatrix( const Float3 &angularAxis, const Float3 &translation, Float4x4 &targetMem = Float4x4() );
/*******************************************************************
* Sets and returns targetMem as an orientation Matrix

View File

@ -12,6 +12,60 @@ namespace Oyster { namespace Physics3D
namespace Formula
{ /// Library of 3D physics related formulas
/******************************************************************
* Returns the linear momentum of a mass in motion.
* @todo TODO: improve doc
******************************************************************/
inline ::Oyster::Math::Float4 LinearMomentum( const ::Oyster::Math::Float &mass, const ::Oyster::Math::Float4 &linearVelocity )
{
return linearVelocity * mass;
}
/******************************************************************
* Returns the linear momentum of a mass in motion.
* @todo TODO: improve doc
******************************************************************/
inline ::Oyster::Math::Float4 LinearVelocity( const ::Oyster::Math::Float &mass, const ::Oyster::Math::Float4 &linearMomentum )
{
return linearMomentum / mass;
}
/******************************************************************
* Returns the world angular momentum of a mass in rotation.
* @todo TODO: improve doc
******************************************************************/
inline ::Oyster::Math::Float4 AngularMomentum( const ::Oyster::Math::Float4 linearMomentum, const ::Oyster::Math::Float4 &worldOffset )
{
return ::Oyster::Math::Float4( worldOffset.xyz.Cross(linearMomentum.xyz), 0.0f );
}
/******************************************************************
* Returns the world angular momentum of a mass in rotation.
* @todo TODO: improve doc
******************************************************************/
inline ::Oyster::Math::Float4 AngularMomentum( const ::Oyster::Math::Float4x4 &worldMomentOfInertia, const ::Oyster::Math::Float4 &angularVelocity )
{
return worldMomentOfInertia * angularVelocity;
}
/******************************************************************
* Returns the world angular velocity of a mass in rotation.
* @todo TODO: improve doc
******************************************************************/
inline ::Oyster::Math::Float4 AngularVelocity( const ::Oyster::Math::Float4x4 &worldMomentOfInertiaInversed, const ::Oyster::Math::Float4 &angularMomentum )
{
return worldMomentOfInertiaInversed * angularMomentum;
}
/******************************************************************
* Returns the world tangential momentum at worldPos, of a mass in rotation.
* @todo TODO: improve doc
******************************************************************/
inline ::Oyster::Math::Float4 TangentialLinearMomentum( const ::Oyster::Math::Float4 &angularMomentum, const ::Oyster::Math::Float4 &worldOffset )
{
return ::Oyster::Math::Float4( angularMomentum.xyz.Cross(worldOffset.xyz), 0.0f );
}
/******************************************************************
* Returns the linear kinetic energy of a mass in motion.
* @todo TODO: improve doc
@ -192,12 +246,6 @@ namespace Oyster { namespace Physics3D
return ( momentOfInertia * ::Oyster::Math::Float4(angularImpulseAcceleration, 0.0f) ).xyz;
}
inline ::Oyster::Math::Float3 Impulse( )
{
//! @todo TODO: implement calculation for impulse. Hijack Mattias Eriksson
return ::Oyster::Math::Float3::null;
}
namespace MomentOfInertia
{ /// Library of Formulas to calculate moment of inerta for simple shapes
/** @todo TODO: add MomentOfInertia tensor formulas */

View File

@ -16,6 +16,8 @@ RigidBody::RigidBody( const Box &b, Float m, const Float4x4 &inertiaTensor )
this->linearMomentum = Float3::null;
this->impulseTorqueSum = Float3::null;
this->impulseForceSum = Float3::null;
this->restitutionCoeff = 1.0f;
this->frictionCoeff = 1.0f;
if( m != 0.0f )
{
@ -43,6 +45,8 @@ RigidBody & RigidBody::operator = ( const RigidBody &body )
this->linearMomentum = body.linearMomentum;
this->impulseTorqueSum = body.impulseTorqueSum;
this->impulseForceSum = body.impulseForceSum;
this->restitutionCoeff = body.restitutionCoeff;
this->frictionCoeff = body.frictionCoeff;
this->mass = body.mass;
this->momentOfInertiaTensor = body.momentOfInertiaTensor;
return *this;

View File

@ -19,6 +19,7 @@ namespace Oyster { namespace Physics3D
linearMomentum, /** The linear momentum G (kg*m/s). (worldValue) */
impulseTorqueSum, /** The impulse torque T (Nm) that will be consumed each update. (worldValue) */
impulseForceSum; /** The impulse force F (N) that will be consumed each update. (worldValue) */
::Oyster::Math::Float restitutionCoeff, frictionCoeff;
RigidBody( const ::Oyster::Collision3D::Box &box = ::Oyster::Collision3D::Box(),
::Oyster::Math::Float mass = 12.0f,