CustomBodies now aware of it's scene
+ other minor changes
This commit is contained in:
parent
59d5a3dc1e
commit
42418257cb
|
@ -31,6 +31,7 @@ Octree& Octree::operator=(const Octree& orig)
|
|||
|
||||
void Octree::AddObject(UniquePointer< ICustomBody > customBodyRef)
|
||||
{
|
||||
customBodyRef->SetScene( this );
|
||||
Data data;
|
||||
//Data* tempPtr = this->worldNode.dataPtr;
|
||||
|
||||
|
|
|
@ -44,10 +44,9 @@ namespace
|
|||
protoState.GetMass(), protoG_Magnitude );;
|
||||
Float4 sumJ = normal*impulse;
|
||||
|
||||
sumJ -= Formula::CollisionResponse::Friction( impulse, normal, protoState.GetLinearMomentum(),
|
||||
protoState.GetFrictionCoeff(), 0.2f, protoState.GetMass(),
|
||||
deuterState.GetLinearMomentum(), deuterState.GetFrictionCoeff(),
|
||||
0.2f, deuterState.GetMass());
|
||||
sumJ -= Formula::CollisionResponse::Friction( impulse, normal,
|
||||
protoState.GetLinearMomentum(), protoState.GetFrictionCoeff_Static(), protoState.GetFrictionCoeff_Kinetic(), protoState.GetMass(),
|
||||
deuterState.GetLinearMomentum(), deuterState.GetFrictionCoeff_Static(), deuterState.GetFrictionCoeff_Kinetic(), deuterState.GetMass());
|
||||
|
||||
// calc from perspective of proto
|
||||
proto->GetNormalAt( worldPointOfContact, normal );
|
||||
|
|
|
@ -14,6 +14,7 @@ SimpleRigidBody::SimpleRigidBody()
|
|||
this->gravityNormal = Float3::null;
|
||||
this->collisionAction = Default::EventAction_Collision;
|
||||
this->ignoreGravity = false;
|
||||
this->scene = nullptr;
|
||||
}
|
||||
|
||||
SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc )
|
||||
|
@ -33,6 +34,7 @@ SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc )
|
|||
}
|
||||
|
||||
this->ignoreGravity = desc.ignoreGravity;
|
||||
this->scene = nullptr;
|
||||
}
|
||||
|
||||
SimpleRigidBody::~SimpleRigidBody() {}
|
||||
|
@ -61,10 +63,31 @@ SimpleRigidBody::State & SimpleRigidBody::GetState( SimpleRigidBody::State &targ
|
|||
}
|
||||
|
||||
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.center = state.GetCenterPosition();
|
||||
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 )
|
||||
|
@ -187,6 +210,11 @@ UpdateState SimpleRigidBody::Update( Float timeStepLength )
|
|||
return UpdateState_altered;
|
||||
}
|
||||
|
||||
void SimpleRigidBody::SetScene( void *scene )
|
||||
{
|
||||
this->scene = (Octree*)scene;
|
||||
}
|
||||
|
||||
void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_Collision functionPointer )
|
||||
{
|
||||
if( functionPointer )
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "..\PhysicsAPI.h"
|
||||
#include "RigidBody.h"
|
||||
#include "Octree.h"
|
||||
|
||||
namespace Oyster { namespace Physics
|
||||
{
|
||||
|
@ -36,6 +37,7 @@ namespace Oyster { namespace Physics
|
|||
|
||||
UpdateState Update( ::Oyster::Math::Float timeStepLength );
|
||||
|
||||
void SetScene( void *scene );
|
||||
void SetSubscription( EventAction_Collision functionPointer );
|
||||
void SetGravity( bool ignore);
|
||||
void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector );
|
||||
|
@ -53,6 +55,7 @@ namespace Oyster { namespace Physics
|
|||
::Oyster::Physics3D::RigidBody rigid;
|
||||
::Oyster::Math::Float3 gravityNormal;
|
||||
EventAction_Collision collisionAction;
|
||||
Octree *scene;
|
||||
bool ignoreGravity;
|
||||
};
|
||||
} }
|
||||
|
|
|
@ -14,6 +14,7 @@ SphericalRigidBody::SphericalRigidBody()
|
|||
this->gravityNormal = Float3::null;
|
||||
this->collisionAction = Default::EventAction_Collision;
|
||||
this->ignoreGravity = false;
|
||||
this->scene = nullptr;
|
||||
this->body = Sphere( Float3::null, 0.5f );
|
||||
}
|
||||
|
||||
|
@ -34,6 +35,7 @@ SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &des
|
|||
}
|
||||
|
||||
this->ignoreGravity = desc.ignoreGravity;
|
||||
this->scene = nullptr;
|
||||
this->body = Sphere( desc.centerPosition, desc.radius );
|
||||
}
|
||||
|
||||
|
@ -63,10 +65,31 @@ SphericalRigidBody::State & SphericalRigidBody::GetState( SphericalRigidBody::St
|
|||
}
|
||||
|
||||
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.center = state.GetCenterPosition();
|
||||
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 )
|
||||
|
@ -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->gravityNormal = Float3::null;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "..\PhysicsAPI.h"
|
||||
#include "RigidBody.h"
|
||||
#include "Sphere.h"
|
||||
#include "Octree.h"
|
||||
|
||||
namespace Oyster { namespace Physics
|
||||
{
|
||||
|
@ -37,6 +38,7 @@ namespace Oyster { namespace Physics
|
|||
|
||||
UpdateState Update( ::Oyster::Math::Float timeStepLength );
|
||||
|
||||
void SetScene( void *scene );
|
||||
void SetSubscription( EventAction_Collision functionPointer );
|
||||
void SetGravity( bool ignore);
|
||||
void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector );
|
||||
|
@ -55,6 +57,7 @@ namespace Oyster { namespace Physics
|
|||
::Oyster::Math::Float3 gravityNormal;
|
||||
EventAction_Collision collisionAction;
|
||||
bool ignoreGravity;
|
||||
Octree *scene;
|
||||
::Oyster::Collision3D::Sphere body;
|
||||
};
|
||||
} }
|
||||
|
|
|
@ -338,6 +338,13 @@ namespace Oyster
|
|||
********************************************************/
|
||||
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
|
||||
* whenever a collision occurs.
|
||||
|
|
Loading…
Reference in New Issue