Added visit function to API

Called with collideable and hit action
This commit is contained in:
Robin Engman 2014-01-21 14:10:31 +01:00
parent 94f1c20817
commit 090d44b518
5 changed files with 18 additions and 7 deletions

View File

@ -108,7 +108,7 @@ std::vector<ICustomBody*>& 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; i<this->leafData.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);
}
}
}

View File

@ -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<ICustomBody*>& Sample(ICustomBody* customBodyRef, std::vector<ICustomBody*>& updateList);
std::vector<ICustomBody*>& Sample(const Oyster::Collision3D::ICollideable& collideable, std::vector<ICustomBody*>& 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);

View File

@ -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 );

View File

@ -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 );

View File

@ -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.