parent
64565b50de
commit
2928e08252
|
@ -169,7 +169,7 @@ UniquePointer<ICustomBody> API_Impl::CreateRigidBody( const API::SimpleBodyDescr
|
||||||
|
|
||||||
UniquePointer<ICustomBody> API_Impl::CreateRigidBody( const API::SphericalBodyDescription &desc ) const
|
UniquePointer<ICustomBody> API_Impl::CreateRigidBody( const API::SphericalBodyDescription &desc ) const
|
||||||
{
|
{
|
||||||
return new SphericalRigidBody();
|
return new SphericalRigidBody( desc );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Oyster { namespace Physics { namespace Default
|
namespace Oyster { namespace Physics { namespace Default
|
||||||
|
|
|
@ -10,7 +10,7 @@ using namespace ::Utility::Value;
|
||||||
|
|
||||||
SimpleRigidBody::SimpleRigidBody()
|
SimpleRigidBody::SimpleRigidBody()
|
||||||
{
|
{
|
||||||
this->rigid = RigidBody();
|
this->rigid = RigidBody( Box(Float4x4::identity, Float3::null, Float3(1.0f)), 16.0f, Float4x4::identity );
|
||||||
this->gravityNormal = Float3::null;
|
this->gravityNormal = Float3::null;
|
||||||
this->collisionAction = Default::EventAction_Collision;
|
this->collisionAction = Default::EventAction_Collision;
|
||||||
this->ignoreGravity = false;
|
this->ignoreGravity = false;
|
||||||
|
|
|
@ -9,11 +9,33 @@ using namespace ::Utility::DynamicMemory;
|
||||||
using namespace ::Utility::Value;
|
using namespace ::Utility::Value;
|
||||||
|
|
||||||
SphericalRigidBody::SphericalRigidBody()
|
SphericalRigidBody::SphericalRigidBody()
|
||||||
: previous(), current( Box(Float4x4::identity, Float3::null, Float3(1.0f)) ),
|
{
|
||||||
gravityNormal( 0.0f ),
|
this->rigid = RigidBody( Box(Float4x4::identity, Float3::null, Float3(1.0f)), 10.0f, Float4x4::identity );
|
||||||
collisionAction(Default::EventAction_Collision),
|
this->gravityNormal = Float3::null;
|
||||||
ignoreGravity( false ),
|
this->collisionAction = Default::EventAction_Collision;
|
||||||
body( Float3::null, 0.5f ) {}
|
this->ignoreGravity = false;
|
||||||
|
this->body = Sphere( Float3::null, 0.5f );
|
||||||
|
}
|
||||||
|
|
||||||
|
SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &desc )
|
||||||
|
{
|
||||||
|
this->rigid = RigidBody( Box( desc.rotation, desc.centerPosition, Float3(2.0f * desc.radius) ),
|
||||||
|
desc.mass,
|
||||||
|
desc.inertiaTensor );
|
||||||
|
this->gravityNormal = Float3::null;
|
||||||
|
|
||||||
|
if( desc.subscription )
|
||||||
|
{
|
||||||
|
this->collisionAction = desc.subscription;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->collisionAction = Default::EventAction_Collision;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->ignoreGravity = desc.ignoreGravity;
|
||||||
|
this->body = Sphere( desc.centerPosition, desc.radius );
|
||||||
|
}
|
||||||
|
|
||||||
SphericalRigidBody::~SphericalRigidBody() {}
|
SphericalRigidBody::~SphericalRigidBody() {}
|
||||||
|
|
||||||
|
@ -43,7 +65,7 @@ bool SphericalRigidBody::Intersects( const ICustomBody &object, Float timeStepLe
|
||||||
|
|
||||||
bool SphericalRigidBody::Intersects( const ICollideable &shape ) const
|
bool SphericalRigidBody::Intersects( const ICollideable &shape ) const
|
||||||
{
|
{
|
||||||
return this->current.box.Intersects( shape );
|
return this->rigid.box.Intersects( shape );
|
||||||
}
|
}
|
||||||
|
|
||||||
Sphere & SphericalRigidBody::GetBoundingSphere( Sphere &targetMem ) const
|
Sphere & SphericalRigidBody::GetBoundingSphere( Sphere &targetMem ) const
|
||||||
|
@ -54,7 +76,7 @@ Sphere & SphericalRigidBody::GetBoundingSphere( Sphere &targetMem ) const
|
||||||
Float3 & SphericalRigidBody::GetNormalAt( const Float3 &worldPos, Float3 &targetMem ) const
|
Float3 & SphericalRigidBody::GetNormalAt( const Float3 &worldPos, Float3 &targetMem ) const
|
||||||
{
|
{
|
||||||
//! @todo TODO: better implementation needed
|
//! @todo TODO: better implementation needed
|
||||||
return targetMem = (worldPos - this->current.box.center).GetNormalized();
|
return targetMem = (worldPos - this->rigid.box.center).GetNormalized();
|
||||||
}
|
}
|
||||||
|
|
||||||
Float3 & SphericalRigidBody::GetGravityNormal( Float3 &targetMem ) const
|
Float3 & SphericalRigidBody::GetGravityNormal( Float3 &targetMem ) const
|
||||||
|
@ -64,33 +86,32 @@ Float3 & SphericalRigidBody::GetGravityNormal( Float3 &targetMem ) const
|
||||||
|
|
||||||
Float3 & SphericalRigidBody::GetCenter( Float3 &targetMem ) const
|
Float3 & SphericalRigidBody::GetCenter( Float3 &targetMem ) const
|
||||||
{
|
{
|
||||||
return targetMem = this->current.box.center;
|
return targetMem = this->rigid.box.center;
|
||||||
}
|
}
|
||||||
|
|
||||||
Float4x4 & SphericalRigidBody::GetRotation( Float4x4 &targetMem ) const
|
Float4x4 & SphericalRigidBody::GetRotation( Float4x4 &targetMem ) const
|
||||||
{
|
{
|
||||||
return targetMem = this->current.box.rotation;
|
return targetMem = this->rigid.box.rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
Float4x4 & SphericalRigidBody::GetOrientation( Float4x4 &targetMem ) const
|
Float4x4 & SphericalRigidBody::GetOrientation( Float4x4 &targetMem ) const
|
||||||
{
|
{
|
||||||
return targetMem = this->current.GetOrientation();
|
return targetMem = this->rigid.GetOrientation();
|
||||||
}
|
}
|
||||||
|
|
||||||
Float4x4 & SphericalRigidBody::GetView( Float4x4 &targetMem ) const
|
Float4x4 & SphericalRigidBody::GetView( Float4x4 &targetMem ) const
|
||||||
{
|
{
|
||||||
return targetMem = this->current.GetView();
|
return targetMem = this->rigid.GetView();
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateState SphericalRigidBody::Update( Float timeStepLength )
|
UpdateState SphericalRigidBody::Update( Float timeStepLength )
|
||||||
{
|
{
|
||||||
this->previous = this->current; // memorizing the old state
|
this->rigid.Update_LeapFrog( timeStepLength );
|
||||||
|
this->body.center = this->rigid.GetCenter();
|
||||||
this->current.Update_LeapFrog( timeStepLength );
|
|
||||||
this->body.center = this->current.GetCenter();
|
|
||||||
|
|
||||||
// compare previous and new state and return result
|
// compare previous and new state and return result
|
||||||
return this->current == this->previous ? UpdateState_resting : UpdateState_altered;
|
//return this->current == this->previous ? UpdateState_resting : UpdateState_altered;
|
||||||
|
return UpdateState_altered;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Collision functionPointer )
|
void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Collision functionPointer )
|
||||||
|
@ -118,43 +139,43 @@ void SphericalRigidBody::SetGravityNormal( const Float3 &normalizedVector )
|
||||||
|
|
||||||
void SphericalRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI )
|
void SphericalRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI )
|
||||||
{
|
{
|
||||||
this->current.SetMomentOfInertia_KeepVelocity( localI );
|
this->rigid.SetMomentOfInertia_KeepVelocity( localI );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SphericalRigidBody::SetMomentOfInertiaTensor_KeepMomentum( const Float4x4 &localI )
|
void SphericalRigidBody::SetMomentOfInertiaTensor_KeepMomentum( const Float4x4 &localI )
|
||||||
{
|
{
|
||||||
this->current.SetMomentOfInertia_KeepMomentum( localI );
|
this->rigid.SetMomentOfInertia_KeepMomentum( localI );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SphericalRigidBody::SetMass_KeepVelocity( Float m )
|
void SphericalRigidBody::SetMass_KeepVelocity( Float m )
|
||||||
{
|
{
|
||||||
this->current.SetMass_KeepVelocity( m );
|
this->rigid.SetMass_KeepVelocity( m );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SphericalRigidBody::SetMass_KeepMomentum( Float m )
|
void SphericalRigidBody::SetMass_KeepMomentum( Float m )
|
||||||
{
|
{
|
||||||
this->current.SetMass_KeepMomentum( m );
|
this->rigid.SetMass_KeepMomentum( m );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SphericalRigidBody::SetCenter( const Float3 &worldPos )
|
void SphericalRigidBody::SetCenter( const Float3 &worldPos )
|
||||||
{
|
{
|
||||||
this->current.SetCenter( worldPos );
|
this->rigid.SetCenter( worldPos );
|
||||||
this->body.center = worldPos;
|
this->body.center = worldPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SphericalRigidBody::SetRotation( const Float4x4 &rotation )
|
void SphericalRigidBody::SetRotation( const Float4x4 &rotation )
|
||||||
{
|
{
|
||||||
this->current.SetRotation( rotation );
|
this->rigid.SetRotation( rotation );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SphericalRigidBody::SetOrientation( const Float4x4 &orientation )
|
void SphericalRigidBody::SetOrientation( const Float4x4 &orientation )
|
||||||
{
|
{
|
||||||
this->current.SetOrientation( orientation );
|
this->rigid.SetOrientation( orientation );
|
||||||
this->body.center = orientation.v[3].xyz;
|
this->body.center = orientation.v[3].xyz;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SphericalRigidBody::SetSize( const Float3 &size )
|
void SphericalRigidBody::SetSize( const Float3 &size )
|
||||||
{
|
{
|
||||||
this->current.SetSize( size );
|
this->rigid.SetSize( size );
|
||||||
this->body.radius = 0.5f * Min( Min( size.x, size.y ), size.z ); // inline Min( FloatN )?
|
this->body.radius = 0.5f * Min( Min( size.x, size.y ), size.z ); // inline Min( FloatN )?
|
||||||
}
|
}
|
|
@ -11,6 +11,7 @@ namespace Oyster { namespace Physics
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SphericalRigidBody();
|
SphericalRigidBody();
|
||||||
|
SphericalRigidBody( const API::SphericalBodyDescription &desc );
|
||||||
virtual ~SphericalRigidBody();
|
virtual ~SphericalRigidBody();
|
||||||
|
|
||||||
::Utility::DynamicMemory::UniquePointer<ICustomBody> Clone() const;
|
::Utility::DynamicMemory::UniquePointer<ICustomBody> Clone() const;
|
||||||
|
@ -43,7 +44,7 @@ namespace Oyster { namespace Physics
|
||||||
void SetSize( const ::Oyster::Math::Float3 &size );
|
void SetSize( const ::Oyster::Math::Float3 &size );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
::Oyster::Physics3D::RigidBody previous, current;
|
::Oyster::Physics3D::RigidBody rigid;
|
||||||
::Oyster::Math::Float3 gravityNormal;
|
::Oyster::Math::Float3 gravityNormal;
|
||||||
EventAction_Collision collisionAction;
|
EventAction_Collision collisionAction;
|
||||||
bool ignoreGravity;
|
bool ignoreGravity;
|
||||||
|
|
Loading…
Reference in New Issue