CustomBodies now aware of it's scene

+ other minor changes
This commit is contained in:
Dander7BD 2013-12-19 10:53:55 +01:00
parent 59d5a3dc1e
commit 42418257cb
7 changed files with 76 additions and 7 deletions

View File

@ -31,6 +31,7 @@ Octree& Octree::operator=(const Octree& orig)
void Octree::AddObject(UniquePointer< ICustomBody > customBodyRef) void Octree::AddObject(UniquePointer< ICustomBody > customBodyRef)
{ {
customBodyRef->SetScene( this );
Data data; Data data;
//Data* tempPtr = this->worldNode.dataPtr; //Data* tempPtr = this->worldNode.dataPtr;

View File

@ -44,10 +44,9 @@ namespace
protoState.GetMass(), protoG_Magnitude );; protoState.GetMass(), protoG_Magnitude );;
Float4 sumJ = normal*impulse; Float4 sumJ = normal*impulse;
sumJ -= Formula::CollisionResponse::Friction( impulse, normal, protoState.GetLinearMomentum(), sumJ -= Formula::CollisionResponse::Friction( impulse, normal,
protoState.GetFrictionCoeff(), 0.2f, protoState.GetMass(), protoState.GetLinearMomentum(), protoState.GetFrictionCoeff_Static(), protoState.GetFrictionCoeff_Kinetic(), protoState.GetMass(),
deuterState.GetLinearMomentum(), deuterState.GetFrictionCoeff(), deuterState.GetLinearMomentum(), deuterState.GetFrictionCoeff_Static(), deuterState.GetFrictionCoeff_Kinetic(), deuterState.GetMass());
0.2f, deuterState.GetMass());
// calc from perspective of proto // calc from perspective of proto
proto->GetNormalAt( worldPointOfContact, normal ); proto->GetNormalAt( worldPointOfContact, normal );

View File

@ -14,6 +14,7 @@ SimpleRigidBody::SimpleRigidBody()
this->gravityNormal = Float3::null; this->gravityNormal = Float3::null;
this->collisionAction = Default::EventAction_Collision; this->collisionAction = Default::EventAction_Collision;
this->ignoreGravity = false; this->ignoreGravity = false;
this->scene = nullptr;
} }
SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc ) SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc )
@ -33,6 +34,7 @@ SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc )
} }
this->ignoreGravity = desc.ignoreGravity; this->ignoreGravity = desc.ignoreGravity;
this->scene = nullptr;
} }
SimpleRigidBody::~SimpleRigidBody() {} SimpleRigidBody::~SimpleRigidBody() {}
@ -61,10 +63,31 @@ SimpleRigidBody::State & SimpleRigidBody::GetState( SimpleRigidBody::State &targ
} }
void SimpleRigidBody::SetState( const SimpleRigidBody::State &state ) void SimpleRigidBody::SetState( const SimpleRigidBody::State &state )
{ /** @todo TODO: temporary solution! Need to know it's occtree */ {
this->rigid.box.boundingOffset = state.GetReach(); this->rigid.box.boundingOffset = state.GetReach();
this->rigid.box.center = state.GetCenterPosition(); this->rigid.box.center = state.GetCenterPosition();
this->rigid.box.rotation = state.GetRotation(); this->rigid.box.rotation = state.GetRotation();
this->rigid.angularMomentum = state.GetAngularMomentum().xyz;
this->rigid.linearMomentum = state.GetLinearMomentum().xyz;
this->rigid.impulseTorqueSum += state.GetAngularImpulse().xyz;
this->rigid.impulseForceSum += state.GetLinearImpulse().xyz;
this->rigid.restitutionCoeff = state.GetRestitutionCoeff();
this->rigid.frictionCoeff_Static = state.GetFrictionCoeff_Static();
this->rigid.frictionCoeff_Kinetic = state.GetFrictionCoeff_Kinetic();
if( this->scene )
{
if( state.IsSpatiallyAltered() )
{
unsigned int tempRef = this->scene->GetTemporaryReferenceOf( this );
this->scene->SetAsAltered( tempRef );
this->scene->EvaluatePosition( tempRef );
}
else if( state.IsDisturbed() )
{
this->scene->SetAsAltered( this->scene->GetTemporaryReferenceOf(this) );
}
}
} }
ICustomBody::SubscriptMessage SimpleRigidBody::CallSubscription( const ICustomBody *proto, const ICustomBody *deuter ) ICustomBody::SubscriptMessage SimpleRigidBody::CallSubscription( const ICustomBody *proto, const ICustomBody *deuter )
@ -187,6 +210,11 @@ UpdateState SimpleRigidBody::Update( Float timeStepLength )
return UpdateState_altered; return UpdateState_altered;
} }
void SimpleRigidBody::SetScene( void *scene )
{
this->scene = (Octree*)scene;
}
void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_Collision functionPointer ) void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_Collision functionPointer )
{ {
if( functionPointer ) if( functionPointer )

View File

@ -3,6 +3,7 @@
#include "..\PhysicsAPI.h" #include "..\PhysicsAPI.h"
#include "RigidBody.h" #include "RigidBody.h"
#include "Octree.h"
namespace Oyster { namespace Physics namespace Oyster { namespace Physics
{ {
@ -36,6 +37,7 @@ namespace Oyster { namespace Physics
UpdateState Update( ::Oyster::Math::Float timeStepLength ); UpdateState Update( ::Oyster::Math::Float timeStepLength );
void SetScene( void *scene );
void SetSubscription( EventAction_Collision functionPointer ); void SetSubscription( EventAction_Collision functionPointer );
void SetGravity( bool ignore); void SetGravity( bool ignore);
void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector ); void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector );
@ -53,6 +55,7 @@ namespace Oyster { namespace Physics
::Oyster::Physics3D::RigidBody rigid; ::Oyster::Physics3D::RigidBody rigid;
::Oyster::Math::Float3 gravityNormal; ::Oyster::Math::Float3 gravityNormal;
EventAction_Collision collisionAction; EventAction_Collision collisionAction;
Octree *scene;
bool ignoreGravity; bool ignoreGravity;
}; };
} } } }

