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
|
||||
{
|
||||
return new SphericalRigidBody();
|
||||
return new SphericalRigidBody( desc );
|
||||
}
|
||||
|
||||
namespace Oyster { namespace Physics { namespace Default
|
||||
|
|
|
@ -10,7 +10,7 @@ using namespace ::Utility::Value;
|
|||
|
||||
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->collisionAction = Default::EventAction_Collision;
|
||||
this->ignoreGravity = false;
|
||||
|
|
|
@ -9,11 +9,33 @@ using namespace ::Utility::DynamicMemory;
|
|||
using namespace ::Utility::Value;
|
||||
|
||||
SphericalRigidBody::SphericalRigidBody()
|
||||
: previous(), current( Box(Float4x4::identity, Float3::null, Float3(1.0f)) ),
|
||||
gravityNormal( 0.0f ),
|
||||
collisionAction(Default::EventAction_Collision),
|
||||
ignoreGravity( false ),
|
||||
body( Float3::null, 0.5f ) {}
|
||||
{
|
||||
this->rigid = RigidBody( Box(Float4x4::identity, Float3::null, Float3(1.0f)), 10.0f, Float4x4::identity );
|
||||
this->gravityNormal = Float3::null;
|
||||
this->collisionAction = Default::EventAction_Collision;
|
||||
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() {}
|
||||
|
||||
|
@ -43,7 +65,7 @@ bool SphericalRigidBody::Intersects( const ICustomBody &object, Float timeStepLe
|
|||
|
||||
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
|
||||
|
@ -54,7 +76,7 @@ Sphere & SphericalRigidBody::GetBoundingSphere( Sphere &targetMem ) const
|
|||
Float3 & SphericalRigidBody::GetNormalAt( const Float3 &worldPos, Float3 &targetMem ) const
|
||||
{
|
||||
//! @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
|
||||
|
@ -64,33 +86,32 @@ Float3 & SphericalRigidBody::GetGravityNormal( 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
|
||||
{
|
||||
return targetMem = this->current.box.rotation;
|
||||
return targetMem = this->rigid.box.rotation;
|
||||
}
|
||||
|
||||
Float4x4 & SphericalRigidBody::GetOrientation( Float4x4 &targetMem ) const
|
||||
{
|
||||
return targetMem = this->current.GetOrientation();
|
||||
return targetMem = this->rigid.GetOrientation();
|
||||
}
|
||||
|
||||
Float4x4 & SphericalRigidBody::GetView( Float4x4 &targetMem ) const
|
||||
{
|
||||
return targetMem = this->current.GetView();
|
||||
return targetMem = this->rigid.GetView();
|
||||
}
|
||||
|
||||
UpdateState SphericalRigidBody::Update( Float timeStepLength )
|
||||
{
|
||||
this->previous = this->current; // memorizing the old state
|
||||
|
||||
this->current.Update_LeapFrog( timeStepLength );
|
||||
this->body.center = this->current.GetCenter();
|
||||
this->rigid.Update_LeapFrog( timeStepLength );
|
||||
this->body.center = this->rigid.GetCenter();
|
||||
|
||||
// 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 )
|
||||
|
@ -118,43 +139,43 @@ void SphericalRigidBody::SetGravityNormal( const Float3 &normalizedVector )
|
|||
|
||||
void SphericalRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI )
|
||||
{
|
||||
this->current.SetMomentOfInertia_KeepVelocity( localI );
|
||||
this->rigid.SetMomentOfInertia_KeepVelocity( localI );
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetMomentOfInertiaTensor_KeepMomentum( const Float4x4 &localI )
|
||||
{
|
||||
this->current.SetMomentOfInertia_KeepMomentum( localI );
|
||||
this->rigid.SetMomentOfInertia_KeepMomentum( localI );
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetMass_KeepVelocity( Float m )
|
||||
{
|
||||
this->current.SetMass_KeepVelocity( m );
|
||||
this->rigid.SetMass_KeepVelocity( m );
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetMass_KeepMomentum( Float m )
|
||||
{
|
||||
this->current.SetMass_KeepMomentum( m );
|
||||
this->rigid.SetMass_KeepMomentum( m );
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetCenter( const Float3 &worldPos )
|
||||
{
|
||||
this->current.SetCenter( worldPos );
|
||||
this->rigid.SetCenter( worldPos );
|
||||
this->body.center = worldPos;
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetRotation( const Float4x4 &rotation )
|
||||
{
|
||||
this->current.SetRotation( rotation );
|
||||
this->rigid.SetRotation( rotation );
|
||||
}
|
||||
|
||||
void SphericalRigidBody::SetOrientation( const Float4x4 &orientation )
|
||||
{
|
||||
this->current.SetOrientation( orientation );
|
||||
this->rigid.SetOrientation( orientation );
|
||||
this->body.center = orientation.v[3].xyz;
|
||||
}
|
||||
|
||||
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 )?
|
||||
}
|
|
@ -11,6 +11,7 @@ namespace Oyster { namespace Physics
|
|||
{
|
||||
public:
|
||||
SphericalRigidBody();
|
||||
SphericalRigidBody( const API::SphericalBodyDescription &desc );
|
||||
virtual ~SphericalRigidBody();
|
||||
|
||||
::Utility::DynamicMemory::UniquePointer<ICustomBody> Clone() const;
|
||||
|
@ -43,7 +44,7 @@ namespace Oyster { namespace Physics
|
|||
void SetSize( const ::Oyster::Math::Float3 &size );
|
||||
|
||||
private:
|
||||
::Oyster::Physics3D::RigidBody previous, current;
|
||||
::Oyster::Physics3D::RigidBody rigid;
|
||||
::Oyster::Math::Float3 gravityNormal;
|
||||
EventAction_Collision collisionAction;
|
||||
bool ignoreGravity;
|
||||
|
|
Loading…
Reference in New Issue