From 090d44b518aca8580f2081094889a09f305fa109 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Tue, 21 Jan 2014 14:10:31 +0100 Subject: [PATCH] Added visit function to API Called with collideable and hit action --- Code/GamePhysics/Implementation/Octree.cpp | 8 ++++---- Code/GamePhysics/Implementation/Octree.h | 7 ++++--- Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp | 5 +++++ Code/GamePhysics/Implementation/PhysicsAPI_Impl.h | 2 ++ Code/GamePhysics/PhysicsAPI.h | 3 +++ 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Code/GamePhysics/Implementation/Octree.cpp b/Code/GamePhysics/Implementation/Octree.cpp index a1ccdbd8..60f05298 100644 --- a/Code/GamePhysics/Implementation/Octree.cpp +++ b/Code/GamePhysics/Implementation/Octree.cpp @@ -108,7 +108,7 @@ std::vector& Octree::Sample(const Oyster::Collision3D::ICollideabl return updateList; } -void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction ) +void Octree::Visit(ICustomBody* customBodyRef, VisitorAction hitAction ) { auto object = this->mapReferences.find(customBodyRef); @@ -128,13 +128,13 @@ void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction ) } } -void Octree::Visit(const Oyster::Collision3D::ICollideable& collideable, VistorAction hitAction) +void Octree::Visit(const Oyster::Collision3D::ICollideable& collideable, VisitorActionCollideable hitAction) { for(unsigned int i = 0; ileafData.size(); i++) { - if(this->leafData[i].container.Intersects(collideable)) + if(collideable.Intersects(this->leafData[i].container)) { - //hitAction(*this, tempRef, i); // @todo TODO: Add typedef to handle function calls with ICollideable + hitAction(*this, i); } } } diff --git a/Code/GamePhysics/Implementation/Octree.h b/Code/GamePhysics/Implementation/Octree.h index 96631605..6c6606a9 100644 --- a/Code/GamePhysics/Implementation/Octree.h +++ b/Code/GamePhysics/Implementation/Octree.h @@ -17,7 +17,8 @@ namespace Oyster public: static const unsigned int invalid_ref; - typedef void(*VistorAction)(Octree&, unsigned int, unsigned int); + typedef void(*VisitorAction)(Octree&, unsigned int, unsigned int); + typedef void(*VisitorActionCollideable)(Octree&, unsigned int); struct Data { @@ -51,8 +52,8 @@ namespace Oyster std::vector& Sample(ICustomBody* customBodyRef, std::vector& updateList); std::vector& Sample(const Oyster::Collision3D::ICollideable& collideable, std::vector& updateList); - void Visit(ICustomBody* customBodyRef, VistorAction hitAction ); - void Visit(const Oyster::Collision3D::ICollideable& collideable, VistorAction hitAction ); + void Visit(ICustomBody* customBodyRef, VisitorAction hitAction ); + void Visit(const Oyster::Collision3D::ICollideable& collideable, VisitorActionCollideable hitAction ); ICustomBody* GetCustomBody(const unsigned int tempRef); diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 7bec7852..2899eae6 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -268,6 +268,11 @@ void API_Impl::RemoveGravity( const API::Gravity &g ) } } +void API_Impl::ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void(hitAction)(Octree&, unsigned int) ) +{ + this->worldScene.Visit(collideable, hitAction); +} + //void API_Impl::ApplyForceAt( const ICustomBody* objRef, const Float3 &worldPos, const Float3 &worldF ) //{ // unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef ); diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h index 8b38004c..ad2c91a4 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h @@ -35,6 +35,8 @@ namespace Oyster void AddGravity( const API::Gravity &g ); void RemoveGravity( const API::Gravity &g ); + void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void(hitAction)(Octree&, unsigned int) ); + //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 ); diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 4fcd2940..3e213dc4 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -16,6 +16,7 @@ namespace Oyster { class API; class ICustomBody; + class Octree; namespace Struct { @@ -136,6 +137,8 @@ namespace Oyster ********************************************************/ virtual void RemoveGravity( const API::Gravity &g ) = 0; + virtual void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void(hitAction)(Octree&, unsigned int) ) = 0; + ///******************************************************** // * Apply force on an object. // * @param objRef: A pointer to the ICustomBody representing a physical object.