View File

@ -14,6 +14,7 @@ SphericalRigidBody::SphericalRigidBody()
this->gravityNormal = Float3::null; this->gravityNormal = Float3::null;
this->collisionAction = Default::EventAction_Collision; this->collisionAction = Default::EventAction_Collision;
this->ignoreGravity = false; this->ignoreGravity = false;
this->scene = nullptr;
this->body = Sphere( Float3::null, 0.5f ); this->body = Sphere( Float3::null, 0.5f );
} }
@ -34,6 +35,7 @@ SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &des
} }
this->ignoreGravity = desc.ignoreGravity; this->ignoreGravity = desc.ignoreGravity;
this->scene = nullptr;
this->body = Sphere( desc.centerPosition, desc.radius ); this->body = Sphere( desc.centerPosition, desc.radius );
} }
@ -63,10 +65,31 @@ SphericalRigidBody::State & SphericalRigidBody::GetState( SphericalRigidBody::St
} }
void SphericalRigidBody::SetState( const SphericalRigidBody::State &state ) void SphericalRigidBody::SetState( const SphericalRigidBody::State &state )
{ /** @todo TODO: temporary solution! Need to know it's occtree */ {
this->rigid.box.boundingOffset = state.GetReach(); this->rigid.box.boundingOffset = state.GetReach();
this->rigid.box.center = state.GetCenterPosition(); this->rigid.box.center = state.GetCenterPosition();
this->rigid.box.rotation = state.GetRotation(); this->rigid.box.rotation = state.GetRotation();
this->rigid.angularMomentum = state.GetAngularMomentum().xyz;
this->rigid.linearMomentum = state.GetLinearMomentum().xyz;
this->rigid.impulseTorqueSum += state.GetAngularImpulse().xyz;
this->rigid.impulseForceSum += state.GetLinearImpulse().xyz;
this->rigid.restitutionCoeff = state.GetRestitutionCoeff();
this->rigid.frictionCoeff_Static = state.GetFrictionCoeff_Static();
this->rigid.frictionCoeff_Kinetic = state.GetFrictionCoeff_Kinetic();
if( this->scene )
{
if( state.IsSpatiallyAltered() )
{
unsigned int tempRef = this->scene->GetTemporaryReferenceOf( this );
this->scene->SetAsAltered( tempRef );
this->scene->EvaluatePosition( tempRef );
}
else if( state.IsDisturbed() )
{
this->scene->SetAsAltered( this->scene->GetTemporaryReferenceOf(this) );
}
}
} }
ICustomBody::SubscriptMessage SphericalRigidBody::CallSubscription( const ICustomBody *proto, const ICustomBody *deuter ) ICustomBody::SubscriptMessage SphericalRigidBody::CallSubscription( const ICustomBody *proto, const ICustomBody *deuter )
@ -156,7 +179,12 @@ void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Collision fun
} }
} }
void SphericalRigidBody::SetGravity( bool ignore) void SphericalRigidBody::SetScene( void *scene )
{
this->scene = (Octree*)scene;
}
void SphericalRigidBody::SetGravity( bool ignore )
{ {
this->ignoreGravity = ignore; this->ignoreGravity = ignore;
this->gravityNormal = Float3::null; this->gravityNormal = Float3::null;

View File

@ -4,6 +4,7 @@
#include "..\PhysicsAPI.h" #include "..\PhysicsAPI.h"
#include "RigidBody.h" #include "RigidBody.h"
#include "Sphere.h" #include "Sphere.h"
#include "Octree.h"
namespace Oyster { namespace Physics namespace Oyster { namespace Physics
{ {
@ -37,6 +38,7 @@ namespace Oyster { namespace Physics
UpdateState Update( ::Oyster::Math::Float timeStepLength ); UpdateState Update( ::Oyster::Math::Float timeStepLength );
void SetScene( void *scene );
void SetSubscription( EventAction_Collision functionPointer ); void SetSubscription( EventAction_Collision functionPointer );
void SetGravity( bool ignore); void SetGravity( bool ignore);
void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector ); void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector );
@ -55,6 +57,7 @@ namespace Oyster { namespace Physics
::Oyster::Math::Float3 gravityNormal; ::Oyster::Math::Float3 gravityNormal;
EventAction_Collision collisionAction; EventAction_Collision collisionAction;
bool ignoreGravity; bool ignoreGravity;
Octree *scene;
::Oyster::Collision3D::Sphere body; ::Oyster::Collision3D::Sphere body;
}; };
} } } }

View File

@ -338,6 +338,13 @@ namespace Oyster
********************************************************/ ********************************************************/
virtual UpdateState Update( ::Oyster::Math::Float timeStepLength ) = 0; virtual UpdateState Update( ::Oyster::Math::Float timeStepLength ) = 0;
/********************************************************
* Sets which scene this ICustomBody is within.
* Reserved to only be used by the scene.
* @todo TODO: create an IScene interface
********************************************************/
virtual void SetScene( void *scene ) = 0;
/******************************************************** /********************************************************
* Sets the function that will be called by the engine * Sets the function that will be called by the engine
* whenever a collision occurs. * whenever a collision occurs.