From e5009123ce05666adecf3c1cd118445ed9604736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 28 Jun 2014 00:40:44 -0300 Subject: [PATCH] Physics Module refactored. --- include/eepp/physics.hpp | 42 +-- .../physics/{carbiter.hpp => arbiter.hpp} | 14 +- include/eepp/physics/{cbody.hpp => body.hpp} | 66 ++-- .../{cconstraint.hpp => constraint.hpp} | 18 +- ...otaryspring.hpp => dampedrotaryspring.hpp} | 6 +- .../{cdampedspring.hpp => dampedspring.hpp} | 6 +- .../{cgearjoint.hpp => gearjoint.hpp} | 6 +- .../{cgroovejoint.hpp => groovejoint.hpp} | 6 +- .../{cpinjoint.hpp => pinjoint.hpp} | 6 +- .../{cpivotjoint.hpp => pivotjoint.hpp} | 8 +- .../{cratchetjoint.hpp => ratchetjoint.hpp} | 6 +- ...arylimitjoint.hpp => rotarylimitjoint.hpp} | 6 +- .../{csimplemotor.hpp => simplemotor.hpp} | 6 +- .../{cslidejoint.hpp => slidejoint.hpp} | 6 +- include/eepp/physics/cshapepoly.hpp | 37 --- include/eepp/physics/cshapepolysprite.hpp | 42 --- ...cphysicsmanager.hpp => physicsmanager.hpp} | 52 +-- .../eepp/physics/{cshape.hpp => shape.hpp} | 34 +- .../{cshapecircle.hpp => shapecircle.hpp} | 10 +- ...circlesprite.hpp => shapecirclesprite.hpp} | 12 +- .../{cshapepoint.hpp => shapepoint.hpp} | 10 +- include/eepp/physics/shapepoly.hpp | 37 +++ include/eepp/physics/shapepolysprite.hpp | 42 +++ .../{cshapesegment.hpp => shapesegment.hpp} | 10 +- .../eepp/physics/{cspace.hpp => space.hpp} | 134 ++++---- projects/linux/ee.creator.user | 2 +- projects/linux/ee.files | 88 ++--- .../physics/{carbiter.cpp => arbiter.cpp} | 54 ++-- src/eepp/physics/body.cpp | 300 ++++++++++++++++++ src/eepp/physics/cbody.cpp | 300 ------------------ src/eepp/physics/constraints/cconstraint.cpp | 85 ----- .../constraints/cdampedrotaryspring.cpp | 38 --- src/eepp/physics/constraints/cgearjoint.cpp | 30 -- src/eepp/physics/constraints/constraint.cpp | 85 +++++ .../physics/constraints/cratchetjoint.cpp | 38 --- .../physics/constraints/crotarylimitjoint.cpp | 30 -- src/eepp/physics/constraints/csimplemotor.cpp | 22 -- .../constraints/dampedrotaryspring.cpp | 38 +++ .../{cdampedspring.cpp => dampedspring.cpp} | 32 +- src/eepp/physics/constraints/gearjoint.cpp | 30 ++ .../{cgroovejoint.cpp => groovejoint.cpp} | 24 +- .../{cpinjoint.cpp => pinjoint.cpp} | 24 +- .../{cpivotjoint.cpp => pivotjoint.cpp} | 24 +- src/eepp/physics/constraints/ratchetjoint.cpp | 38 +++ .../physics/constraints/rotarylimitjoint.cpp | 30 ++ src/eepp/physics/constraints/simplemotor.cpp | 22 ++ .../{cslidejoint.cpp => slidejoint.cpp} | 28 +- src/eepp/physics/cshape.cpp | 195 ------------ src/eepp/physics/cshapecirclesprite.cpp | 55 ---- ...cphysicsmanager.cpp => physicsmanager.cpp} | 46 +-- src/eepp/physics/shape.cpp | 195 ++++++++++++ .../{cshapecircle.cpp => shapecircle.cpp} | 24 +- src/eepp/physics/shapecirclesprite.cpp | 55 ++++ .../{cshapepoint.cpp => shapepoint.cpp} | 28 +- .../physics/{cshapepoly.cpp => shapepoly.cpp} | 42 +-- ...hapepolysprite.cpp => shapepolysprite.cpp} | 26 +- .../{cshapesegment.cpp => shapesegment.cpp} | 34 +- src/eepp/physics/{cspace.cpp => space.cpp} | 266 ++++++++-------- src/eepp/window/engine.cpp | 4 +- src/examples/physics/physics.cpp | 136 ++++---- src/test/eetest.cpp | 82 ++--- src/test/eetest.hpp | 18 +- 62 files changed, 1595 insertions(+), 1595 deletions(-) rename include/eepp/physics/{carbiter.hpp => arbiter.hpp} (75%) rename include/eepp/physics/{cbody.hpp => body.hpp} (61%) rename include/eepp/physics/constraints/{cconstraint.hpp => constraint.hpp} (67%) rename include/eepp/physics/constraints/{cdampedrotaryspring.hpp => dampedrotaryspring.hpp} (64%) rename include/eepp/physics/constraints/{cdampedspring.hpp => dampedspring.hpp} (73%) rename include/eepp/physics/constraints/{cgearjoint.hpp => gearjoint.hpp} (61%) rename include/eepp/physics/constraints/{cgroovejoint.hpp => groovejoint.hpp} (72%) rename include/eepp/physics/constraints/{cpinjoint.hpp => pinjoint.hpp} (74%) rename include/eepp/physics/constraints/{cpivotjoint.hpp => pivotjoint.hpp} (66%) rename include/eepp/physics/constraints/{cratchetjoint.hpp => ratchetjoint.hpp} (66%) rename include/eepp/physics/constraints/{crotarylimitjoint.hpp => rotarylimitjoint.hpp} (60%) rename include/eepp/physics/constraints/{csimplemotor.hpp => simplemotor.hpp} (57%) rename include/eepp/physics/constraints/{cslidejoint.hpp => slidejoint.hpp} (73%) delete mode 100644 include/eepp/physics/cshapepoly.hpp delete mode 100644 include/eepp/physics/cshapepolysprite.hpp rename include/eepp/physics/{cphysicsmanager.hpp => physicsmanager.hpp} (54%) rename include/eepp/physics/{cshape.hpp => shape.hpp} (69%) rename include/eepp/physics/{cshapecircle.hpp => shapecircle.hpp} (50%) rename include/eepp/physics/{cshapecirclesprite.hpp => shapecirclesprite.hpp} (51%) rename include/eepp/physics/{cshapepoint.hpp => shapepoint.hpp} (61%) create mode 100644 include/eepp/physics/shapepoly.hpp create mode 100644 include/eepp/physics/shapepolysprite.hpp rename include/eepp/physics/{cshapesegment.hpp => shapesegment.hpp} (67%) rename include/eepp/physics/{cspace.hpp => space.hpp} (50%) rename src/eepp/physics/{carbiter.cpp => arbiter.cpp} (53%) create mode 100644 src/eepp/physics/body.cpp delete mode 100644 src/eepp/physics/cbody.cpp delete mode 100644 src/eepp/physics/constraints/cconstraint.cpp delete mode 100644 src/eepp/physics/constraints/cdampedrotaryspring.cpp delete mode 100644 src/eepp/physics/constraints/cgearjoint.cpp create mode 100644 src/eepp/physics/constraints/constraint.cpp delete mode 100644 src/eepp/physics/constraints/cratchetjoint.cpp delete mode 100644 src/eepp/physics/constraints/crotarylimitjoint.cpp delete mode 100644 src/eepp/physics/constraints/csimplemotor.cpp create mode 100644 src/eepp/physics/constraints/dampedrotaryspring.cpp rename src/eepp/physics/constraints/{cdampedspring.cpp => dampedspring.cpp} (75%) create mode 100644 src/eepp/physics/constraints/gearjoint.cpp rename src/eepp/physics/constraints/{cgroovejoint.cpp => groovejoint.cpp} (70%) rename src/eepp/physics/constraints/{cpinjoint.cpp => pinjoint.cpp} (72%) rename src/eepp/physics/constraints/{cpivotjoint.cpp => pivotjoint.cpp} (67%) create mode 100644 src/eepp/physics/constraints/ratchetjoint.cpp create mode 100644 src/eepp/physics/constraints/rotarylimitjoint.cpp create mode 100644 src/eepp/physics/constraints/simplemotor.cpp rename src/eepp/physics/constraints/{cslidejoint.cpp => slidejoint.cpp} (68%) delete mode 100644 src/eepp/physics/cshape.cpp delete mode 100644 src/eepp/physics/cshapecirclesprite.cpp rename src/eepp/physics/{cphysicsmanager.cpp => physicsmanager.cpp} (53%) create mode 100644 src/eepp/physics/shape.cpp rename src/eepp/physics/{cshapecircle.cpp => shapecircle.cpp} (52%) create mode 100644 src/eepp/physics/shapecirclesprite.cpp rename src/eepp/physics/{cshapepoint.cpp => shapepoint.cpp} (56%) rename src/eepp/physics/{cshapepoly.cpp => shapepoly.cpp} (60%) rename src/eepp/physics/{cshapepolysprite.cpp => shapepolysprite.cpp} (51%) rename src/eepp/physics/{cshapesegment.cpp => shapesegment.cpp} (77%) rename src/eepp/physics/{cspace.cpp => space.cpp} (59%) diff --git a/include/eepp/physics.hpp b/include/eepp/physics.hpp index 3e538a6a6..a9fb1dfe1 100644 --- a/include/eepp/physics.hpp +++ b/include/eepp/physics.hpp @@ -1,28 +1,28 @@ #ifndef EEPP_PHYSICS_HPP #define EEPP_PHYSICS_HPP -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include +#include +#include #endif diff --git a/include/eepp/physics/carbiter.hpp b/include/eepp/physics/arbiter.hpp similarity index 75% rename from include/eepp/physics/carbiter.hpp rename to include/eepp/physics/arbiter.hpp index af9ed4cc5..e496c30aa 100644 --- a/include/eepp/physics/carbiter.hpp +++ b/include/eepp/physics/arbiter.hpp @@ -2,14 +2,14 @@ #define EE_PHYSICS_CARBITER_HPP #include -#include -#include +#include +#include CP_NAMESPACE_BEGIN -class CP_API cArbiter { +class CP_API Arbiter { public: - cArbiter( cpArbiter * arbiter ); + Arbiter( cpArbiter * arbiter ); cVect TotalImpulse(); @@ -17,9 +17,9 @@ class CP_API cArbiter { void Ignore(); - void GetShapes( cShape ** a, cShape ** b ); + void GetShapes( Shape ** a, Shape ** b ); - void GetBodies( cBody ** a, cBody ** b); + void GetBodies( Body ** a, Body ** b); bool IsFirstContact(); @@ -35,7 +35,7 @@ class CP_API cArbiter { void ContactPointSet( cpContactPointSet * contact ); - cpArbiter * Arbiter() const; + cpArbiter * GetArbiter() const; cpFloat Elasticity(); diff --git a/include/eepp/physics/cbody.hpp b/include/eepp/physics/body.hpp similarity index 61% rename from include/eepp/physics/cbody.hpp rename to include/eepp/physics/body.hpp index ea88facc9..94079131a 100644 --- a/include/eepp/physics/cbody.hpp +++ b/include/eepp/physics/body.hpp @@ -5,80 +5,80 @@ CP_NAMESPACE_BEGIN -class cShape; -class cConstraint; -class cArbiter; +class Shape; +class Constraint; +class Arbiter; -class CP_API cBody { +class CP_API Body { public: - typedef cb::Callback3 ShapeIteratorFunc; - typedef cb::Callback3 ConstraintIteratorFunc; - typedef cb::Callback3 ArbiterIteratorFunc; - typedef cb::Callback4 BodyVelocityFunc; - typedef cb::Callback2 BodyPositionFunc; + typedef cb::Callback3 ShapeIteratorFunc; + typedef cb::Callback3 ConstraintIteratorFunc; + typedef cb::Callback3 ArbiterIteratorFunc; + typedef cb::Callback4 BodyVelocityFunc; + typedef cb::Callback2 BodyPositionFunc; - class cShapeIterator { + class ShapeIterator { public: - cShapeIterator( cBody * body, void * data, ShapeIteratorFunc func ) : + ShapeIterator( Physics::Body * body, void * data, ShapeIteratorFunc func ) : Body( body ), Data( data ), Func( func ) {} - cBody * Body; + Physics::Body * Body; void * Data; ShapeIteratorFunc Func; }; - class cConstraintIterator { + class ConstraintIterator { public: - cConstraintIterator( cBody * body, void * data, ConstraintIteratorFunc func ) : + ConstraintIterator( Physics::Body * body, void * data, ConstraintIteratorFunc func ) : Body( body ), Data( data ), Func( func ) {} - cBody * Body; + Physics::Body * Body; void * Data; ConstraintIteratorFunc Func; }; - class cArbiterIterator { + class ArbiterIterator { public: - cArbiterIterator( cBody * body, void * data, ArbiterIteratorFunc func ) : + ArbiterIterator( Physics::Body * body, void * data, ArbiterIteratorFunc func ) : Body( body ), Data( data ), Func( func ) {} - cBody * Body; + Physics::Body * Body; void * Data; ArbiterIteratorFunc Func; }; - static cBody * New( cpFloat m, cpFloat i ); + static Body * New( cpFloat m, cpFloat i ); - static cBody * New( cpBody * body ); + static Body * New( cpBody * body ); - static cBody * New(); + static Body * New(); - static void Free( cBody * body ); + static void Free( Body * body ); - cBody( cpBody * body ); + Body( cpBody * body ); - cBody( cpFloat m, cpFloat i ); + Body( cpFloat m, cpFloat i ); - cBody(); + Body(); - virtual ~cBody(); + virtual ~Body(); void Activate(); - void ActivateStatic( cBody *body, cShape * filter ); + void ActivateStatic( Body *body, Shape * filter ); void Sleep(); - void SleepWithGroup( cBody * Group ); + void SleepWithGroup( Body * Group ); bool IsSleeping(); @@ -86,7 +86,7 @@ class CP_API cBody { bool IsRogue(); - cpBody * Body() const; + cpBody * GetBody() const; cpFloat Mass() const; @@ -156,21 +156,21 @@ class CP_API cBody { void EachShape( ShapeIteratorFunc Func, void * data ); - virtual void OnEachShape( cShape * Shape, cShapeIterator * it ); + virtual void OnEachShape( Shape * Shape, ShapeIterator * it ); void EachConstraint( ConstraintIteratorFunc Func, void * data ); - virtual void OnEachConstraint( cConstraint * Constraint, cConstraintIterator * it ); + virtual void OnEachConstraint( Constraint * Constraint, ConstraintIterator * it ); void EachArbiter( ArbiterIteratorFunc Func, void * data ); - virtual void OnEachArbiter( cArbiter * Arbiter, cArbiterIterator * it ); + virtual void OnEachArbiter( Arbiter * Arbiter, ArbiterIterator * it ); void VelocityFunc( BodyVelocityFunc func ); void PositionFunc( BodyPositionFunc func ); protected: - friend class cSpace; + friend class Space; static void BodyVelocityFuncWrapper( cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt ); diff --git a/include/eepp/physics/constraints/cconstraint.hpp b/include/eepp/physics/constraints/constraint.hpp similarity index 67% rename from include/eepp/physics/constraints/cconstraint.hpp rename to include/eepp/physics/constraints/constraint.hpp index 79fe7ee42..dff7b2f7e 100644 --- a/include/eepp/physics/constraints/cconstraint.hpp +++ b/include/eepp/physics/constraints/constraint.hpp @@ -2,23 +2,23 @@ #define EE_PHYSICS_CCONSTRAINT_HPP #include -#include +#include CP_NAMESPACE_BEGIN -class CP_API cConstraint { +class CP_API Constraint { public: - static void Free( cConstraint * constraint ); + static void Free( Constraint * constraint ); - cConstraint( cpConstraint * Constraint ); + Constraint( cpConstraint * Constraint ); - virtual ~cConstraint(); + virtual ~Constraint(); - cpConstraint * Constraint() const; + cpConstraint * GetConstraint() const; - cBody * A(); + Body * A(); - cBody * B(); + Body * B(); cpFloat MaxForce(); @@ -44,7 +44,7 @@ class CP_API cConstraint { void * mData; - cConstraint(); + Constraint(); void SetData(); }; diff --git a/include/eepp/physics/constraints/cdampedrotaryspring.hpp b/include/eepp/physics/constraints/dampedrotaryspring.hpp similarity index 64% rename from include/eepp/physics/constraints/cdampedrotaryspring.hpp rename to include/eepp/physics/constraints/dampedrotaryspring.hpp index b49f4c466..6f6818c78 100644 --- a/include/eepp/physics/constraints/cdampedrotaryspring.hpp +++ b/include/eepp/physics/constraints/dampedrotaryspring.hpp @@ -1,13 +1,13 @@ #ifndef EE_PHYSICS_CDAMPEDROTARYSPRING_HPP #define EE_PHYSICS_CDAMPEDROTARYSPRING_HPP -#include +#include CP_NAMESPACE_BEGIN -class CP_API cDampedRotarySpring : public cConstraint { +class CP_API DampedRotarySpring : public Constraint { public: - cDampedRotarySpring( cBody * a, cBody * b, cpFloat restAngle, cpFloat stiffness, cpFloat damping ); + DampedRotarySpring( Body * a, Body * b, cpFloat restAngle, cpFloat stiffness, cpFloat damping ); cpFloat RestAngle(); diff --git a/include/eepp/physics/constraints/cdampedspring.hpp b/include/eepp/physics/constraints/dampedspring.hpp similarity index 73% rename from include/eepp/physics/constraints/cdampedspring.hpp rename to include/eepp/physics/constraints/dampedspring.hpp index 7976d330a..d054c80fd 100644 --- a/include/eepp/physics/constraints/cdampedspring.hpp +++ b/include/eepp/physics/constraints/dampedspring.hpp @@ -1,13 +1,13 @@ #ifndef EE_PHYSICS_CDAMPEDSPRING_HPP #define EE_PHYSICS_CDAMPEDSPRING_HPP -#include +#include CP_NAMESPACE_BEGIN -class CP_API cDampedSpring : public cConstraint { +class CP_API DampedSpring : public Constraint { public: - cDampedSpring( cBody * a, cBody * b, cVect anchr1, cVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping ); + DampedSpring( Body * a, Body * b, cVect anchr1, cVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping ); cVect Anchr1(); diff --git a/include/eepp/physics/constraints/cgearjoint.hpp b/include/eepp/physics/constraints/gearjoint.hpp similarity index 61% rename from include/eepp/physics/constraints/cgearjoint.hpp rename to include/eepp/physics/constraints/gearjoint.hpp index 336314fd8..d57369261 100644 --- a/include/eepp/physics/constraints/cgearjoint.hpp +++ b/include/eepp/physics/constraints/gearjoint.hpp @@ -1,13 +1,13 @@ #ifndef EE_PHYSICS_CGEARJOINT_HPP #define EE_PHYSICS_CGEARJOINT_HPP -#include +#include CP_NAMESPACE_BEGIN -class CP_API cGearJoint : public cConstraint { +class CP_API GearJoint : public Constraint { public: - cGearJoint( cBody * a, cBody * b, cpFloat phase, cpFloat ratio ); + GearJoint( Body * a, Body * b, cpFloat phase, cpFloat ratio ); cpFloat Phase(); diff --git a/include/eepp/physics/constraints/cgroovejoint.hpp b/include/eepp/physics/constraints/groovejoint.hpp similarity index 72% rename from include/eepp/physics/constraints/cgroovejoint.hpp rename to include/eepp/physics/constraints/groovejoint.hpp index fe60f2a08..f06740d3f 100644 --- a/include/eepp/physics/constraints/cgroovejoint.hpp +++ b/include/eepp/physics/constraints/groovejoint.hpp @@ -1,13 +1,13 @@ #ifndef EE_PHYSICS_CGROOVEJOINT_HPP #define EE_PHYSICS_CGROOVEJOINT_HPP -#include +#include CP_NAMESPACE_BEGIN -class CP_API cGrooveJoint : public cConstraint { +class CP_API GrooveJoint : public Constraint { public: - cGrooveJoint( cBody * a, cBody * b, cVect groove_a, cVect groove_b, cVect anchr2 ); + GrooveJoint( Body * a, Body * b, cVect groove_a, cVect groove_b, cVect anchr2 ); cVect Anchr2(); diff --git a/include/eepp/physics/constraints/cpinjoint.hpp b/include/eepp/physics/constraints/pinjoint.hpp similarity index 74% rename from include/eepp/physics/constraints/cpinjoint.hpp rename to include/eepp/physics/constraints/pinjoint.hpp index cb9e4bd2d..231aaf463 100644 --- a/include/eepp/physics/constraints/cpinjoint.hpp +++ b/include/eepp/physics/constraints/pinjoint.hpp @@ -1,13 +1,13 @@ #ifndef EE_PHYSICS_CPINJOINT_HPP #define EE_PHYSICS_CPINJOINT_HPP -#include +#include CP_NAMESPACE_BEGIN -class CP_API cPinJoint : public cConstraint { +class CP_API PinJoint : public Constraint { public: - cPinJoint( cBody * a, cBody * b, cVect anchr1, cVect anchr2 ); + PinJoint( Body * a, Body * b, cVect anchr1, cVect anchr2 ); cVect Anchr1(); diff --git a/include/eepp/physics/constraints/cpivotjoint.hpp b/include/eepp/physics/constraints/pivotjoint.hpp similarity index 66% rename from include/eepp/physics/constraints/cpivotjoint.hpp rename to include/eepp/physics/constraints/pivotjoint.hpp index cbc725977..3343a0d21 100644 --- a/include/eepp/physics/constraints/cpivotjoint.hpp +++ b/include/eepp/physics/constraints/pivotjoint.hpp @@ -1,15 +1,15 @@ #ifndef EE_PHYSICS_CPIVOTJOINT_HPP #define EE_PHYSICS_CPIVOTJOINT_HPP -#include +#include CP_NAMESPACE_BEGIN -class CP_API cPivotJoint : public cConstraint { +class CP_API PivotJoint : public Constraint { public: - cPivotJoint( cBody * a, cBody * b, cVect pivot ); + PivotJoint( Body * a, Body * b, cVect pivot ); - cPivotJoint( cBody * a, cBody * b, cVect anchr1, cVect anchr2 ); + PivotJoint( Body * a, Body * b, cVect anchr1, cVect anchr2 ); cVect Anchr1(); diff --git a/include/eepp/physics/constraints/cratchetjoint.hpp b/include/eepp/physics/constraints/ratchetjoint.hpp similarity index 66% rename from include/eepp/physics/constraints/cratchetjoint.hpp rename to include/eepp/physics/constraints/ratchetjoint.hpp index d730873e1..ae1290e6f 100644 --- a/include/eepp/physics/constraints/cratchetjoint.hpp +++ b/include/eepp/physics/constraints/ratchetjoint.hpp @@ -1,13 +1,13 @@ #ifndef EE_PHYSICS_CRATCHETJOINT_HPP #define EE_PHYSICS_CRATCHETJOINT_HPP -#include +#include CP_NAMESPACE_BEGIN -class CP_API cRatchetJoint : public cConstraint { +class CP_API RatchetJoint : public Constraint { public: - cRatchetJoint( cBody * a, cBody * b, cpFloat phase, cpFloat ratchet ); + RatchetJoint( Body * a, Body * b, cpFloat phase, cpFloat ratchet ); cpFloat Angle(); diff --git a/include/eepp/physics/constraints/crotarylimitjoint.hpp b/include/eepp/physics/constraints/rotarylimitjoint.hpp similarity index 60% rename from include/eepp/physics/constraints/crotarylimitjoint.hpp rename to include/eepp/physics/constraints/rotarylimitjoint.hpp index c34305522..5c28b1b12 100644 --- a/include/eepp/physics/constraints/crotarylimitjoint.hpp +++ b/include/eepp/physics/constraints/rotarylimitjoint.hpp @@ -1,13 +1,13 @@ #ifndef EE_PHYSICS_CROTARYLIMITJOINT_HPP #define EE_PHYSICS_CROTARYLIMITJOINT_HPP -#include +#include CP_NAMESPACE_BEGIN -class CP_API cRotaryLimitJoint : public cConstraint { +class CP_API RotaryLimitJoint : public Constraint { public: - cRotaryLimitJoint( cBody * a, cBody * b, cpFloat min, cpFloat max ); + RotaryLimitJoint( Body * a, Body * b, cpFloat min, cpFloat max ); cpFloat Min(); diff --git a/include/eepp/physics/constraints/csimplemotor.hpp b/include/eepp/physics/constraints/simplemotor.hpp similarity index 57% rename from include/eepp/physics/constraints/csimplemotor.hpp rename to include/eepp/physics/constraints/simplemotor.hpp index 9d67bc265..5cdce1854 100644 --- a/include/eepp/physics/constraints/csimplemotor.hpp +++ b/include/eepp/physics/constraints/simplemotor.hpp @@ -1,13 +1,13 @@ #ifndef EE_PHYSICS_CSIMPLEMOTOR_HPP #define EE_PHYSICS_CSIMPLEMOTOR_HPP -#include +#include CP_NAMESPACE_BEGIN -class CP_API cSimpleMotor : public cConstraint { +class CP_API SimpleMotor : public Constraint { public: - cSimpleMotor( cBody * a, cBody * b, cpFloat rate ); + SimpleMotor( Body * a, Body * b, cpFloat rate ); cpFloat Rate(); diff --git a/include/eepp/physics/constraints/cslidejoint.hpp b/include/eepp/physics/constraints/slidejoint.hpp similarity index 73% rename from include/eepp/physics/constraints/cslidejoint.hpp rename to include/eepp/physics/constraints/slidejoint.hpp index a6fc6ef8c..32363b10a 100644 --- a/include/eepp/physics/constraints/cslidejoint.hpp +++ b/include/eepp/physics/constraints/slidejoint.hpp @@ -1,13 +1,13 @@ #ifndef EE_PHYSICS_CSLIDEJOINT_HPP #define EE_PHYSICS_CSLIDEJOINT_HPP -#include +#include CP_NAMESPACE_BEGIN -class CP_API cSlideJoint : public cConstraint { +class CP_API SlideJoint : public Constraint { public: - cSlideJoint( cBody * a, cBody *b, cVect anchr1, cVect anchr2, cpFloat min, cpFloat max ); + SlideJoint( Body * a, Body *b, cVect anchr1, cVect anchr2, cpFloat min, cpFloat max ); cVect Anchr1(); diff --git a/include/eepp/physics/cshapepoly.hpp b/include/eepp/physics/cshapepoly.hpp deleted file mode 100644 index 21defa495..000000000 --- a/include/eepp/physics/cshapepoly.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef EE_PHYSICS_CSHAPEPOLY_HPP -#define EE_PHYSICS_CSHAPEPOLY_HPP - -#include - -CP_NAMESPACE_BEGIN - -class CP_API cShapePoly : public cShape { - public: - static cShapePoly * New( cBody * body, int numVerts, cVect *verts, cVect offset ); - - static cShapePoly * New( cBody * body, cpFloat width, cpFloat height ); - - cShapePoly( cBody * body, int numVerts, cVect *verts, cVect offset ); - - cShapePoly( cBody * body, cpFloat width, cpFloat height ); - - static bool Validate( const cVect * verts, const int numVerts ); - - int GetNumVerts(); - - cVect GetVert( int idx ); - - void SetVerts( int numVerts, cVect *verts, cVect offset ); - - virtual void Draw( cSpace * space ); - - virtual void DrawBorder( cSpace * space ); - - static void Recenter( int numVerts, cVect * verts ); - - static cVect Centroid( int numVerts, const cVect * verts ); -}; - -CP_NAMESPACE_END - -#endif diff --git a/include/eepp/physics/cshapepolysprite.hpp b/include/eepp/physics/cshapepolysprite.hpp deleted file mode 100644 index cd1899fb7..000000000 --- a/include/eepp/physics/cshapepolysprite.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef EE_PHYSICS_CSHAPEPOLYSPRITE_HPP -#define EE_PHYSICS_CSHAPEPOLYSPRITE_HPP - -#include - -#ifdef PHYSICS_RENDERER_ENABLED - -namespace EE { namespace Graphics { -class Sprite; -}} -using namespace EE::Graphics; - -CP_NAMESPACE_BEGIN - -class CP_API cShapePolySprite : public cShapePoly { - public: - static cShapePolySprite * New( cBody * body, int numVerts, cVect *verts, cVect offset, Sprite * Sprite, bool AutoDeleteSprite = false ); - - static cShapePolySprite * New( cBody * body, cpFloat width, cpFloat height, Sprite * Sprite, bool AutoDeleteSprite = false ); - - cShapePolySprite( cBody * body, int numVerts, cVect *verts, cVect offset, Sprite * Sprite, bool AutoDeleteSprite = false ); - - cShapePolySprite( cBody * body, cpFloat width, cpFloat height, Sprite * Sprite, bool AutoDeleteSprite = false ); - - virtual ~cShapePolySprite(); - - virtual void Draw( cSpace * space ); - - Sprite * GetSprite() const; - protected: - Sprite * mSprite; - bool mSpriteAutoDelete; - Vector2i mOffset; - - void OffsetSet( cVect center ); -}; - -CP_NAMESPACE_END - -#endif - -#endif diff --git a/include/eepp/physics/cphysicsmanager.hpp b/include/eepp/physics/physicsmanager.hpp similarity index 54% rename from include/eepp/physics/cphysicsmanager.hpp rename to include/eepp/physics/physicsmanager.hpp index 6ca5304a0..c586f5e73 100644 --- a/include/eepp/physics/cphysicsmanager.hpp +++ b/include/eepp/physics/physicsmanager.hpp @@ -5,13 +5,13 @@ CP_NAMESPACE_BEGIN -class cBody; -class cShape; -class cConstraint; -class cSpace; +class Body; +class Shape; +class Constraint; +class Space; -class CP_API cPhysicsManager { - SINGLETON_DECLARE_HEADERS(cPhysicsManager) +class CP_API PhysicsManager { + SINGLETON_DECLARE_HEADERS(PhysicsManager) public: class cDrawSpaceOptions { @@ -37,9 +37,9 @@ class CP_API cPhysicsManager { cpFloat LineThickness; }; - ~cPhysicsManager(); + ~PhysicsManager(); - /** The Memory Manager will keep track of all the allocations from cSpace, cBody, cShape and cConstraint and will release any non-released pointer. + /** The Memory Manager will keep track of all the allocations from Space, Body, Shape and Constraint and will release any non-released pointer. *** This is a lazy deallocation for the lazy programmers. It is disabled by default. *** To work properly set as active before allocating anything, activate it just after the singleton instantiation. */ @@ -47,38 +47,38 @@ class CP_API cPhysicsManager { const bool& MemoryManager() const; - cPhysicsManager::cDrawSpaceOptions * GetDrawOptions(); + PhysicsManager::cDrawSpaceOptions * GetDrawOptions(); protected: cDrawSpaceOptions mOptions; - friend class cBody; - friend class cShape; - friend class cConstraint; - friend class cSpace; + friend class Body; + friend class Shape; + friend class Constraint; + friend class Space; bool mMemoryManager; - std::list mBodysFree; - std::list mShapesFree; - std::list mConstraintFree; - std::list mSpaces; + std::list mBodysFree; + std::list mShapesFree; + std::list mConstraintFree; + std::list mSpaces; - cPhysicsManager(); + PhysicsManager(); - void AddBodyFree( cBody * body ); + void AddBodyFree( Body * body ); - void RemoveBodyFree( cBody * body ); + void RemoveBodyFree( Body * body ); - void AddShapeFree( cShape * shape ); + void AddShapeFree( Shape * shape ); - void RemoveShapeFree( cShape * shape ); + void RemoveShapeFree( Shape * shape ); - void AddConstraintFree( cConstraint * constraint ); + void AddConstraintFree( Constraint * constraint ); - void RemoveConstraintFree( cConstraint * constraint ); + void RemoveConstraintFree( Constraint * constraint ); - void AddSpace( cSpace * space ); + void AddSpace( Space * space ); - void RemoveSpace( cSpace * space ); + void RemoveSpace( Space * space ); }; CP_NAMESPACE_END diff --git a/include/eepp/physics/cshape.hpp b/include/eepp/physics/shape.hpp similarity index 69% rename from include/eepp/physics/cshape.hpp rename to include/eepp/physics/shape.hpp index f12b3dd00..985084d76 100644 --- a/include/eepp/physics/cshape.hpp +++ b/include/eepp/physics/shape.hpp @@ -2,28 +2,28 @@ #define EE_PHYSICS_CSHAPE_HPP #include -#include +#include CP_NAMESPACE_BEGIN -class cShapeCircle; -class cShapeSegment; -class cShapePoly; -class cSpace; +class ShapeCircle; +class ShapeSegment; +class ShapePoly; +class Space; -class CP_API cShape { +class CP_API Shape { public: static void ResetShapeIdCounter(); - static void Free( cShape * shape, bool DeleteBody = false ); + static void Free( Shape * shape, bool DeleteBody = false ); - cpShape * Shape() const; + cpShape * GetShape() const; - virtual ~cShape(); + virtual ~Shape(); - cBody * Body() const; + Physics::Body * Body() const; - void Body( cBody * body ); + void Body( Physics::Body * body ); cBB BB() const; @@ -73,15 +73,15 @@ class CP_API cShape { cpShapeType Type() const; - cShapePoly * GetAsPoly(); + ShapePoly * GetAsPoly(); - cShapeCircle * GetAsCircle(); + ShapeCircle * GetAsCircle(); - cShapeSegment * GetAsSegment(); + ShapeSegment * GetAsSegment(); - virtual void Draw( cSpace * space ); + virtual void Draw( Space * space ); - virtual void DrawBorder( cSpace * space ); + virtual void DrawBorder( Space * space ); virtual void DrawBB(); @@ -89,7 +89,7 @@ class CP_API cShape { void Data( void * data ); protected: - cShape(); + Shape(); cpShape * mShape; void * mData; diff --git a/include/eepp/physics/cshapecircle.hpp b/include/eepp/physics/shapecircle.hpp similarity index 50% rename from include/eepp/physics/cshapecircle.hpp rename to include/eepp/physics/shapecircle.hpp index c26d48916..9905007a9 100644 --- a/include/eepp/physics/cshapecircle.hpp +++ b/include/eepp/physics/shapecircle.hpp @@ -1,15 +1,15 @@ #ifndef EE_PHYSICS_CSHAPECIRCLE_HPP #define EE_PHYSICS_CSHAPECIRCLE_HPP -#include +#include CP_NAMESPACE_BEGIN -class CP_API cShapeCircle : public cShape { +class CP_API ShapeCircle : public Shape { public: - static cShapeCircle * New( cBody * body, cpFloat radius, cVect offset ); + static ShapeCircle * New( Physics::Body * body, cpFloat radius, cVect offset ); - cShapeCircle( cBody * body, cpFloat radius, cVect offset ); + ShapeCircle( Physics::Body * body, cpFloat radius, cVect offset ); cVect Offset(); @@ -19,7 +19,7 @@ class CP_API cShapeCircle : public cShape { virtual void Radius( const cpFloat& radius ); - virtual void Draw( cSpace * space ); + virtual void Draw( Space * space ); }; CP_NAMESPACE_END diff --git a/include/eepp/physics/cshapecirclesprite.hpp b/include/eepp/physics/shapecirclesprite.hpp similarity index 51% rename from include/eepp/physics/cshapecirclesprite.hpp rename to include/eepp/physics/shapecirclesprite.hpp index 371660623..f268f2615 100644 --- a/include/eepp/physics/cshapecirclesprite.hpp +++ b/include/eepp/physics/shapecirclesprite.hpp @@ -1,7 +1,7 @@ #ifndef CSHAPECIRCLESPRITE_HPP #define CSHAPECIRCLESPRITE_HPP -#include +#include #ifdef PHYSICS_RENDERER_ENABLED @@ -12,15 +12,15 @@ using namespace EE::Graphics; CP_NAMESPACE_BEGIN -class CP_API cShapeCircleSprite : public cShapeCircle { +class CP_API ShapeCircleSprite : public ShapeCircle { public: - static cShapeCircleSprite * New( cBody * body, cpFloat radius, cVect offset, Sprite * Sprite, bool AutoDeleteSprite = false ); + static ShapeCircleSprite * New( Physics::Body * body, cpFloat radius, cVect offset, Sprite * Sprite, bool AutoDeleteSprite = false ); - cShapeCircleSprite( cBody * body, cpFloat radius, cVect offset, Sprite * Sprite, bool AutoDeleteSprite = false ); + ShapeCircleSprite( Physics::Body * body, cpFloat radius, cVect offset, Sprite * Sprite, bool AutoDeleteSprite = false ); - virtual ~cShapeCircleSprite(); + virtual ~ShapeCircleSprite(); - virtual void Draw( cSpace * space ); + virtual void Draw( Space * space ); virtual void Radius( const cpFloat& radius ); diff --git a/include/eepp/physics/cshapepoint.hpp b/include/eepp/physics/shapepoint.hpp similarity index 61% rename from include/eepp/physics/cshapepoint.hpp rename to include/eepp/physics/shapepoint.hpp index 550def019..a8fbb4196 100644 --- a/include/eepp/physics/cshapepoint.hpp +++ b/include/eepp/physics/shapepoint.hpp @@ -1,15 +1,15 @@ #ifndef EE_PHYSICS_CSHAPEPOINT_HPP #define EE_PHYSICS_CSHAPEPOINT_HPP -#include +#include CP_NAMESPACE_BEGIN -class CP_API cShapePoint : public cShape { +class CP_API ShapePoint : public Shape { public: - static cShapePoint * New( cBody * body, cpFloat radius, cVect offset ); + static ShapePoint * New( Physics::Body * body, cpFloat radius, cVect offset ); - cShapePoint( cBody * body, cpFloat radius, cVect offset ); + ShapePoint( Physics::Body * body, cpFloat radius, cVect offset ); cVect Offset(); @@ -19,7 +19,7 @@ class CP_API cShapePoint : public cShape { virtual void Radius( const cpFloat& radius ); - virtual void Draw( cSpace * space ); + virtual void Draw( Space * space ); #ifdef PHYSICS_RENDERER_ENABLED cpFloat DrawRadius(); diff --git a/include/eepp/physics/shapepoly.hpp b/include/eepp/physics/shapepoly.hpp new file mode 100644 index 000000000..2fd3ccb3f --- /dev/null +++ b/include/eepp/physics/shapepoly.hpp @@ -0,0 +1,37 @@ +#ifndef EE_PHYSICS_CSHAPEPOLY_HPP +#define EE_PHYSICS_CSHAPEPOLY_HPP + +#include + +CP_NAMESPACE_BEGIN + +class CP_API ShapePoly : public Shape { + public: + static ShapePoly * New( Physics::Body * body, int numVerts, cVect *verts, cVect offset ); + + static ShapePoly * New( Physics::Body * body, cpFloat width, cpFloat height ); + + ShapePoly( Physics::Body * body, int numVerts, cVect *verts, cVect offset ); + + ShapePoly( Physics::Body * body, cpFloat width, cpFloat height ); + + static bool Validate( const cVect * verts, const int numVerts ); + + int GetNumVerts(); + + cVect GetVert( int idx ); + + void SetVerts( int numVerts, cVect *verts, cVect offset ); + + virtual void Draw( Space * space ); + + virtual void DrawBorder( Space * space ); + + static void Recenter( int numVerts, cVect * verts ); + + static cVect Centroid( int numVerts, const cVect * verts ); +}; + +CP_NAMESPACE_END + +#endif diff --git a/include/eepp/physics/shapepolysprite.hpp b/include/eepp/physics/shapepolysprite.hpp new file mode 100644 index 000000000..4786e3afd --- /dev/null +++ b/include/eepp/physics/shapepolysprite.hpp @@ -0,0 +1,42 @@ +#ifndef EE_PHYSICS_CSHAPEPOLYSPRITE_HPP +#define EE_PHYSICS_CSHAPEPOLYSPRITE_HPP + +#include + +#ifdef PHYSICS_RENDERER_ENABLED + +namespace EE { namespace Graphics { +class Sprite; +}} +using namespace EE::Graphics; + +CP_NAMESPACE_BEGIN + +class CP_API ShapePolySprite : public ShapePoly { + public: + static ShapePolySprite * New( Physics::Body * body, int numVerts, cVect *verts, cVect offset, Sprite * Sprite, bool AutoDeleteSprite = false ); + + static ShapePolySprite * New( Physics::Body * body, cpFloat width, cpFloat height, Sprite * Sprite, bool AutoDeleteSprite = false ); + + ShapePolySprite( Physics::Body * body, int numVerts, cVect *verts, cVect offset, Sprite * Sprite, bool AutoDeleteSprite = false ); + + ShapePolySprite( Physics::Body * body, cpFloat width, cpFloat height, Sprite * Sprite, bool AutoDeleteSprite = false ); + + virtual ~ShapePolySprite(); + + virtual void Draw( Space * space ); + + Sprite * GetSprite() const; + protected: + Sprite * mSprite; + bool mSpriteAutoDelete; + Vector2i mOffset; + + void OffsetSet( cVect center ); +}; + +CP_NAMESPACE_END + +#endif + +#endif diff --git a/include/eepp/physics/cshapesegment.hpp b/include/eepp/physics/shapesegment.hpp similarity index 67% rename from include/eepp/physics/cshapesegment.hpp rename to include/eepp/physics/shapesegment.hpp index a97e34b6a..50ee5c92c 100644 --- a/include/eepp/physics/cshapesegment.hpp +++ b/include/eepp/physics/shapesegment.hpp @@ -1,15 +1,15 @@ #ifndef EE_PHYSICS_CSHAPESEGMENT_HPP #define EE_PHYSICS_CSHAPESEGMENT_HPP -#include +#include CP_NAMESPACE_BEGIN -class CP_API cShapeSegment : public cShape { +class CP_API ShapeSegment : public Shape { public: - static cShapeSegment * New( cBody * body, cVect a, cVect b, cpFloat radius ); + static ShapeSegment * New( Physics::Body * body, cVect a, cVect b, cpFloat radius ); - cShapeSegment( cBody * body, cVect a, cVect b, cpFloat radius ); + ShapeSegment( Physics::Body * body, cVect a, cVect b, cpFloat radius ); cVect A(); @@ -29,7 +29,7 @@ class CP_API cShapeSegment : public cShape { static cpFloat QueryHitDist( const cVect start, const cVect end, const cpSegmentQueryInfo info ); - virtual void Draw( cSpace * space ); + virtual void Draw( Space * space ); }; CP_NAMESPACE_END diff --git a/include/eepp/physics/cspace.hpp b/include/eepp/physics/space.hpp similarity index 50% rename from include/eepp/physics/cspace.hpp rename to include/eepp/physics/space.hpp index 1ccfb82ee..5f5363eaf 100644 --- a/include/eepp/physics/cspace.hpp +++ b/include/eepp/physics/space.hpp @@ -2,25 +2,25 @@ #define EE_PHYSICS_CSPACE_HPP #include -#include -#include -#include -#include +#include +#include +#include +#include CP_NAMESPACE_BEGIN -class CP_API cSpace { +class CP_API Space { public: - typedef cb::Callback3 CollisionBeginFunc; - typedef cb::Callback3 CollisionPreSolveFunc; - typedef cb::Callback3 CollisionPostSolveFunc; - typedef cb::Callback3 CollisionSeparateFunc; - typedef cb::Callback3 PostStepCallback; - typedef cb::Callback2 BBQueryFunc; - typedef cb::Callback4 SegmentQueryFunc; - typedef cb::Callback2 PointQueryFunc; - typedef cb::Callback3 BodyIteratorFunc; - typedef cb::Callback3 ShapeIteratorFunc; + typedef cb::Callback3 CollisionBeginFunc; + typedef cb::Callback3 CollisionPreSolveFunc; + typedef cb::Callback3 CollisionPostSolveFunc; + typedef cb::Callback3 CollisionSeparateFunc; + typedef cb::Callback3 PostStepCallback; + typedef cb::Callback2 BBQueryFunc; + typedef cb::Callback4 SegmentQueryFunc; + typedef cb::Callback2 PointQueryFunc; + typedef cb::Callback3 BodyIteratorFunc; + typedef cb::Callback3 ShapeIteratorFunc; class cCollisionHandler { public: @@ -66,9 +66,9 @@ class CP_API cSpace { Data( NULL ) {} - cSpace * Space; - BBQueryFunc Func; - void * Data; + Physics::Space * Space; + BBQueryFunc Func; + void * Data; }; class cSegmentQuery { @@ -76,7 +76,7 @@ class CP_API cSpace { cSegmentQuery() {} - cSpace * Space; + Physics::Space * Space; SegmentQueryFunc Func; void * Data; }; @@ -87,50 +87,50 @@ class CP_API cSpace { Data( NULL ) {} - cSpace * Space; - PointQueryFunc Func; - void * Data; + Physics::Space * Space; + PointQueryFunc Func; + void * Data; }; - class cBodyIterator { + class BodyIterator { public: - cBodyIterator( cSpace * space, void * data, BodyIteratorFunc func ) : + BodyIterator( Physics::Space * space, void * data, BodyIteratorFunc func ) : Space( space ), Data( data ), Func( func ) {} - cSpace * Space; - void * Data; - BodyIteratorFunc Func; + Physics::Space * Space; + void * Data; + BodyIteratorFunc Func; }; - class cShapeIterator { + class ShapeIterator { public: - cShapeIterator( cSpace * space, void * data, ShapeIteratorFunc func ) : + ShapeIterator( Physics::Space * space, void * data, ShapeIteratorFunc func ) : Space( space ), Data( data ), Func( func ) {} - cSpace * Space; + Physics::Space * Space; void * Data; ShapeIteratorFunc Func; }; - static cSpace * New(); + static Space * New(); - static void Free( cSpace * space ); + static void Free( Space * space ); - cSpace(); + Space(); - virtual ~cSpace(); + virtual ~Space(); void Step( const cpFloat& dt ); void Update(); - cBody * StaticBody() const; + Body * StatiBody() const; const int& Iterations() const; @@ -168,37 +168,37 @@ class CP_API cSpace { void EnableContactGraph( bool value ); - bool Contains( cShape * shape ); + bool Contains( Shape * shape ); - bool Contains( cBody * body ); + bool Contains( Body * body ); - bool Contains( cConstraint * constraint ); + bool Contains( Constraint * constraint ); - cShape * AddShape( cShape * shape ); + Shape * AddShape( Shape * shape ); - cShape * AddStaticShape( cShape *shape ); + Shape * AddStatiShape( Shape *shape ); - cBody * AddBody( cBody * body ); + Body * AddBody( Body * body ); - cConstraint * AddConstraint( cConstraint * constraint ); + Constraint * AddConstraint( Constraint * constraint ); - void RemoveShape( cShape * shape ); + void RemoveShape( Shape * shape ); - void RemoveStaticShape( cShape * shape ); + void RemoveStatiShape( Shape * shape ); - void RemoveBody( cBody * body ); + void RemoveBody( Body * body ); - void RemoveConstraint( cConstraint * constraint ); + void RemoveConstraint( Constraint * constraint ); - cpSpace * Space() const; + cpSpace * GetSpace() const; - void ActivateShapesTouchingShape( cShape * shape ); + void ActivateShapesTouchingShape( Shape * shape ); virtual void Draw(); - cShape * PointQueryFirst( cVect point, cpLayers layers, cpGroup group ); + Shape * PointQueryFirst( cVect point, cpLayers layers, cpGroup group ); - cShape * SegmentQueryFirst( cVect start, cVect end, cpLayers layers, cpGroup group, cpSegmentQueryInfo * out ); + Shape * SegmentQueryFirst( cVect start, cVect end, cpLayers layers, cpGroup group, cpSegmentQueryInfo * out ); void AddCollisionHandler( const cCollisionHandler& handler ); @@ -208,21 +208,21 @@ class CP_API cSpace { void AddPostStepCallback( PostStepCallback postStep, void * obj, void * data ); - virtual cpBool OnCollisionBegin( cArbiter * arb, void * data ); + virtual cpBool OnCollisionBegin( Arbiter * arb, void * data ); - virtual cpBool OnCollisionPreSolve( cArbiter * arb, void * data ); + virtual cpBool OnCollisionPreSolve( Arbiter * arb, void * data ); - virtual void OnCollisionPostSolve( cArbiter * arb, void * data ); + virtual void OnCollisionPostSolve( Arbiter * arb, void * data ); - virtual void OnCollisionSeparate( cArbiter * arb, void * data ); + virtual void OnCollisionSeparate( Arbiter * arb, void * data ); virtual void OnPostStepCallback( void * obj, void * data ); - virtual void OnBBQuery( cShape * shape, cBBQuery * query ); + virtual void OnBBQuery( Shape * shape, cBBQuery * query ); - virtual void OnSegmentQuery( cShape * shape, cpFloat t, cVect n , cSegmentQuery * query ); + virtual void OnSegmentQuery( Shape * shape, cpFloat t, cVect n , cSegmentQuery * query ); - virtual void OnPointQuery( cShape * shape, cPointQuery * query ); + virtual void OnPointQuery( Shape * shape, cPointQuery * query ); void BBQuery( cBB bb, cpLayers layers, cpGroup group, BBQueryFunc func, void * data ); @@ -234,9 +234,9 @@ class CP_API cSpace { void * Data() const; - void ReindexShape( cShape * shape ); + void ReindexShape( Shape * shape ); - void ReindexShapesForBody( cBody *body ); + void ReindexShapesForBody( Body *body ); void ReindexStatic(); @@ -244,22 +244,22 @@ class CP_API cSpace { void EachShape( ShapeIteratorFunc Func, void * data ); - virtual void OnEachShape( cShape * Shape, cShapeIterator * it ); + virtual void OnEachShape( Shape * Shape, ShapeIterator * it ); void EachBody( BodyIteratorFunc Func, void * data ); - virtual void OnEachBody( cBody * Body, cBodyIterator * it ); + virtual void OnEachBody( Body * Body, BodyIterator * it ); - void ConvertBodyToDynamic( cBody * body, cpFloat mass, cpFloat moment ); + void ConvertBodyToDynamic( Body * body, cpFloat mass, cpFloat moment ); - void ConvertBodyToStatic( cBody * body ); + void ConvertBodyToStatic( Body * body ); protected: cpSpace * mSpace; - cBody * mStaticBody; + Body * mStatiBody; void * mData; - std::list mBodys; - std::list mShapes; - std::list mConstraints; + std::list mBodys; + std::list mShapes; + std::list mConstraints; std::map< cpHashValue, cCollisionHandler > mCollisions; cCollisionHandler mCollisionsDefault; std::list< cPostStepCallback* > mPostStepCallbacks; diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index dfb9beb1c..b6171c3ea 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 941603d4f..16e5f8718 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -166,50 +166,50 @@ ../../include/eepp/physics/settings.hpp ../../include/eepp/physics/physicshelper.hpp ../../include/eepp/physics/moment.hpp -../../include/eepp/physics/cspace.hpp -../../include/eepp/physics/cshapesegment.hpp -../../include/eepp/physics/cshapepolysprite.hpp -../../include/eepp/physics/cshapepoly.hpp -../../include/eepp/physics/cshapecirclesprite.hpp -../../include/eepp/physics/cshapecircle.hpp -../../include/eepp/physics/cshape.hpp -../../include/eepp/physics/cphysicsmanager.hpp -../../include/eepp/physics/cbody.hpp -../../include/eepp/physics/carbiter.hpp +../../include/eepp/physics/space.hpp +../../include/eepp/physics/shapesegment.hpp +../../include/eepp/physics/shapepolysprite.hpp +../../include/eepp/physics/shapepoly.hpp +../../include/eepp/physics/shapecirclesprite.hpp +../../include/eepp/physics/shapecircle.hpp +../../include/eepp/physics/shape.hpp +../../include/eepp/physics/physicsmanager.hpp +../../include/eepp/physics/body.hpp +../../include/eepp/physics/arbiter.hpp ../../include/eepp/physics/base.hpp ../../include/eepp/physics/area.hpp -../../include/eepp/physics/constraints/cslidejoint.hpp -../../include/eepp/physics/constraints/csimplemotor.hpp -../../include/eepp/physics/constraints/crotarylimitjoint.hpp -../../include/eepp/physics/constraints/cratchetjoint.hpp -../../include/eepp/physics/constraints/cpivotjoint.hpp -../../include/eepp/physics/constraints/cpinjoint.hpp -../../include/eepp/physics/constraints/cgroovejoint.hpp -../../include/eepp/physics/constraints/cgearjoint.hpp -../../include/eepp/physics/constraints/cdampedspring.hpp -../../include/eepp/physics/constraints/cdampedrotaryspring.hpp -../../include/eepp/physics/constraints/cconstraint.hpp -../../src/eepp/physics/cspace.cpp -../../src/eepp/physics/cshapesegment.cpp -../../src/eepp/physics/cshapepolysprite.cpp -../../src/eepp/physics/cshapepoly.cpp -../../src/eepp/physics/cshapecirclesprite.cpp -../../src/eepp/physics/cshapecircle.cpp -../../src/eepp/physics/cshape.cpp -../../src/eepp/physics/cphysicsmanager.cpp -../../src/eepp/physics/cbody.cpp -../../src/eepp/physics/carbiter.cpp -../../src/eepp/physics/constraints/cslidejoint.cpp -../../src/eepp/physics/constraints/csimplemotor.cpp -../../src/eepp/physics/constraints/crotarylimitjoint.cpp -../../src/eepp/physics/constraints/cratchetjoint.cpp -../../src/eepp/physics/constraints/cpivotjoint.cpp -../../src/eepp/physics/constraints/cpinjoint.cpp -../../src/eepp/physics/constraints/cgroovejoint.cpp -../../src/eepp/physics/constraints/cgearjoint.cpp -../../src/eepp/physics/constraints/cdampedspring.cpp -../../src/eepp/physics/constraints/cdampedrotaryspring.cpp -../../src/eepp/physics/constraints/cconstraint.cpp +../../include/eepp/physics/constraints/slidejoint.hpp +../../include/eepp/physics/constraints/simplemotor.hpp +../../include/eepp/physics/constraints/rotarylimitjoint.hpp +../../include/eepp/physics/constraints/ratchetjoint.hpp +../../include/eepp/physics/constraints/pivotjoint.hpp +../../include/eepp/physics/constraints/pinjoint.hpp +../../include/eepp/physics/constraints/groovejoint.hpp +../../include/eepp/physics/constraints/gearjoint.hpp +../../include/eepp/physics/constraints/dampedspring.hpp +../../include/eepp/physics/constraints/dampedrotaryspring.hpp +../../include/eepp/physics/constraints/constraint.hpp +../../src/eepp/physics/space.cpp +../../src/eepp/physics/shapesegment.cpp +../../src/eepp/physics/shapepolysprite.cpp +../../src/eepp/physics/shapepoly.cpp +../../src/eepp/physics/shapecirclesprite.cpp +../../src/eepp/physics/shapecircle.cpp +../../src/eepp/physics/shape.cpp +../../src/eepp/physics/physicsmanager.cpp +../../src/eepp/physics/body.cpp +../../src/eepp/physics/arbiter.cpp +../../src/eepp/physics/constraints/slidejoint.cpp +../../src/eepp/physics/constraints/simplemotor.cpp +../../src/eepp/physics/constraints/rotarylimitjoint.cpp +../../src/eepp/physics/constraints/ratchetjoint.cpp +../../src/eepp/physics/constraints/pivotjoint.cpp +../../src/eepp/physics/constraints/pinjoint.cpp +../../src/eepp/physics/constraints/groovejoint.cpp +../../src/eepp/physics/constraints/gearjoint.cpp +../../src/eepp/physics/constraints/dampedspring.cpp +../../src/eepp/physics/constraints/dampedrotaryspring.cpp +../../src/eepp/physics/constraints/constraint.cpp ../../include/eepp/ui/uihelper.hpp ../../include/eepp/ui/tuiitemcontainer.hpp ../../include/eepp/ui/cuiwinmenu.hpp @@ -604,8 +604,8 @@ ../../src/examples/fonts/fonts.cpp ../../src/examples/vbo_fbo_batch/vbo_fbo_batch.cpp ../../src/examples/physics/physics.cpp -../../src/eepp/physics/cshapepoint.cpp -../../include/eepp/physics/cshapepoint.hpp +../../src/eepp/physics/shapepoint.cpp +../../include/eepp/physics/shapepoint.hpp ../../include/eepp/math/originpoint.hpp ../../include/eepp/system/condition.hpp ../../src/eepp/system/condition.cpp diff --git a/src/eepp/physics/carbiter.cpp b/src/eepp/physics/arbiter.cpp similarity index 53% rename from src/eepp/physics/carbiter.cpp rename to src/eepp/physics/arbiter.cpp index 4e3a50916..831471f2e 100644 --- a/src/eepp/physics/carbiter.cpp +++ b/src/eepp/physics/arbiter.cpp @@ -1,118 +1,118 @@ -#include +#include CP_NAMESPACE_BEGIN -cArbiter::cArbiter( cpArbiter * arbiter ) { +Arbiter::Arbiter( cpArbiter * arbiter ) { mArbiter = arbiter; } -cVect cArbiter::TotalImpulse() { +cVect Arbiter::TotalImpulse() { return tovect( cpArbiterTotalImpulse( mArbiter ) ); } -cVect cArbiter::TotalImpulseWithFriction() { +cVect Arbiter::TotalImpulseWithFriction() { return tovect( cpArbiterTotalImpulseWithFriction( mArbiter ) ); } -void cArbiter::Ignore() { +void Arbiter::Ignore() { return cpArbiterIgnore( mArbiter ); } -void cArbiter::GetShapes( cShape ** a, cShape ** b ) { +void Arbiter::GetShapes( Shape ** a, Shape ** b ) { cpShape * tA; cpShape * tB; cpArbiterGetShapes( mArbiter, &tA, &tB ); if ( NULL != tA ) - *a = reinterpret_cast( tA->data ); + *a = reinterpret_cast( tA->data ); else *a = NULL; if ( NULL != tB ) - *b = reinterpret_cast( tB->data ); + *b = reinterpret_cast( tB->data ); else *b = NULL; } -void cArbiter::GetBodies( cBody ** a, cBody ** b) { +void Arbiter::GetBodies( Body ** a, Body ** b) { cpBody * tA; cpBody * tB; cpArbiterGetBodies( mArbiter, &tA, &tB ); if ( NULL != tA ) - *a = reinterpret_cast( tA->data ); + *a = reinterpret_cast( tA->data ); else *a = NULL; if ( NULL != tB ) - *b = reinterpret_cast( tB->data ); + *b = reinterpret_cast( tB->data ); else *b = NULL; } -bool cArbiter::IsFirstContact() { +bool Arbiter::IsFirstContact() { return 0 != cpArbiterIsFirstContact( mArbiter ); } -int cArbiter::GetCount() { +int Arbiter::GetCount() { return cpArbiterGetCount( mArbiter ); } -cVect cArbiter::GetNormal( int i ) { +cVect Arbiter::GetNormal( int i ) { return tovect( cpArbiterGetNormal( mArbiter, i ) ); } -cVect cArbiter::GetPoint( int i ) { +cVect Arbiter::GetPoint( int i ) { return tovect( cpArbiterGetPoint( mArbiter, i ) ); } -cpFloat cArbiter::GetDepth( int i ) { +cpFloat Arbiter::GetDepth( int i ) { return cpArbiterGetDepth( mArbiter, i ); } -cpContactPointSet cArbiter::ContactPointSet() { +cpContactPointSet Arbiter::ContactPointSet() { return cpArbiterGetContactPointSet( mArbiter ); } -void cArbiter::ContactPointSet( cpContactPointSet * contact ) { +void Arbiter::ContactPointSet( cpContactPointSet * contact ) { cpArbiterSetContactPointSet( mArbiter, contact ); } -cpArbiter * cArbiter::Arbiter() const { +cpArbiter * Arbiter::GetArbiter() const { return mArbiter; } -cpFloat cArbiter::Elasticity() { +cpFloat Arbiter::Elasticity() { return cpArbiterGetElasticity( mArbiter); } -void cArbiter::Elasticity( cpFloat value ) { +void Arbiter::Elasticity( cpFloat value ) { cpArbiterSetElasticity( mArbiter, value ); } -cpFloat cArbiter::Friction() { +cpFloat Arbiter::Friction() { return cpArbiterGetFriction( mArbiter ); } -void cArbiter::Friction( cpFloat value ) { +void Arbiter::Friction( cpFloat value ) { cpArbiterSetFriction( mArbiter, value ); } -cVect cArbiter::SurfaceVelocity() { +cVect Arbiter::SurfaceVelocity() { return tovect( cpArbiterGetSurfaceVelocity( mArbiter ) ); } -void cArbiter::SurfaceVelocity( cVect value ) { +void Arbiter::SurfaceVelocity( cVect value ) { cpArbiterSetSurfaceVelocity( mArbiter, tocpv( value ) ); } -void cArbiter::UserData( cpDataPointer value ) { +void Arbiter::UserData( cpDataPointer value ) { cpArbiterSetUserData( mArbiter, value ); } -cpDataPointer cArbiter::UserData() const { +cpDataPointer Arbiter::UserData() const { return cpArbiterGetUserData( mArbiter ); } diff --git a/src/eepp/physics/body.cpp b/src/eepp/physics/body.cpp new file mode 100644 index 000000000..0cb05b02e --- /dev/null +++ b/src/eepp/physics/body.cpp @@ -0,0 +1,300 @@ +#include +#include +#include +#include +#include + +CP_NAMESPACE_BEGIN + +Body * Body::New( cpFloat m, cpFloat i ) { + return cpNew( Body, ( m, i ) ); +} + +Body * Body::New( cpBody * body ) { + return cpNew( Body, ( body ) ); +} + +Body * Body::New() { + return cpNew( Body, () ); +} + +void Body::Free( Body * body ) { + cpSAFE_DELETE( body ); +} + +Body::Body( cpBody * body ) : + mBody( body ), + mData( NULL ) +{ + SetData(); +} + +Body::Body( cpFloat m, cpFloat i ) : + mBody( cpBodyNew( m, i ) ), + mData( NULL ) +{ + SetData(); +} + +Body::Body() : + mBody( cpBodyNewStatic() ), + mData( NULL ) +{ + SetData(); +} + +Body::~Body() { + if ( NULL != mBody ) + cpBodyFree( mBody ); + + PhysicsManager::instance()->RemoveBodyFree( this ); +} + +void Body::SetData() { + mBody->data = (void*)this; + + PhysicsManager::instance()->AddBodyFree( this ); +} + +void Body::Activate() { + cpBodyActivate( mBody ); +} + +void Body::ActivateStatic( Body *body, Shape * filter ) { + cpBodyActivateStatic( mBody, filter->GetShape() ); +} + +void Body::Sleep() { + cpBodySleep( mBody ); +} + +void Body::SleepWithGroup( Body * Group ) { + cpBodySleepWithGroup( mBody, Group->GetBody() ); +} + +bool Body::IsSleeping() { + return cpFalse != cpBodyIsSleeping( mBody ); +} + +bool Body::IsStatic() { + return cpFalse != cpBodyIsStatic( mBody ); +} + +bool Body::IsRogue() { + return cpFalse != cpBodyIsRogue( mBody ); +} + +cpBody * Body::GetBody() const { + return mBody; +} + +cpFloat Body::Mass() const { + return cpBodyGetMass( mBody ); +} + +void Body::Mass( const cpFloat& mass ) { + cpBodySetMass( mBody, mass ); +} + +cpFloat Body::Moment() const { + return cpBodyGetMoment( mBody ); +} + +void Body::Moment( const cpFloat& i ) { + cpBodySetMoment( mBody, i ); +} + +cVect Body::Pos() const { + return tovect( cpBodyGetPos( mBody ) ); +} + +void Body::Pos( const cVect& pos ) { + cpBodySetPos( mBody, tocpv( pos ) ); +} + +cVect Body::Vel() const { + return tovect( cpBodyGetVel( mBody ) ); +} + +void Body::Vel( const cVect& vel ) { + cpBodySetVel( mBody, tocpv( vel ) ); +} + +cVect Body::Force() const { + return tovect( cpBodyGetForce( mBody ) ); +} + +void Body::Force( const cVect& force ) { + cpBodySetForce( mBody, tocpv( force ) ); +} + +cpFloat Body::Angle() const { + return cpBodyGetAngle( mBody ); +} + +void Body::Angle( const cpFloat& rads ) { + cpBodySetAngle( mBody, rads ); +} + +cpFloat Body::AngleDeg() { + return cpDegrees( mBody->a ); +} + +void Body::AngleDeg( const cpFloat& angle ) { + Angle( cpRadians( angle ) ); +} + +cpFloat Body::AngVel() const { + return cpBodyGetAngVel( mBody ); +} + +void Body::AngVel( const cpFloat& rotVel ) { + cpBodySetAngVel( mBody, rotVel ); +} + +cpFloat Body::Torque() const { + return cpBodyGetTorque( mBody ); +} + +void Body::Torque( const cpFloat& torque ) { + cpBodySetTorque( mBody, torque ); +} + +cVect Body::Rot() const { + return tovect( cpBodyGetRot( mBody ) ); +} + +cpFloat Body::VelLimit() const { + return cpBodyGetVelLimit( mBody ); +} + +void Body::VelLimit( const cpFloat& speed ) { + cpBodySetVelLimit( mBody, speed ); +} + +cpFloat Body::AngVelLimit() const { + return cpBodyGetAngVelLimit( mBody ); +} + +void Body::AngVelLimit( const cpFloat& speed ) { + cpBodySetAngVelLimit( mBody, speed ); +} + +void Body::UpdateVelocity( cVect gravity, cpFloat damping, cpFloat dt ) { + cpBodyUpdateVelocity( mBody, tocpv( gravity ), damping, dt ); +} + +void Body::UpdatePosition( cpFloat dt ) { + cpBodyUpdatePosition( mBody, dt ); +} + +void Body::BodyVelocityFuncWrapper( cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt ) { + Body * tBody = reinterpret_cast( body->data ); + + if ( tBody->mVelocityFunc.IsSet() ) { + tBody->mVelocityFunc( reinterpret_cast( body->data ), tovect( gravity ), damping, dt ); + } +} + +void Body::VelocityFunc( BodyVelocityFunc func ) { + mBody->velocity_func = &Body::BodyVelocityFuncWrapper; + + mVelocityFunc = func; +} + +void Body::BodyPositionFuncWrapper( cpBody* body, cpFloat dt ) { + Body * tBody = reinterpret_cast( body->data ); + + if ( tBody->mPositionFunc.IsSet() ) { + tBody->mPositionFunc( reinterpret_cast( body->data ), dt ); + } +} + +void Body::PositionFunc( BodyPositionFunc func ) { + mBody->position_func = &Body::BodyPositionFuncWrapper; + + mPositionFunc = func; +} + +cVect Body::Local2World( const cVect v ) { + return tovect( cpBodyLocal2World( mBody, tocpv( v ) ) ); +} + +cVect Body::World2Local( const cVect v ) { + return tovect( cpBodyWorld2Local( mBody, tocpv( v ) ) ); +} + +void Body::ApplyImpulse( const cVect j, const cVect r ) { + cpBodyApplyImpulse( mBody, tocpv( j ), tocpv( r ) ); +} + +void Body::ResetForces() { + cpBodyResetForces( mBody ); +} + +void Body::ApplyForce( const cVect f, const cVect r ) { + cpBodyApplyForce( mBody, tocpv( f ), tocpv( r ) ); +} + +cpFloat Body::KineticEnergy() { + return cpBodyKineticEnergy( mBody ); +} + +void * Body::Data() const { + return mData; +} + +void Body::Data( void * data ) { + mData = data; +} + +static void BodyShapeIteratorFunc ( cpBody * body, cpShape * shape, void * data ) { + Body::ShapeIterator * it = reinterpret_cast ( data ); + it->Body->OnEachShape( reinterpret_cast( shape->data ), it ); +} + +void Body::EachShape( ShapeIteratorFunc Func, void * data ) { + ShapeIterator it( this, data, Func ); + cpBodyEachShape( mBody, &BodyShapeIteratorFunc, (void*)&it ); +} + +void Body::OnEachShape( Shape * Shape, ShapeIterator * it ) { + if ( it->Func.IsSet() ) { + it->Func( it->Body, Shape, it->Data ); + } +} + +static void BodyConstraintIteratorFunc( cpBody * body, cpConstraint * constraint, void * data ) { + Body::ConstraintIterator * it = reinterpret_cast ( data ); + it->Body->OnEachConstraint( reinterpret_cast ( constraint->data ), it ); +} + +void Body::EachConstraint( ConstraintIteratorFunc Func, void * data ) { + ConstraintIterator it( this, data, Func ); + cpBodyEachConstraint( mBody, &BodyConstraintIteratorFunc, (void*)&it ); +} + +void Body::OnEachConstraint( Constraint * Constraint, ConstraintIterator * it ) { + if ( it->Func.IsSet() ) { + it->Func( this, Constraint, it->Data ); + } +} + +static void BodyArbiterIteratorFunc( cpBody * body, cpArbiter * arbiter, void * data ) { + Body::ArbiterIterator * it = reinterpret_cast ( data ); + Arbiter tarb( arbiter ); + it->Body->OnEachArbiter( &tarb, it ); +} + +void Body::EachArbiter( ArbiterIteratorFunc Func, void * data ) { + ArbiterIterator it( this, data, Func ); + cpBodyEachArbiter( mBody, &BodyArbiterIteratorFunc, (void*)&it ); +} + +void Body::OnEachArbiter( Arbiter * Arbiter, ArbiterIterator * it ) { + if ( it->Func.IsSet() ) { + it->Func( this, Arbiter, it->Data ); + } +} + +CP_NAMESPACE_END diff --git a/src/eepp/physics/cbody.cpp b/src/eepp/physics/cbody.cpp deleted file mode 100644 index 608c4e16b..000000000 --- a/src/eepp/physics/cbody.cpp +++ /dev/null @@ -1,300 +0,0 @@ -#include -#include -#include -#include -#include - -CP_NAMESPACE_BEGIN - -cBody * cBody::New( cpFloat m, cpFloat i ) { - return cpNew( cBody, ( m, i ) ); -} - -cBody * cBody::New( cpBody * body ) { - return cpNew( cBody, ( body ) ); -} - -cBody * cBody::New() { - return cpNew( cBody, () ); -} - -void cBody::Free( cBody * body ) { - cpSAFE_DELETE( body ); -} - -cBody::cBody( cpBody * body ) : - mBody( body ), - mData( NULL ) -{ - SetData(); -} - -cBody::cBody( cpFloat m, cpFloat i ) : - mBody( cpBodyNew( m, i ) ), - mData( NULL ) -{ - SetData(); -} - -cBody::cBody() : - mBody( cpBodyNewStatic() ), - mData( NULL ) -{ - SetData(); -} - -cBody::~cBody() { - if ( NULL != mBody ) - cpBodyFree( mBody ); - - cPhysicsManager::instance()->RemoveBodyFree( this ); -} - -void cBody::SetData() { - mBody->data = (void*)this; - - cPhysicsManager::instance()->AddBodyFree( this ); -} - -void cBody::Activate() { - cpBodyActivate( mBody ); -} - -void cBody::ActivateStatic( cBody *body, cShape * filter ) { - cpBodyActivateStatic( mBody, filter->Shape() ); -} - -void cBody::Sleep() { - cpBodySleep( mBody ); -} - -void cBody::SleepWithGroup( cBody * Group ) { - cpBodySleepWithGroup( mBody, Group->Body() ); -} - -bool cBody::IsSleeping() { - return cpFalse != cpBodyIsSleeping( mBody ); -} - -bool cBody::IsStatic() { - return cpFalse != cpBodyIsStatic( mBody ); -} - -bool cBody::IsRogue() { - return cpFalse != cpBodyIsRogue( mBody ); -} - -cpBody * cBody::Body() const { - return mBody; -} - -cpFloat cBody::Mass() const { - return cpBodyGetMass( mBody ); -} - -void cBody::Mass( const cpFloat& mass ) { - cpBodySetMass( mBody, mass ); -} - -cpFloat cBody::Moment() const { - return cpBodyGetMoment( mBody ); -} - -void cBody::Moment( const cpFloat& i ) { - cpBodySetMoment( mBody, i ); -} - -cVect cBody::Pos() const { - return tovect( cpBodyGetPos( mBody ) ); -} - -void cBody::Pos( const cVect& pos ) { - cpBodySetPos( mBody, tocpv( pos ) ); -} - -cVect cBody::Vel() const { - return tovect( cpBodyGetVel( mBody ) ); -} - -void cBody::Vel( const cVect& vel ) { - cpBodySetVel( mBody, tocpv( vel ) ); -} - -cVect cBody::Force() const { - return tovect( cpBodyGetForce( mBody ) ); -} - -void cBody::Force( const cVect& force ) { - cpBodySetForce( mBody, tocpv( force ) ); -} - -cpFloat cBody::Angle() const { - return cpBodyGetAngle( mBody ); -} - -void cBody::Angle( const cpFloat& rads ) { - cpBodySetAngle( mBody, rads ); -} - -cpFloat cBody::AngleDeg() { - return cpDegrees( mBody->a ); -} - -void cBody::AngleDeg( const cpFloat& angle ) { - Angle( cpRadians( angle ) ); -} - -cpFloat cBody::AngVel() const { - return cpBodyGetAngVel( mBody ); -} - -void cBody::AngVel( const cpFloat& rotVel ) { - cpBodySetAngVel( mBody, rotVel ); -} - -cpFloat cBody::Torque() const { - return cpBodyGetTorque( mBody ); -} - -void cBody::Torque( const cpFloat& torque ) { - cpBodySetTorque( mBody, torque ); -} - -cVect cBody::Rot() const { - return tovect( cpBodyGetRot( mBody ) ); -} - -cpFloat cBody::VelLimit() const { - return cpBodyGetVelLimit( mBody ); -} - -void cBody::VelLimit( const cpFloat& speed ) { - cpBodySetVelLimit( mBody, speed ); -} - -cpFloat cBody::AngVelLimit() const { - return cpBodyGetAngVelLimit( mBody ); -} - -void cBody::AngVelLimit( const cpFloat& speed ) { - cpBodySetAngVelLimit( mBody, speed ); -} - -void cBody::UpdateVelocity( cVect gravity, cpFloat damping, cpFloat dt ) { - cpBodyUpdateVelocity( mBody, tocpv( gravity ), damping, dt ); -} - -void cBody::UpdatePosition( cpFloat dt ) { - cpBodyUpdatePosition( mBody, dt ); -} - -void cBody::BodyVelocityFuncWrapper( cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt ) { - cBody * tBody = reinterpret_cast( body->data ); - - if ( tBody->mVelocityFunc.IsSet() ) { - tBody->mVelocityFunc( reinterpret_cast( body->data ), tovect( gravity ), damping, dt ); - } -} - -void cBody::VelocityFunc( BodyVelocityFunc func ) { - mBody->velocity_func = &cBody::BodyVelocityFuncWrapper; - - mVelocityFunc = func; -} - -void cBody::BodyPositionFuncWrapper( cpBody* body, cpFloat dt ) { - cBody * tBody = reinterpret_cast( body->data ); - - if ( tBody->mPositionFunc.IsSet() ) { - tBody->mPositionFunc( reinterpret_cast( body->data ), dt ); - } -} - -void cBody::PositionFunc( BodyPositionFunc func ) { - mBody->position_func = &cBody::BodyPositionFuncWrapper; - - mPositionFunc = func; -} - -cVect cBody::Local2World( const cVect v ) { - return tovect( cpBodyLocal2World( mBody, tocpv( v ) ) ); -} - -cVect cBody::World2Local( const cVect v ) { - return tovect( cpBodyWorld2Local( mBody, tocpv( v ) ) ); -} - -void cBody::ApplyImpulse( const cVect j, const cVect r ) { - cpBodyApplyImpulse( mBody, tocpv( j ), tocpv( r ) ); -} - -void cBody::ResetForces() { - cpBodyResetForces( mBody ); -} - -void cBody::ApplyForce( const cVect f, const cVect r ) { - cpBodyApplyForce( mBody, tocpv( f ), tocpv( r ) ); -} - -cpFloat cBody::KineticEnergy() { - return cpBodyKineticEnergy( mBody ); -} - -void * cBody::Data() const { - return mData; -} - -void cBody::Data( void * data ) { - mData = data; -} - -static void BodyShapeIteratorFunc ( cpBody * body, cpShape * shape, void * data ) { - cBody::cShapeIterator * it = reinterpret_cast ( data ); - it->Body->OnEachShape( reinterpret_cast( shape->data ), it ); -} - -void cBody::EachShape( ShapeIteratorFunc Func, void * data ) { - cShapeIterator it( this, data, Func ); - cpBodyEachShape( mBody, &BodyShapeIteratorFunc, (void*)&it ); -} - -void cBody::OnEachShape( cShape * Shape, cShapeIterator * it ) { - if ( it->Func.IsSet() ) { - it->Func( it->Body, Shape, it->Data ); - } -} - -static void BodyConstraintIteratorFunc( cpBody * body, cpConstraint * constraint, void * data ) { - cBody::cConstraintIterator * it = reinterpret_cast ( data ); - it->Body->OnEachConstraint( reinterpret_cast ( constraint->data ), it ); -} - -void cBody::EachConstraint( ConstraintIteratorFunc Func, void * data ) { - cConstraintIterator it( this, data, Func ); - cpBodyEachConstraint( mBody, &BodyConstraintIteratorFunc, (void*)&it ); -} - -void cBody::OnEachConstraint( cConstraint * Constraint, cConstraintIterator * it ) { - if ( it->Func.IsSet() ) { - it->Func( this, Constraint, it->Data ); - } -} - -static void BodyArbiterIteratorFunc( cpBody * body, cpArbiter * arbiter, void * data ) { - cBody::cArbiterIterator * it = reinterpret_cast ( data ); - cArbiter tarb( arbiter ); - it->Body->OnEachArbiter( &tarb, it ); -} - -void cBody::EachArbiter( ArbiterIteratorFunc Func, void * data ) { - cArbiterIterator it( this, data, Func ); - cpBodyEachArbiter( mBody, &BodyArbiterIteratorFunc, (void*)&it ); -} - -void cBody::OnEachArbiter( cArbiter * Arbiter, cArbiterIterator * it ) { - if ( it->Func.IsSet() ) { - it->Func( this, Arbiter, it->Data ); - } -} - -CP_NAMESPACE_END diff --git a/src/eepp/physics/constraints/cconstraint.cpp b/src/eepp/physics/constraints/cconstraint.cpp deleted file mode 100644 index 61b912091..000000000 --- a/src/eepp/physics/constraints/cconstraint.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include - -CP_NAMESPACE_BEGIN - -void cConstraint::Free( cConstraint * constraint ) { - cpSAFE_DELETE( constraint ); -} - -cConstraint::cConstraint( cpConstraint * Constraint ) : - mData( NULL ) -{ - mConstraint = Constraint; - SetData(); -} - -cConstraint::cConstraint() : - mConstraint( NULL ), - mData( NULL ) -{ -} - -cConstraint::~cConstraint() { - cpConstraintFree( mConstraint ); - - cPhysicsManager::instance()->RemoveConstraintFree( this ); -} - -void cConstraint::SetData() { - mConstraint->data = (void*)this; - cPhysicsManager::instance()->AddConstraintFree( this ); -} - -cpConstraint * cConstraint::Constraint() const { - return mConstraint; -} - -cBody * cConstraint::A() { - return reinterpret_cast( mConstraint->a->data ); -} - -cBody * cConstraint::B() { - return reinterpret_cast( mConstraint->b->data ); -} - -cpFloat cConstraint::MaxForce() { - return mConstraint->maxForce; -} - -void cConstraint::MaxForce( const cpFloat& maxforce ) { - mConstraint->maxForce = maxforce; -} - -cpFloat cConstraint::MaxBias() { - return mConstraint->maxBias; -} - -void cConstraint::MaxBias( const cpFloat& maxbias ) { - mConstraint->maxBias = maxbias; -} - -cpFloat cConstraint::ErrorBias() { - return cpConstraintGetErrorBias( mConstraint ); -} - -void cConstraint::ErrorBias( cpFloat value ) { - cpConstraintSetErrorBias( mConstraint, value ); -} - -void cConstraint::Data( void * data ) { - mData = data; -} - -void * cConstraint::Data() const { - return mData; -} - -cpFloat cConstraint::Impulse() { - return cpConstraintGetImpulse( mConstraint ); -} - -void cConstraint::Draw() { -} - -CP_NAMESPACE_END diff --git a/src/eepp/physics/constraints/cdampedrotaryspring.cpp b/src/eepp/physics/constraints/cdampedrotaryspring.cpp deleted file mode 100644 index 77edd1e0b..000000000 --- a/src/eepp/physics/constraints/cdampedrotaryspring.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include - -CP_NAMESPACE_BEGIN - -cDampedRotarySpring::cDampedRotarySpring( cBody * a, cBody * b, cpFloat restAngle, cpFloat stiffness, cpFloat damping ) { - mConstraint = cpDampedRotarySpringNew( a->Body(), b->Body(), restAngle, stiffness, damping ); - SetData(); -} - -cpFloat cDampedRotarySpring::RestAngle() { - return cpDampedRotarySpringGetRestAngle( mConstraint ); -} - -void cDampedRotarySpring::RestAngle( const cpFloat& restangle ) { - cpDampedRotarySpringSetRestAngle( mConstraint, restangle ); -} - -cpFloat cDampedRotarySpring::Stiffness() { - return cpDampedRotarySpringGetStiffness( mConstraint ); -} - -void cDampedRotarySpring::Stiffness( const cpFloat& stiffness ) { - cpDampedRotarySpringSetStiffness( mConstraint, stiffness ); -} - -cpFloat cDampedRotarySpring::Damping() { - return cpDampedRotarySpringGetDamping( mConstraint ); -} - -void cDampedRotarySpring::Damping( const cpFloat& damping ) { - cpDampedRotarySpringSetDamping( mConstraint, damping ); -} - -void cDampedRotarySpring::Draw() { - // Not implemented -} - -CP_NAMESPACE_END diff --git a/src/eepp/physics/constraints/cgearjoint.cpp b/src/eepp/physics/constraints/cgearjoint.cpp deleted file mode 100644 index 945e467a2..000000000 --- a/src/eepp/physics/constraints/cgearjoint.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include - -CP_NAMESPACE_BEGIN - -cGearJoint::cGearJoint( cBody * a, cBody * b, cpFloat phase, cpFloat ratio ) { - mConstraint = cpGearJointNew( a->Body(), b->Body(), phase, ratio ); - SetData(); -} - -cpFloat cGearJoint::Phase() { - return cpGearJointGetPhase( mConstraint ); -} - -void cGearJoint::Phase( const cpFloat& phase ) { - cpGearJointSetPhase( mConstraint, phase ); -} - -cpFloat cGearJoint::Ratio() { - return cpGearJointGetRatio( mConstraint ); -} - -void cGearJoint::Ratio( const cpFloat& ratio ) { - cpGearJointSetRatio( mConstraint, ratio ); -} - -void cGearJoint::Draw() { - // Not implemented -} - -CP_NAMESPACE_END diff --git a/src/eepp/physics/constraints/constraint.cpp b/src/eepp/physics/constraints/constraint.cpp new file mode 100644 index 000000000..8e78c0e81 --- /dev/null +++ b/src/eepp/physics/constraints/constraint.cpp @@ -0,0 +1,85 @@ +#include +#include + +CP_NAMESPACE_BEGIN + +void Constraint::Free( Constraint * constraint ) { + cpSAFE_DELETE( constraint ); +} + +Constraint::Constraint( cpConstraint * Constraint ) : + mData( NULL ) +{ + mConstraint = Constraint; + SetData(); +} + +Constraint::Constraint() : + mConstraint( NULL ), + mData( NULL ) +{ +} + +Constraint::~Constraint() { + cpConstraintFree( mConstraint ); + + PhysicsManager::instance()->RemoveConstraintFree( this ); +} + +void Constraint::SetData() { + mConstraint->data = (void*)this; + PhysicsManager::instance()->AddConstraintFree( this ); +} + +cpConstraint * Constraint::GetConstraint() const { + return mConstraint; +} + +Body * Constraint::A() { + return reinterpret_cast( mConstraint->a->data ); +} + +Body * Constraint::B() { + return reinterpret_cast( mConstraint->b->data ); +} + +cpFloat Constraint::MaxForce() { + return mConstraint->maxForce; +} + +void Constraint::MaxForce( const cpFloat& maxforce ) { + mConstraint->maxForce = maxforce; +} + +cpFloat Constraint::MaxBias() { + return mConstraint->maxBias; +} + +void Constraint::MaxBias( const cpFloat& maxbias ) { + mConstraint->maxBias = maxbias; +} + +cpFloat Constraint::ErrorBias() { + return cpConstraintGetErrorBias( mConstraint ); +} + +void Constraint::ErrorBias( cpFloat value ) { + cpConstraintSetErrorBias( mConstraint, value ); +} + +void Constraint::Data( void * data ) { + mData = data; +} + +void * Constraint::Data() const { + return mData; +} + +cpFloat Constraint::Impulse() { + return cpConstraintGetImpulse( mConstraint ); +} + +void Constraint::Draw() { +} + +CP_NAMESPACE_END diff --git a/src/eepp/physics/constraints/cratchetjoint.cpp b/src/eepp/physics/constraints/cratchetjoint.cpp deleted file mode 100644 index a5cf764c1..000000000 --- a/src/eepp/physics/constraints/cratchetjoint.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include - -CP_NAMESPACE_BEGIN - -cRatchetJoint::cRatchetJoint( cBody * a, cBody * b, cpFloat phase, cpFloat ratchet ) { - mConstraint = cpRatchetJointNew( a->Body(), b->Body(), phase, ratchet ); - SetData(); -} - -cpFloat cRatchetJoint::Angle() { - return cpRatchetJointGetAngle( mConstraint ); -} - -void cRatchetJoint::Angle( const cpFloat& angle ) { - cpRatchetJointSetAngle( mConstraint, angle ); -} - -cpFloat cRatchetJoint::Phase() { - return cpRatchetJointGetPhase( mConstraint ); -} - -void cRatchetJoint::Phase( const cpFloat& phase ) { - cpRatchetJointSetPhase( mConstraint, phase ); -} - -cpFloat cRatchetJoint::Ratchet() { - return cpRatchetJointGetRatchet( mConstraint ); -} - -void cRatchetJoint::Ratchet( const cpFloat& ratchet ) { - cpRatchetJointSetRatchet( mConstraint, ratchet ); -} - -void cRatchetJoint::Draw() { - // Not implemented -} - -CP_NAMESPACE_END diff --git a/src/eepp/physics/constraints/crotarylimitjoint.cpp b/src/eepp/physics/constraints/crotarylimitjoint.cpp deleted file mode 100644 index 88a2fd91b..000000000 --- a/src/eepp/physics/constraints/crotarylimitjoint.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include - -CP_NAMESPACE_BEGIN - -cRotaryLimitJoint::cRotaryLimitJoint( cBody * a, cBody * b, cpFloat min, cpFloat max ) { - mConstraint = cpRotaryLimitJointNew( a->Body(), b->Body(), min, max ); - SetData(); -} - -cpFloat cRotaryLimitJoint::Min() { - return cpRotaryLimitJointGetMin( mConstraint ); -} - -void cRotaryLimitJoint::Min( const cpFloat& min ) { - cpRotaryLimitJointSetMin( mConstraint, min ); -} - -cpFloat cRotaryLimitJoint::Max() { - return cpRotaryLimitJointGetMax( mConstraint ); -} - -void cRotaryLimitJoint::Max( const cpFloat& max ) { - cpRotaryLimitJointSetMax( mConstraint, max ); -} - -void cRotaryLimitJoint::Draw() { - // Not implemented -} - -CP_NAMESPACE_END diff --git a/src/eepp/physics/constraints/csimplemotor.cpp b/src/eepp/physics/constraints/csimplemotor.cpp deleted file mode 100644 index 55d6d1ee2..000000000 --- a/src/eepp/physics/constraints/csimplemotor.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include - -CP_NAMESPACE_BEGIN - -cSimpleMotor::cSimpleMotor( cBody * a, cBody * b, cpFloat rate ) { - mConstraint = cpSimpleMotorNew( a->Body(), b->Body(), rate ); - SetData(); -} - -cpFloat cSimpleMotor::Rate() { - return cpSimpleMotorGetRate( mConstraint ); -} - -void cSimpleMotor::Rate( const cpFloat& rate ) { - cpSimpleMotorSetRate( mConstraint, rate ); -} - -void cSimpleMotor::Draw() { - // Not implemented -} - -CP_NAMESPACE_END diff --git a/src/eepp/physics/constraints/dampedrotaryspring.cpp b/src/eepp/physics/constraints/dampedrotaryspring.cpp new file mode 100644 index 000000000..329dae1b8 --- /dev/null +++ b/src/eepp/physics/constraints/dampedrotaryspring.cpp @@ -0,0 +1,38 @@ +#include + +CP_NAMESPACE_BEGIN + +DampedRotarySpring::DampedRotarySpring( Body * a, Body * b, cpFloat restAngle, cpFloat stiffness, cpFloat damping ) { + mConstraint = cpDampedRotarySpringNew( a->GetBody(), b->GetBody(), restAngle, stiffness, damping ); + SetData(); +} + +cpFloat DampedRotarySpring::RestAngle() { + return cpDampedRotarySpringGetRestAngle( mConstraint ); +} + +void DampedRotarySpring::RestAngle( const cpFloat& restangle ) { + cpDampedRotarySpringSetRestAngle( mConstraint, restangle ); +} + +cpFloat DampedRotarySpring::Stiffness() { + return cpDampedRotarySpringGetStiffness( mConstraint ); +} + +void DampedRotarySpring::Stiffness( const cpFloat& stiffness ) { + cpDampedRotarySpringSetStiffness( mConstraint, stiffness ); +} + +cpFloat DampedRotarySpring::Damping() { + return cpDampedRotarySpringGetDamping( mConstraint ); +} + +void DampedRotarySpring::Damping( const cpFloat& damping ) { + cpDampedRotarySpringSetDamping( mConstraint, damping ); +} + +void DampedRotarySpring::Draw() { + // Not implemented +} + +CP_NAMESPACE_END diff --git a/src/eepp/physics/constraints/cdampedspring.cpp b/src/eepp/physics/constraints/dampedspring.cpp similarity index 75% rename from src/eepp/physics/constraints/cdampedspring.cpp rename to src/eepp/physics/constraints/dampedspring.cpp index 9e4cfeee8..d902dcaab 100644 --- a/src/eepp/physics/constraints/cdampedspring.cpp +++ b/src/eepp/physics/constraints/dampedspring.cpp @@ -1,4 +1,4 @@ -#include +#include #ifdef PHYSICS_RENDERER_ENABLED #include @@ -10,56 +10,56 @@ using namespace EE::Graphics; CP_NAMESPACE_BEGIN -cDampedSpring::cDampedSpring( cBody * a, cBody * b, cVect anchr1, cVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping ) +DampedSpring::DampedSpring( Body * a, Body * b, cVect anchr1, cVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping ) #ifdef PHYSICS_RENDERER_ENABLED : mDrawPointSize( 5.f ) #endif { - mConstraint = cpDampedSpringNew( a->Body(), b->Body(), tocpv( anchr1 ), tocpv( anchr2 ), restLength, stiffness, damping ); + mConstraint = cpDampedSpringNew( a->GetBody(), b->GetBody(), tocpv( anchr1 ), tocpv( anchr2 ), restLength, stiffness, damping ); SetData(); } -cVect cDampedSpring::Anchr1() { +cVect DampedSpring::Anchr1() { return tovect( cpDampedSpringGetAnchr1( mConstraint ) ); } -void cDampedSpring::Anchr1( const cVect& anchr1 ) { +void DampedSpring::Anchr1( const cVect& anchr1 ) { cpDampedSpringSetAnchr1( mConstraint, tocpv( anchr1 ) ); } -cVect cDampedSpring::Anchr2() { +cVect DampedSpring::Anchr2() { return tovect( cpDampedSpringGetAnchr2( mConstraint ) ); } -void cDampedSpring::Anchr2( const cVect& anchr2 ) { +void DampedSpring::Anchr2( const cVect& anchr2 ) { cpDampedSpringSetAnchr2( mConstraint, tocpv( anchr2 ) ); } -cpFloat cDampedSpring::RestLength() { +cpFloat DampedSpring::RestLength() { return cpDampedSpringGetRestLength( mConstraint ); } -void cDampedSpring::RestLength( const cpFloat& restlength ) { +void DampedSpring::RestLength( const cpFloat& restlength ) { cpDampedSpringSetRestLength( mConstraint, restlength ); } -cpFloat cDampedSpring::Stiffness() { +cpFloat DampedSpring::Stiffness() { return cpDampedSpringGetStiffness( mConstraint ); } -void cDampedSpring::Stiffness( const cpFloat& stiffness ) { +void DampedSpring::Stiffness( const cpFloat& stiffness ) { cpDampedSpringSetStiffness( mConstraint, stiffness ); } -cpFloat cDampedSpring::Damping() { +cpFloat DampedSpring::Damping() { return cpDampedSpringGetDamping( mConstraint ); } -void cDampedSpring::Damping( const cpFloat& damping ) { +void DampedSpring::Damping( const cpFloat& damping ) { cpDampedSpringSetDamping( mConstraint, damping ); } -void cDampedSpring::Draw() { +void DampedSpring::Draw() { #ifdef PHYSICS_RENDERER_ENABLED static const float springVAR[] = { 0.00f, 0.0f, @@ -135,11 +135,11 @@ void cDampedSpring::Draw() { #ifdef PHYSICS_RENDERER_ENABLED -cpFloat cDampedSpring::DrawPointSize() { +cpFloat DampedSpring::DrawPointSize() { return mDrawPointSize; } -void cDampedSpring::DrawPointSize( const cpFloat& size ) { +void DampedSpring::DrawPointSize( const cpFloat& size ) { mDrawPointSize = size; } #endif diff --git a/src/eepp/physics/constraints/gearjoint.cpp b/src/eepp/physics/constraints/gearjoint.cpp new file mode 100644 index 000000000..fb7876279 --- /dev/null +++ b/src/eepp/physics/constraints/gearjoint.cpp @@ -0,0 +1,30 @@ +#include + +CP_NAMESPACE_BEGIN + +GearJoint::GearJoint( Body * a, Body * b, cpFloat phase, cpFloat ratio ) { + mConstraint = cpGearJointNew( a->GetBody(), b->GetBody(), phase, ratio ); + SetData(); +} + +cpFloat GearJoint::Phase() { + return cpGearJointGetPhase( mConstraint ); +} + +void GearJoint::Phase( const cpFloat& phase ) { + cpGearJointSetPhase( mConstraint, phase ); +} + +cpFloat GearJoint::Ratio() { + return cpGearJointGetRatio( mConstraint ); +} + +void GearJoint::Ratio( const cpFloat& ratio ) { + cpGearJointSetRatio( mConstraint, ratio ); +} + +void GearJoint::Draw() { + // Not implemented +} + +CP_NAMESPACE_END diff --git a/src/eepp/physics/constraints/cgroovejoint.cpp b/src/eepp/physics/constraints/groovejoint.cpp similarity index 70% rename from src/eepp/physics/constraints/cgroovejoint.cpp rename to src/eepp/physics/constraints/groovejoint.cpp index e71e739fa..37e8fa7ff 100644 --- a/src/eepp/physics/constraints/cgroovejoint.cpp +++ b/src/eepp/physics/constraints/groovejoint.cpp @@ -1,4 +1,4 @@ -#include +#include #ifdef PHYSICS_RENDERER_ENABLED #include @@ -7,40 +7,40 @@ using namespace EE::Graphics; CP_NAMESPACE_BEGIN -cGrooveJoint::cGrooveJoint( cBody * a, cBody * b, cVect groove_a, cVect groove_b, cVect anchr2 ) +GrooveJoint::GrooveJoint( Body * a, Body * b, cVect groove_a, cVect groove_b, cVect anchr2 ) #ifdef PHYSICS_RENDERER_ENABLED : mDrawPointSize( 5.f ) #endif { - mConstraint = cpGrooveJointNew( a->Body(), b->Body(), tocpv( groove_a ), tocpv( groove_b ), tocpv( anchr2 ) ); + mConstraint = cpGrooveJointNew( a->GetBody(), b->GetBody(), tocpv( groove_a ), tocpv( groove_b ), tocpv( anchr2 ) ); SetData(); } -cVect cGrooveJoint::Anchr2() { +cVect GrooveJoint::Anchr2() { return tovect( cpGrooveJointGetAnchr2( mConstraint ) ); } -void cGrooveJoint::Anchr2( const cVect& anchr2 ) { +void GrooveJoint::Anchr2( const cVect& anchr2 ) { cpGrooveJointSetAnchr2( mConstraint, tocpv( anchr2 ) ); } -cVect cGrooveJoint::GrooveA() { +cVect GrooveJoint::GrooveA() { return tovect( cpGrooveJointGetGrooveA( mConstraint ) ); } -void cGrooveJoint::GrooveA( const cVect& groove_a ) { +void GrooveJoint::GrooveA( const cVect& groove_a ) { cpGrooveJointSetGrooveA( mConstraint, tocpv( groove_a ) ); } -cVect cGrooveJoint::GrooveB() { +cVect GrooveJoint::GrooveB() { return tovect( cpGrooveJointGetGrooveB( mConstraint ) ); } -void cGrooveJoint::GrooveB( const cVect& groove_b ) { +void GrooveJoint::GrooveB( const cVect& groove_b ) { cpGrooveJointSetGrooveB( mConstraint, tocpv( groove_b ) ); } -void cGrooveJoint::Draw() { +void GrooveJoint::Draw() { #ifdef PHYSICS_RENDERER_ENABLED if ( mDrawPointSize <= 0 ) return; @@ -69,11 +69,11 @@ void cGrooveJoint::Draw() { } #ifdef PHYSICS_RENDERER_ENABLED -cpFloat cGrooveJoint::DrawPointSize() { +cpFloat GrooveJoint::DrawPointSize() { return mDrawPointSize; } -void cGrooveJoint::DrawPointSize( const cpFloat& size ) { +void GrooveJoint::DrawPointSize( const cpFloat& size ) { mDrawPointSize = size; } #endif diff --git a/src/eepp/physics/constraints/cpinjoint.cpp b/src/eepp/physics/constraints/pinjoint.cpp similarity index 72% rename from src/eepp/physics/constraints/cpinjoint.cpp rename to src/eepp/physics/constraints/pinjoint.cpp index b01464620..39ac92abc 100644 --- a/src/eepp/physics/constraints/cpinjoint.cpp +++ b/src/eepp/physics/constraints/pinjoint.cpp @@ -1,4 +1,4 @@ -#include +#include #ifdef PHYSICS_RENDERER_ENABLED #include @@ -7,40 +7,40 @@ using namespace EE::Graphics; CP_NAMESPACE_BEGIN -cPinJoint::cPinJoint( cBody * a, cBody * b, cVect anchr1, cVect anchr2 ) +PinJoint::PinJoint( Body * a, Body * b, cVect anchr1, cVect anchr2 ) #ifdef PHYSICS_RENDERER_ENABLED : mDrawPointSize( 5.f ) #endif { - mConstraint = cpPinJointNew( a->Body(), b->Body(), tocpv( anchr1 ), tocpv( anchr2 ) ); + mConstraint = cpPinJointNew( a->GetBody(), b->GetBody(), tocpv( anchr1 ), tocpv( anchr2 ) ); SetData(); } -cVect cPinJoint::Anchr1() { +cVect PinJoint::Anchr1() { return tovect( cpPinJointGetAnchr1( mConstraint ) ); } -void cPinJoint::Anchr1( const cVect& anchr1 ) { +void PinJoint::Anchr1( const cVect& anchr1 ) { cpPinJointSetAnchr1( mConstraint, tocpv( anchr1 ) ); } -cVect cPinJoint::Anchr2() { +cVect PinJoint::Anchr2() { return tovect( cpPinJointGetAnchr2( mConstraint ) ); } -void cPinJoint::Anchr2( const cVect& anchr2 ) { +void PinJoint::Anchr2( const cVect& anchr2 ) { cpPinJointSetAnchr2( mConstraint, tocpv( anchr2 ) ); } -cpFloat cPinJoint::Dist() { +cpFloat PinJoint::Dist() { return cpPinJointGetDist( mConstraint ); } -void cPinJoint::Dist( const cpFloat& dist ) { +void PinJoint::Dist( const cpFloat& dist ) { cpPinJointSetDist( mConstraint, dist ); } -void cPinJoint::Draw() { +void PinJoint::Draw() { #ifdef PHYSICS_RENDERER_ENABLED if ( mDrawPointSize <= 0 ) return; @@ -71,11 +71,11 @@ void cPinJoint::Draw() { } #ifdef PHYSICS_RENDERER_ENABLED -cpFloat cPinJoint::DrawPointSize() { +cpFloat PinJoint::DrawPointSize() { return mDrawPointSize; } -void cPinJoint::DrawPointSize( const cpFloat& size ) { +void PinJoint::DrawPointSize( const cpFloat& size ) { mDrawPointSize = size; } #endif diff --git a/src/eepp/physics/constraints/cpivotjoint.cpp b/src/eepp/physics/constraints/pivotjoint.cpp similarity index 67% rename from src/eepp/physics/constraints/cpivotjoint.cpp rename to src/eepp/physics/constraints/pivotjoint.cpp index edc351582..57ffff160 100644 --- a/src/eepp/physics/constraints/cpivotjoint.cpp +++ b/src/eepp/physics/constraints/pivotjoint.cpp @@ -1,4 +1,4 @@ -#include +#include #ifdef PHYSICS_RENDERER_ENABLED #include @@ -7,41 +7,41 @@ using namespace EE::Graphics; CP_NAMESPACE_BEGIN -cPivotJoint::cPivotJoint( cBody * a, cBody * b, cVect pivot ) +PivotJoint::PivotJoint( Body * a, Body * b, cVect pivot ) #ifdef PHYSICS_RENDERER_ENABLED : mDrawPointSize( 10.f ) #endif { - mConstraint = cpPivotJointNew( a->Body(), b->Body(), tocpv( pivot ) ); + mConstraint = cpPivotJointNew( a->GetBody(), b->GetBody(), tocpv( pivot ) ); SetData(); } -cPivotJoint::cPivotJoint( cBody * a, cBody * b, cVect anchr1, cVect anchr2 ) +PivotJoint::PivotJoint( Body * a, Body * b, cVect anchr1, cVect anchr2 ) #ifdef PHYSICS_RENDERER_ENABLED : mDrawPointSize( 10.f ) #endif { - mConstraint = cpPivotJointNew2( a->Body(), b->Body(), tocpv( anchr1 ), tocpv( anchr2 ) ); + mConstraint = cpPivotJointNew2( a->GetBody(), b->GetBody(), tocpv( anchr1 ), tocpv( anchr2 ) ); SetData(); } -cVect cPivotJoint::Anchr1() { +cVect PivotJoint::Anchr1() { return tovect( cpPivotJointGetAnchr1( mConstraint ) ); } -void cPivotJoint::Anchr1( const cVect& anchr1 ) { +void PivotJoint::Anchr1( const cVect& anchr1 ) { cpPivotJointSetAnchr1( mConstraint, tocpv( anchr1 ) ); } -cVect cPivotJoint::Anchr2() { +cVect PivotJoint::Anchr2() { return tovect( cpPivotJointGetAnchr2( mConstraint ) ); } -void cPivotJoint::Anchr2( const cVect& anchr2 ) { +void PivotJoint::Anchr2( const cVect& anchr2 ) { cpPivotJointSetAnchr2( mConstraint, tocpv( anchr2 ) ); } -void cPivotJoint::Draw() { +void PivotJoint::Draw() { #ifdef PHYSICS_RENDERER_ENABLED if ( mDrawPointSize <= 0 ) return; @@ -66,11 +66,11 @@ void cPivotJoint::Draw() { } #ifdef PHYSICS_RENDERER_ENABLED -cpFloat cPivotJoint::DrawPointSize() { +cpFloat PivotJoint::DrawPointSize() { return mDrawPointSize; } -void cPivotJoint::DrawPointSize( const cpFloat& size ) { +void PivotJoint::DrawPointSize( const cpFloat& size ) { mDrawPointSize = size; } #endif diff --git a/src/eepp/physics/constraints/ratchetjoint.cpp b/src/eepp/physics/constraints/ratchetjoint.cpp new file mode 100644 index 000000000..73623b425 --- /dev/null +++ b/src/eepp/physics/constraints/ratchetjoint.cpp @@ -0,0 +1,38 @@ +#include + +CP_NAMESPACE_BEGIN + +RatchetJoint::RatchetJoint( Body * a, Body * b, cpFloat phase, cpFloat ratchet ) { + mConstraint = cpRatchetJointNew( a->GetBody(), b->GetBody(), phase, ratchet ); + SetData(); +} + +cpFloat RatchetJoint::Angle() { + return cpRatchetJointGetAngle( mConstraint ); +} + +void RatchetJoint::Angle( const cpFloat& angle ) { + cpRatchetJointSetAngle( mConstraint, angle ); +} + +cpFloat RatchetJoint::Phase() { + return cpRatchetJointGetPhase( mConstraint ); +} + +void RatchetJoint::Phase( const cpFloat& phase ) { + cpRatchetJointSetPhase( mConstraint, phase ); +} + +cpFloat RatchetJoint::Ratchet() { + return cpRatchetJointGetRatchet( mConstraint ); +} + +void RatchetJoint::Ratchet( const cpFloat& ratchet ) { + cpRatchetJointSetRatchet( mConstraint, ratchet ); +} + +void RatchetJoint::Draw() { + // Not implemented +} + +CP_NAMESPACE_END diff --git a/src/eepp/physics/constraints/rotarylimitjoint.cpp b/src/eepp/physics/constraints/rotarylimitjoint.cpp new file mode 100644 index 000000000..462b60276 --- /dev/null +++ b/src/eepp/physics/constraints/rotarylimitjoint.cpp @@ -0,0 +1,30 @@ +#include + +CP_NAMESPACE_BEGIN + +RotaryLimitJoint::RotaryLimitJoint( Body * a, Body * b, cpFloat min, cpFloat max ) { + mConstraint = cpRotaryLimitJointNew( a->GetBody(), b->GetBody(), min, max ); + SetData(); +} + +cpFloat RotaryLimitJoint::Min() { + return cpRotaryLimitJointGetMin( mConstraint ); +} + +void RotaryLimitJoint::Min( const cpFloat& min ) { + cpRotaryLimitJointSetMin( mConstraint, min ); +} + +cpFloat RotaryLimitJoint::Max() { + return cpRotaryLimitJointGetMax( mConstraint ); +} + +void RotaryLimitJoint::Max( const cpFloat& max ) { + cpRotaryLimitJointSetMax( mConstraint, max ); +} + +void RotaryLimitJoint::Draw() { + // Not implemented +} + +CP_NAMESPACE_END diff --git a/src/eepp/physics/constraints/simplemotor.cpp b/src/eepp/physics/constraints/simplemotor.cpp new file mode 100644 index 000000000..7ad9ef899 --- /dev/null +++ b/src/eepp/physics/constraints/simplemotor.cpp @@ -0,0 +1,22 @@ +#include + +CP_NAMESPACE_BEGIN + +SimpleMotor::SimpleMotor( Body * a, Body * b, cpFloat rate ) { + mConstraint = cpSimpleMotorNew( a->GetBody(), b->GetBody(), rate ); + SetData(); +} + +cpFloat SimpleMotor::Rate() { + return cpSimpleMotorGetRate( mConstraint ); +} + +void SimpleMotor::Rate( const cpFloat& rate ) { + cpSimpleMotorSetRate( mConstraint, rate ); +} + +void SimpleMotor::Draw() { + // Not implemented +} + +CP_NAMESPACE_END diff --git a/src/eepp/physics/constraints/cslidejoint.cpp b/src/eepp/physics/constraints/slidejoint.cpp similarity index 68% rename from src/eepp/physics/constraints/cslidejoint.cpp rename to src/eepp/physics/constraints/slidejoint.cpp index a35753429..2b2d6d3f4 100644 --- a/src/eepp/physics/constraints/cslidejoint.cpp +++ b/src/eepp/physics/constraints/slidejoint.cpp @@ -1,4 +1,4 @@ -#include +#include #ifdef PHYSICS_RENDERER_ENABLED #include @@ -7,48 +7,48 @@ using namespace EE::Graphics; CP_NAMESPACE_BEGIN -cSlideJoint::cSlideJoint( cBody * a, cBody *b, cVect anchr1, cVect anchr2, cpFloat min, cpFloat max ) +SlideJoint::SlideJoint( Body * a, Body *b, cVect anchr1, cVect anchr2, cpFloat min, cpFloat max ) #ifdef PHYSICS_RENDERER_ENABLED : mDrawPointSize( 5.f ) #endif { - mConstraint = cpSlideJointNew( a->Body(), b->Body(), tocpv( anchr1 ), tocpv( anchr2 ), min, max ); + mConstraint = cpSlideJointNew( a->GetBody(), b->GetBody(), tocpv( anchr1 ), tocpv( anchr2 ), min, max ); SetData(); } -cVect cSlideJoint::Anchr1() { +cVect SlideJoint::Anchr1() { return tovect( cpSlideJointGetAnchr1( mConstraint ) ); } -void cSlideJoint::Anchr1( const cVect& anchr1 ) { +void SlideJoint::Anchr1( const cVect& anchr1 ) { cpSlideJointSetAnchr1( mConstraint, tocpv( anchr1 ) ); } -cVect cSlideJoint::Anchr2() { +cVect SlideJoint::Anchr2() { return tovect( cpSlideJointGetAnchr2( mConstraint ) ); } -void cSlideJoint::Anchr2( const cVect& anchr2 ) { +void SlideJoint::Anchr2( const cVect& anchr2 ) { cpSlideJointSetAnchr2( mConstraint, tocpv( anchr2 ) ); } -cpFloat cSlideJoint::Min() { +cpFloat SlideJoint::Min() { return cpSlideJointGetMin( mConstraint ); } -void cSlideJoint::Min( const cpFloat& min ) { +void SlideJoint::Min( const cpFloat& min ) { cpSlideJointSetMin( mConstraint, min ); } -cpFloat cSlideJoint::Max() { +cpFloat SlideJoint::Max() { return cpSlideJointGetMax( mConstraint ); } -void cSlideJoint::Max( const cpFloat& max ) { +void SlideJoint::Max( const cpFloat& max ) { cpSlideJointSetMax( mConstraint, max ); } -void cSlideJoint::Draw() { +void SlideJoint::Draw() { #ifdef PHYSICS_RENDERER_ENABLED if ( mDrawPointSize <= 0 ) return; @@ -77,11 +77,11 @@ void cSlideJoint::Draw() { } #ifdef PHYSICS_RENDERER_ENABLED -cpFloat cSlideJoint::DrawPointSize() { +cpFloat SlideJoint::DrawPointSize() { return mDrawPointSize; } -void cSlideJoint::DrawPointSize( const cpFloat& size ) { +void SlideJoint::DrawPointSize( const cpFloat& size ) { mDrawPointSize = size; } #endif diff --git a/src/eepp/physics/cshape.cpp b/src/eepp/physics/cshape.cpp deleted file mode 100644 index f2457bdfb..000000000 --- a/src/eepp/physics/cshape.cpp +++ /dev/null @@ -1,195 +0,0 @@ -#include -#include -#include -#include -#include - -#ifdef PHYSICS_RENDERER_ENABLED -#include -using namespace EE::Graphics; -#endif - -CP_NAMESPACE_BEGIN - -void cShape::ResetShapeIdCounter() { - cpResetShapeIdCounter(); -} - -void cShape::Free( cShape * shape, bool DeleteBody ) { - if ( DeleteBody ) { - cBody * b = shape->Body(); - cpSAFE_DELETE( b ); - } - - cpSAFE_DELETE( shape ); -} - -cShape::cShape() : - mData( NULL ) -{ -} - -cShape::~cShape() { - cpShapeFree( mShape ); - - cPhysicsManager::instance()->RemoveShapeFree( this ); -} - -void cShape::SetData() { - mShape->data = (void*)this; - cPhysicsManager::instance()->AddShapeFree( this ); -} - -cpShape * cShape::Shape() const { - return mShape; -} - -cBB cShape::CacheBB() { - return tocbb( cpShapeCacheBB( mShape ) ); -} - -cBB cShape::Update( cVect pos, cVect rot ) { - return tocbb( cpShapeUpdate( mShape, tocpv( pos ), tocpv( rot ) ) ); -} - -bool cShape::PointQuery( cVect p ) { - return 0 != cpShapePointQuery( mShape, tocpv( p ) ); -} - -cBody * cShape::Body() const { - return reinterpret_cast( mShape->body->data ); -} - -void cShape::Body( cBody * body ) { - mShape->body = body->Body(); -} - -cBB cShape::BB() const { - return tocbb( mShape->bb ); -} - -void cShape::BB( const cBB& bb ) { - mShape->bb = tocpbb( bb ); -} - -bool cShape::Sensor() { - return 0 != mShape->sensor; -} - -void cShape::Sensor( const bool& sensor ) { - mShape->sensor = sensor ? 1 : 0; -} - -cpFloat cShape::e() const { - return mShape->e; -} - -void cShape::e( const cpFloat& e ) { - mShape->e = e; -} - -cpFloat cShape::Elasticity() const { - return e(); -} - -void cShape::Elasticity( const cpFloat& e ) { - this->e( e ); -} - -cpFloat cShape::u() const { - return mShape->u; -} - -void cShape::u( const cpFloat& u ) { - mShape->u = u; -} - -cpFloat cShape::Friction() const { - return u(); -} - -void cShape::Friction( const cpFloat& u ) { - this->u( u ); -} - -cVect cShape::SurfaceVel() const { - return tovect( mShape->surface_v ); -} - -void cShape::SurfaceVel( const cVect& vel ) { - mShape->surface_v = tocpv( vel ); -} - -cpCollisionType cShape::CollisionType() const { - return mShape->collision_type; -} - -void cShape::CollisionType( const cpCollisionType& type ) { - mShape->collision_type = type; -} - -cpGroup cShape::Group() const { - return mShape->group; -} - -void cShape::Group( const cpGroup& group ) { - mShape->group = group; -} - -cpLayers cShape::Layers() const { - return mShape->layers; -} - -void cShape::Layers( const cpLayers& layers ) { - mShape->layers = layers; -} - -cpShapeType cShape::Type() const { - return mShape->CP_PRIVATE(klass)->type; -} - -cShapePoly * cShape::GetAsPoly() { - eeASSERT( Type() == CP_POLY_SHAPE ); - - return reinterpret_cast( this ); -} - -cShapeCircle * cShape::GetAsCircle() { - eeASSERT( Type() == CP_CIRCLE_SHAPE ); - - return reinterpret_cast( this ); -} - -cShapeSegment * cShape::GetAsSegment() { - eeASSERT( Type() == CP_SEGMENT_SHAPE ); - - return reinterpret_cast( this ); -} - -void cShape::DrawBB() { - #ifdef PHYSICS_RENDERER_ENABLED - Primitives P; - P.SetColor( ColorA( 76, 128, 76, 255 ) ); - P.ForceDraw( false ); - P.DrawLine( Line2f( Vector2f( mShape->bb.l, mShape->bb.t ), Vector2f( mShape->bb.r, mShape->bb.t ) ) ); - P.DrawLine( Line2f( Vector2f( mShape->bb.l, mShape->bb.t ), Vector2f( mShape->bb.l, mShape->bb.b ) ) ); - P.DrawLine( Line2f( Vector2f( mShape->bb.l, mShape->bb.b ), Vector2f( mShape->bb.r, mShape->bb.b ) ) ); - P.DrawLine( Line2f( Vector2f( mShape->bb.r, mShape->bb.t ), Vector2f( mShape->bb.r, mShape->bb.b ) ) ); - #endif -} - -void * cShape::Data() const { - return mData; -} - -void cShape::Data( void * data ) { - mData = data; -} - -void cShape::Draw( cSpace * space ) { -} - -void cShape::DrawBorder( cSpace * space ) { -} - -CP_NAMESPACE_END diff --git a/src/eepp/physics/cshapecirclesprite.cpp b/src/eepp/physics/cshapecirclesprite.cpp deleted file mode 100644 index c4113bbdc..000000000 --- a/src/eepp/physics/cshapecirclesprite.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include - -#ifdef PHYSICS_RENDERER_ENABLED - -#include - -CP_NAMESPACE_BEGIN - -cShapeCircleSprite * cShapeCircleSprite::New( cBody * body, cpFloat radius, cVect offset, Sprite * Sprite, bool AutoDeleteSprite ) { - return cpNew( cShapeCircleSprite, ( body, radius, offset, Sprite, AutoDeleteSprite ) ); -} - -cShapeCircleSprite::cShapeCircleSprite( cBody * body, cpFloat radius, cVect offset, Sprite * Sprite, bool AutoDeleteSprite ) : - cShapeCircle( body, radius, offset ), - mSprite( Sprite ), - mSpriteAutoDelete( AutoDeleteSprite ) -{ - OffsetSet(); -} - -cShapeCircleSprite::~cShapeCircleSprite() { - if ( mSpriteAutoDelete ) - eeSAFE_DELETE( mSprite ); -} - -void cShapeCircleSprite::Draw( cSpace * space ) { - cVect Pos = Body()->Pos(); - - mSprite->Position( Pos.x, Pos.y ); - mSprite->Angle( Body()->AngleDeg() ); - mSprite->Draw(); -} - -void cShapeCircleSprite::OffsetSet() { - mSprite->Size( Sizef( cShapeCircle::Radius() * 2, cShapeCircle::Radius() * 2 ) ); - mSprite->Offset( Vector2i( -cShapeCircle::Radius() + cShapeCircle::Offset().x, -cShapeCircle::Radius() + cShapeCircle::Offset().y ) ); -} - -Sprite * cShapeCircleSprite::GetSprite() const { - return mSprite; -} - -void cShapeCircleSprite::Radius( const cpFloat& radius ) { - cShapeCircle::Radius( radius ); - OffsetSet(); -} - -void cShapeCircleSprite::Offset( const cVect &offset ) { - cShapeCircle::Offset( offset ); - OffsetSet(); -} - -CP_NAMESPACE_END - -#endif diff --git a/src/eepp/physics/cphysicsmanager.cpp b/src/eepp/physics/physicsmanager.cpp similarity index 53% rename from src/eepp/physics/cphysicsmanager.cpp rename to src/eepp/physics/physicsmanager.cpp index a171f9a10..46f711db5 100644 --- a/src/eepp/physics/cphysicsmanager.cpp +++ b/src/eepp/physics/physicsmanager.cpp @@ -1,100 +1,100 @@ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include CP_NAMESPACE_BEGIN -SINGLETON_DECLARE_IMPLEMENTATION(cPhysicsManager) +SINGLETON_DECLARE_IMPLEMENTATION(PhysicsManager) -cPhysicsManager::cPhysicsManager() : +PhysicsManager::PhysicsManager() : mMemoryManager( false ) { } -cPhysicsManager::~cPhysicsManager() { +PhysicsManager::~PhysicsManager() { if ( mMemoryManager ) { mMemoryManager = false; - std::list::iterator its = mSpaces.begin(); + std::list::iterator its = mSpaces.begin(); for ( ; its != mSpaces.end(); its++ ) cpSAFE_DELETE( *its ); - std::list::iterator itb = mBodysFree.begin(); + std::list::iterator itb = mBodysFree.begin(); for ( ; itb != mBodysFree.end(); itb++ ) cpSAFE_DELETE( *itb ); - std::list::iterator itp = mShapesFree.begin(); + std::list::iterator itp = mShapesFree.begin(); for ( ; itp != mShapesFree.end(); itp++ ) cpSAFE_DELETE( *itp ); - std::list::iterator itc = mConstraintFree.begin(); + std::list::iterator itc = mConstraintFree.begin(); for ( ; itc != mConstraintFree.end(); itc++ ) cpSAFE_DELETE( *itc ); } } -cPhysicsManager::cDrawSpaceOptions * cPhysicsManager::GetDrawOptions() { +PhysicsManager::cDrawSpaceOptions * PhysicsManager::GetDrawOptions() { return &mOptions; } -void cPhysicsManager::MemoryManager( bool MemoryManager ) { +void PhysicsManager::MemoryManager( bool MemoryManager ) { mMemoryManager = MemoryManager; } -const bool& cPhysicsManager::MemoryManager() const { +const bool& PhysicsManager::MemoryManager() const { return mMemoryManager; } -void cPhysicsManager::AddBodyFree( cBody * body ) { +void PhysicsManager::AddBodyFree( Body * body ) { if ( mMemoryManager ) { if ( std::find( mBodysFree.begin(), mBodysFree.end(), body ) == mBodysFree.end() ) mBodysFree.push_back( body ); } } -void cPhysicsManager::RemoveBodyFree( cBody * body ) { +void PhysicsManager::RemoveBodyFree( Body * body ) { if ( mMemoryManager ) { mBodysFree.remove( body ); } } -void cPhysicsManager::AddShapeFree( cShape * shape ) { +void PhysicsManager::AddShapeFree( Shape * shape ) { if ( mMemoryManager ) { if ( std::find( mShapesFree.begin(), mShapesFree.end(), shape ) == mShapesFree.end() ) mShapesFree.push_back( shape ); } } -void cPhysicsManager::RemoveShapeFree( cShape * shape ) { +void PhysicsManager::RemoveShapeFree( Shape * shape ) { if ( mMemoryManager ) { mShapesFree.remove( shape ); } } -void cPhysicsManager::AddConstraintFree( cConstraint * constraint ) { +void PhysicsManager::AddConstraintFree( Constraint * constraint ) { if ( mMemoryManager ) { if ( std::find( mConstraintFree.begin(), mConstraintFree.end(), constraint ) == mConstraintFree.end() ) mConstraintFree.push_back( constraint ); } } -void cPhysicsManager::RemoveConstraintFree( cConstraint * constraint ) { +void PhysicsManager::RemoveConstraintFree( Constraint * constraint ) { if ( mMemoryManager ) { mConstraintFree.remove( constraint ); } } -void cPhysicsManager::AddSpace( cSpace * space ) { +void PhysicsManager::AddSpace( Space * space ) { if ( mMemoryManager ) { if ( std::find( mSpaces.begin(), mSpaces.end(), space ) == mSpaces.end() ) mSpaces.push_back( space ); } } -void cPhysicsManager::RemoveSpace( cSpace * space ) { +void PhysicsManager::RemoveSpace( Space * space ) { if ( mMemoryManager ) { mSpaces.remove( space ); } diff --git a/src/eepp/physics/shape.cpp b/src/eepp/physics/shape.cpp new file mode 100644 index 000000000..e366f40a4 --- /dev/null +++ b/src/eepp/physics/shape.cpp @@ -0,0 +1,195 @@ +#include +#include +#include +#include +#include + +#ifdef PHYSICS_RENDERER_ENABLED +#include +using namespace EE::Graphics; +#endif + +CP_NAMESPACE_BEGIN + +void Shape::ResetShapeIdCounter() { + cpResetShapeIdCounter(); +} + +void Shape::Free( Shape * shape, bool DeleteBody ) { + if ( DeleteBody ) { + Physics::Body * b = shape->Body(); + cpSAFE_DELETE( b ); + } + + cpSAFE_DELETE( shape ); +} + +Shape::Shape() : + mData( NULL ) +{ +} + +Shape::~Shape() { + cpShapeFree( mShape ); + + PhysicsManager::instance()->RemoveShapeFree( this ); +} + +void Shape::SetData() { + mShape->data = (void*)this; + PhysicsManager::instance()->AddShapeFree( this ); +} + +cpShape * Shape::GetShape() const { + return mShape; +} + +cBB Shape::CacheBB() { + return tocbb( cpShapeCacheBB( mShape ) ); +} + +cBB Shape::Update( cVect pos, cVect rot ) { + return tocbb( cpShapeUpdate( mShape, tocpv( pos ), tocpv( rot ) ) ); +} + +bool Shape::PointQuery( cVect p ) { + return 0 != cpShapePointQuery( mShape, tocpv( p ) ); +} + +Physics::Body * Shape::Body() const { + return reinterpret_cast( mShape->body->data ); +} + +void Shape::Body( Physics::Body * body ) { + mShape->body = body->GetBody(); +} + +cBB Shape::BB() const { + return tocbb( mShape->bb ); +} + +void Shape::BB( const cBB& bb ) { + mShape->bb = tocpbb( bb ); +} + +bool Shape::Sensor() { + return 0 != mShape->sensor; +} + +void Shape::Sensor( const bool& sensor ) { + mShape->sensor = sensor ? 1 : 0; +} + +cpFloat Shape::e() const { + return mShape->e; +} + +void Shape::e( const cpFloat& e ) { + mShape->e = e; +} + +cpFloat Shape::Elasticity() const { + return e(); +} + +void Shape::Elasticity( const cpFloat& e ) { + this->e( e ); +} + +cpFloat Shape::u() const { + return mShape->u; +} + +void Shape::u( const cpFloat& u ) { + mShape->u = u; +} + +cpFloat Shape::Friction() const { + return u(); +} + +void Shape::Friction( const cpFloat& u ) { + this->u( u ); +} + +cVect Shape::SurfaceVel() const { + return tovect( mShape->surface_v ); +} + +void Shape::SurfaceVel( const cVect& vel ) { + mShape->surface_v = tocpv( vel ); +} + +cpCollisionType Shape::CollisionType() const { + return mShape->collision_type; +} + +void Shape::CollisionType( const cpCollisionType& type ) { + mShape->collision_type = type; +} + +cpGroup Shape::Group() const { + return mShape->group; +} + +void Shape::Group( const cpGroup& group ) { + mShape->group = group; +} + +cpLayers Shape::Layers() const { + return mShape->layers; +} + +void Shape::Layers( const cpLayers& layers ) { + mShape->layers = layers; +} + +cpShapeType Shape::Type() const { + return mShape->CP_PRIVATE(klass)->type; +} + +ShapePoly * Shape::GetAsPoly() { + eeASSERT( Type() == CP_POLY_SHAPE ); + + return reinterpret_cast( this ); +} + +ShapeCircle * Shape::GetAsCircle() { + eeASSERT( Type() == CP_CIRCLE_SHAPE ); + + return reinterpret_cast( this ); +} + +ShapeSegment * Shape::GetAsSegment() { + eeASSERT( Type() == CP_SEGMENT_SHAPE ); + + return reinterpret_cast( this ); +} + +void Shape::DrawBB() { + #ifdef PHYSICS_RENDERER_ENABLED + Primitives P; + P.SetColor( ColorA( 76, 128, 76, 255 ) ); + P.ForceDraw( false ); + P.DrawLine( Line2f( Vector2f( mShape->bb.l, mShape->bb.t ), Vector2f( mShape->bb.r, mShape->bb.t ) ) ); + P.DrawLine( Line2f( Vector2f( mShape->bb.l, mShape->bb.t ), Vector2f( mShape->bb.l, mShape->bb.b ) ) ); + P.DrawLine( Line2f( Vector2f( mShape->bb.l, mShape->bb.b ), Vector2f( mShape->bb.r, mShape->bb.b ) ) ); + P.DrawLine( Line2f( Vector2f( mShape->bb.r, mShape->bb.t ), Vector2f( mShape->bb.r, mShape->bb.b ) ) ); + #endif +} + +void * Shape::Data() const { + return mData; +} + +void Shape::Data( void * data ) { + mData = data; +} + +void Shape::Draw( Space * space ) { +} + +void Shape::DrawBorder( Space * space ) { +} + +CP_NAMESPACE_END diff --git a/src/eepp/physics/cshapecircle.cpp b/src/eepp/physics/shapecircle.cpp similarity index 52% rename from src/eepp/physics/cshapecircle.cpp rename to src/eepp/physics/shapecircle.cpp index 61759384a..379f0bf8b 100644 --- a/src/eepp/physics/cshapecircle.cpp +++ b/src/eepp/physics/shapecircle.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #ifdef PHYSICS_RENDERER_ENABLED @@ -10,38 +10,38 @@ using namespace EE::Graphics; CP_NAMESPACE_BEGIN -cShapeCircle * cShapeCircle::New( cBody * body, cpFloat radius, cVect offset ) { - return cpNew( cShapeCircle, ( body, radius, offset ) ); +ShapeCircle * ShapeCircle::New( Physics::Body * body, cpFloat radius, cVect offset ) { + return cpNew( ShapeCircle, ( body, radius, offset ) ); } -cShapeCircle::cShapeCircle( cBody * body, cpFloat radius, cVect offset ) { - mShape = cpCircleShapeNew( body->Body(), radius, tocpv( offset ) ); +ShapeCircle::ShapeCircle( Physics::Body * body, cpFloat radius, cVect offset ) { + mShape = cpCircleShapeNew( body->GetBody(), radius, tocpv( offset ) ); SetData(); } -cVect cShapeCircle::Offset() { +cVect ShapeCircle::Offset() { return tovect( cpCircleShapeGetOffset( mShape ) ); } -void cShapeCircle::Offset( const cVect &offset ) { +void ShapeCircle::Offset( const cVect &offset ) { cpCircleShapeSetOffset( mShape, tocpv( offset ) ); } -cpFloat cShapeCircle::Radius() { +cpFloat ShapeCircle::Radius() { return cpCircleShapeGetRadius( mShape ); } -void cShapeCircle::Radius( const cpFloat& radius ) { +void ShapeCircle::Radius( const cpFloat& radius ) { cpCircleShapeSetRadius( mShape, radius ); } -void cShapeCircle::Draw( cSpace * space ) { +void ShapeCircle::Draw( Space * space ) { #ifdef PHYSICS_RENDERER_ENABLED Primitives p; cpCircleShape * cs = (cpCircleShape*)mShape; - p.SetColor( ColorForShape( mShape, space->Space() ) ); + p.SetColor( ColorForShape( mShape, space->GetSpace() ) ); p.DrawCircle( Vector2f( cs->CP_PRIVATE(tc).x, cs->CP_PRIVATE(tc).y ), cs->CP_PRIVATE(r) ); #endif diff --git a/src/eepp/physics/shapecirclesprite.cpp b/src/eepp/physics/shapecirclesprite.cpp new file mode 100644 index 000000000..608082959 --- /dev/null +++ b/src/eepp/physics/shapecirclesprite.cpp @@ -0,0 +1,55 @@ +#include + +#ifdef PHYSICS_RENDERER_ENABLED + +#include + +CP_NAMESPACE_BEGIN + +ShapeCircleSprite * ShapeCircleSprite::New( Physics::Body * body, cpFloat radius, cVect offset, Sprite * Sprite, bool AutoDeleteSprite ) { + return cpNew( ShapeCircleSprite, ( body, radius, offset, Sprite, AutoDeleteSprite ) ); +} + +ShapeCircleSprite::ShapeCircleSprite( Physics::Body * body, cpFloat radius, cVect offset, Sprite * Sprite, bool AutoDeleteSprite ) : + ShapeCircle( body, radius, offset ), + mSprite( Sprite ), + mSpriteAutoDelete( AutoDeleteSprite ) +{ + OffsetSet(); +} + +ShapeCircleSprite::~ShapeCircleSprite() { + if ( mSpriteAutoDelete ) + eeSAFE_DELETE( mSprite ); +} + +void ShapeCircleSprite::Draw( Space * space ) { + cVect Pos = Body()->Pos(); + + mSprite->Position( Pos.x, Pos.y ); + mSprite->Angle( Body()->AngleDeg() ); + mSprite->Draw(); +} + +void ShapeCircleSprite::OffsetSet() { + mSprite->Size( Sizef( ShapeCircle::Radius() * 2, ShapeCircle::Radius() * 2 ) ); + mSprite->Offset( Vector2i( -ShapeCircle::Radius() + ShapeCircle::Offset().x, -ShapeCircle::Radius() + ShapeCircle::Offset().y ) ); +} + +Sprite * ShapeCircleSprite::GetSprite() const { + return mSprite; +} + +void ShapeCircleSprite::Radius( const cpFloat& radius ) { + ShapeCircle::Radius( radius ); + OffsetSet(); +} + +void ShapeCircleSprite::Offset( const cVect &offset ) { + ShapeCircle::Offset( offset ); + OffsetSet(); +} + +CP_NAMESPACE_END + +#endif diff --git a/src/eepp/physics/cshapepoint.cpp b/src/eepp/physics/shapepoint.cpp similarity index 56% rename from src/eepp/physics/cshapepoint.cpp rename to src/eepp/physics/shapepoint.cpp index 2d467abd7..050518fdd 100644 --- a/src/eepp/physics/cshapepoint.cpp +++ b/src/eepp/physics/shapepoint.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #ifdef PHYSICS_RENDERER_ENABLED @@ -10,36 +10,36 @@ using namespace EE::Graphics; CP_NAMESPACE_BEGIN -cShapePoint * cShapePoint::New( cBody * body, cpFloat radius, cVect offset ) { - return cpNew( cShapePoint, ( body, radius, offset ) ); +ShapePoint * ShapePoint::New( Physics::Body * body, cpFloat radius, cVect offset ) { + return cpNew( ShapePoint, ( body, radius, offset ) ); } -cShapePoint::cShapePoint( cBody * body, cpFloat radius, cVect offset ) +ShapePoint::ShapePoint( Physics::Body * body, cpFloat radius, cVect offset ) #ifdef PHYSICS_RENDERER_ENABLED : mDrawRadius( radius ) #endif { - mShape = cpCircleShapeNew( body->Body(), radius, tocpv( offset ) ); + mShape = cpCircleShapeNew( body->GetBody(), radius, tocpv( offset ) ); SetData(); } -cVect cShapePoint::Offset() { +cVect ShapePoint::Offset() { return tovect( cpCircleShapeGetOffset( mShape ) ); } -void cShapePoint::Offset( const cVect &offset ) { +void ShapePoint::Offset( const cVect &offset ) { cpCircleShapeSetOffset( mShape, tocpv( offset ) ); } -cpFloat cShapePoint::Radius() { +cpFloat ShapePoint::Radius() { return cpCircleShapeGetRadius( mShape ); } -void cShapePoint::Radius( const cpFloat& radius ) { +void ShapePoint::Radius( const cpFloat& radius ) { cpCircleShapeSetRadius( mShape, radius ); } -void cShapePoint::Draw( cSpace * space ) { +void ShapePoint::Draw( Space * space ) { #ifdef PHYSICS_RENDERER_ENABLED BatchRenderer * BR = GlobalBatchRenderer::instance(); @@ -47,7 +47,7 @@ void cShapePoint::Draw( cSpace * space ) { BR->SetTexture( NULL ); BR->PointsBegin(); - BR->PointSetColor( ColorForShape( mShape, space->Space() ) ); + BR->PointSetColor( ColorForShape( mShape, space->GetSpace() ) ); cpCircleShape * cs = (cpCircleShape*)mShape; @@ -58,11 +58,11 @@ void cShapePoint::Draw( cSpace * space ) { } #ifdef PHYSICS_RENDERER_ENABLED -cpFloat cShapePoint::DrawRadius() { +cpFloat ShapePoint::DrawRadius() { return mDrawRadius; } -void cShapePoint::DrawRadius( const cpFloat& radius ) { +void ShapePoint::DrawRadius( const cpFloat& radius ) { mDrawRadius = radius; } #endif diff --git a/src/eepp/physics/cshapepoly.cpp b/src/eepp/physics/shapepoly.cpp similarity index 60% rename from src/eepp/physics/cshapepoly.cpp rename to src/eepp/physics/shapepoly.cpp index a315e78fb..5f85d9362 100644 --- a/src/eepp/physics/cshapepoly.cpp +++ b/src/eepp/physics/shapepoly.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #ifdef PHYSICS_RENDERER_ENABLED @@ -9,51 +9,51 @@ using namespace EE::Graphics; CP_NAMESPACE_BEGIN -cShapePoly * cShapePoly::New( cBody * body, int numVerts, cVect *verts, cVect offset ) { - return cpNew( cShapePoly, ( body, numVerts, verts, offset ) ); +ShapePoly * ShapePoly::New( Physics::Body * body, int numVerts, cVect *verts, cVect offset ) { + return cpNew( ShapePoly, ( body, numVerts, verts, offset ) ); } -cShapePoly * cShapePoly::New( cBody * body, cpFloat width, cpFloat height ) { - return cpNew( cShapePoly, ( body, width, height ) ); +ShapePoly * ShapePoly::New( Physics::Body * body, cpFloat width, cpFloat height ) { + return cpNew( ShapePoly, ( body, width, height ) ); } -cShapePoly::cShapePoly( cBody * body, int numVerts, cVect *verts, cVect offset ) { - mShape = cpPolyShapeNew( body->Body(), numVerts, casttocpv( verts ), tocpv( offset ) ); +ShapePoly::ShapePoly( Physics::Body * body, int numVerts, cVect *verts, cVect offset ) { + mShape = cpPolyShapeNew( body->GetBody(), numVerts, casttocpv( verts ), tocpv( offset ) ); SetData(); } -cShapePoly::cShapePoly( cBody * body, cpFloat width, cpFloat height ) : - cShape() +ShapePoly::ShapePoly( Physics::Body * body, cpFloat width, cpFloat height ) : + Shape() { - mShape = cpBoxShapeNew( body->Body(), width, height ); + mShape = cpBoxShapeNew( body->GetBody(), width, height ); SetData(); } -bool cShapePoly::Validate( const cVect * verts, const int numVerts ) { +bool ShapePoly::Validate( const cVect * verts, const int numVerts ) { return 0 != cpPolyValidate( constcasttocpv( verts ), numVerts ); } -int cShapePoly::GetNumVerts() { +int ShapePoly::GetNumVerts() { return cpPolyShapeGetNumVerts( mShape ); } -cVect cShapePoly::GetVert( int idx ) { +cVect ShapePoly::GetVert( int idx ) { return tovect( cpPolyShapeGetVert( mShape, idx ) ); } -void cShapePoly::SetVerts( int numVerts, cVect *verts, cVect offset ) { +void ShapePoly::SetVerts( int numVerts, cVect *verts, cVect offset ) { cpPolyShapeSetVerts( mShape, numVerts, casttocpv( verts ), tocpv( offset ) ); } -void cShapePoly::Recenter( int numVerts, cVect *verts ) { +void ShapePoly::Recenter( int numVerts, cVect *verts ) { cpRecenterPoly( numVerts, casttocpv( verts ) ); } -cVect cShapePoly::Centroid( int numVerts, const cVect * verts ) { +cVect ShapePoly::Centroid( int numVerts, const cVect * verts ) { return tovect( cpCentroidForPoly( numVerts, constcasttocpv( verts ) ) ); } -void cShapePoly::Draw( cSpace * space ) { +void ShapePoly::Draw( Space * space ) { #ifdef PHYSICS_RENDERER_ENABLED cpPolyShape * poly = (cpPolyShape*)mShape; @@ -61,7 +61,7 @@ void cShapePoly::Draw( cSpace * space ) { BR->SetTexture( NULL ); - ColorA Col = ColorForShape( (cpShape *)poly, space->Space() ); + ColorA Col = ColorForShape( (cpShape *)poly, space->GetSpace() ); if( !poly->CP_PRIVATE(shape).sensor ){ if ( 4 != poly->CP_PRIVATE(numVerts) ) { @@ -85,13 +85,13 @@ void cShapePoly::Draw( cSpace * space ) { #endif } -void cShapePoly::DrawBorder( cSpace *space ) { +void ShapePoly::DrawBorder( Space *space ) { #ifdef PHYSICS_RENDERER_ENABLED cpPolyShape * poly = (cpPolyShape*)mShape; BatchRenderer * BR = GlobalBatchRenderer::instance(); - ColorA Col = ColorForShape( (cpShape *)poly, space->Space() ); + ColorA Col = ColorForShape( (cpShape *)poly, space->GetSpace() ); BR->LineLoopBegin(); BR->LineLoopSetColor( Col ); diff --git a/src/eepp/physics/cshapepolysprite.cpp b/src/eepp/physics/shapepolysprite.cpp similarity index 51% rename from src/eepp/physics/cshapepolysprite.cpp rename to src/eepp/physics/shapepolysprite.cpp index 6d0b0b835..f4b312a7d 100644 --- a/src/eepp/physics/cshapepolysprite.cpp +++ b/src/eepp/physics/shapepolysprite.cpp @@ -1,4 +1,4 @@ -#include +#include #ifdef PHYSICS_RENDERER_ENABLED @@ -6,24 +6,24 @@ CP_NAMESPACE_BEGIN -cShapePolySprite * cShapePolySprite::New( cBody * body, int numVerts, cVect *verts, cVect offset, Sprite * Sprite, bool AutoDeleteSprite ) { - return cpNew( cShapePolySprite, ( body, numVerts, verts, offset, Sprite, AutoDeleteSprite ) ); +ShapePolySprite * ShapePolySprite::New( Physics::Body * body, int numVerts, cVect *verts, cVect offset, Sprite * Sprite, bool AutoDeleteSprite ) { + return cpNew( ShapePolySprite, ( body, numVerts, verts, offset, Sprite, AutoDeleteSprite ) ); } -cShapePolySprite * cShapePolySprite::New( cBody * body, cpFloat width, cpFloat height, Sprite * Sprite, bool AutoDeleteSprite ) { - return cpNew( cShapePolySprite, ( body, width, height, Sprite, AutoDeleteSprite ) ); +ShapePolySprite * ShapePolySprite::New( Physics::Body * body, cpFloat width, cpFloat height, Sprite * Sprite, bool AutoDeleteSprite ) { + return cpNew( ShapePolySprite, ( body, width, height, Sprite, AutoDeleteSprite ) ); } -cShapePolySprite::cShapePolySprite( cBody * body, int numVerts, cVect *verts, cVect offset, Sprite * Sprite, bool AutoDeleteSprite ) : - cShapePoly( body, numVerts, verts, offset ), +ShapePolySprite::ShapePolySprite( Physics::Body * body, int numVerts, cVect *verts, cVect offset, Sprite * Sprite, bool AutoDeleteSprite ) : + ShapePoly( body, numVerts, verts, offset ), mSprite( Sprite ), mSpriteAutoDelete( AutoDeleteSprite ) { OffsetSet( Centroid( numVerts, verts ) ); } -cShapePolySprite::cShapePolySprite( cBody * body, cpFloat width, cpFloat height, Sprite * Sprite, bool AutoDeleteSprite ) : - cShapePoly( body, width, height ), +ShapePolySprite::ShapePolySprite( Physics::Body * body, cpFloat width, cpFloat height, Sprite * Sprite, bool AutoDeleteSprite ) : + ShapePoly( body, width, height ), mSprite( Sprite ), mSpriteAutoDelete( AutoDeleteSprite ) { @@ -31,12 +31,12 @@ cShapePolySprite::cShapePolySprite( cBody * body, cpFloat width, cpFloat height, OffsetSet( cVectNew( width / 2, height / 2 ) ); } -cShapePolySprite::~cShapePolySprite() { +ShapePolySprite::~ShapePolySprite() { if ( mSpriteAutoDelete ) eeSAFE_DELETE( mSprite ); } -void cShapePolySprite::Draw( cSpace * space ) { +void ShapePolySprite::Draw( Space * space ) { cVect Pos = Body()->Pos(); mSprite->Offset( mOffset ); @@ -45,13 +45,13 @@ void cShapePolySprite::Draw( cSpace * space ) { mSprite->Draw(); } -void cShapePolySprite::OffsetSet( cVect center ) { +void ShapePolySprite::OffsetSet( cVect center ) { cVect myCenter = cVectNew( ( mSprite->Size().x / 2 ), ( mSprite->Size().y / 2 ) ); mOffset = Vector2i( (Int32)( -myCenter.x + ( center.x - myCenter.x ) ) , (Int32)( -myCenter.y + ( center.y - myCenter.y ) ) ); } -Sprite * cShapePolySprite::GetSprite() const { +Sprite * ShapePolySprite::GetSprite() const { return mSprite; } diff --git a/src/eepp/physics/cshapesegment.cpp b/src/eepp/physics/shapesegment.cpp similarity index 77% rename from src/eepp/physics/cshapesegment.cpp rename to src/eepp/physics/shapesegment.cpp index ea07a4bd9..09122309e 100644 --- a/src/eepp/physics/cshapesegment.cpp +++ b/src/eepp/physics/shapesegment.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #ifdef PHYSICS_RENDERER_ENABLED @@ -11,52 +11,52 @@ using namespace EE::Graphics; CP_NAMESPACE_BEGIN -cShapeSegment * cShapeSegment::New( cBody * body, cVect a, cVect b, cpFloat radius ) { - return cpNew( cShapeSegment, ( body, a, b, radius ) ); +ShapeSegment * ShapeSegment::New( Physics::Body * body, cVect a, cVect b, cpFloat radius ) { + return cpNew( ShapeSegment, ( body, a, b, radius ) ); } -cShapeSegment::cShapeSegment( cBody * body, cVect a, cVect b, cpFloat radius ) { - mShape = cpSegmentShapeNew( body->Body(), tocpv( a ), tocpv( b ), radius ); +ShapeSegment::ShapeSegment( Physics::Body * body, cVect a, cVect b, cpFloat radius ) { + mShape = cpSegmentShapeNew( body->GetBody(), tocpv( a ), tocpv( b ), radius ); SetData(); } -cVect cShapeSegment::A() { +cVect ShapeSegment::A() { return tovect( cpSegmentShapeGetA( mShape ) ); } -cVect cShapeSegment::B() { +cVect ShapeSegment::B() { return tovect( cpSegmentShapeGetB( mShape ) ); } -cVect cShapeSegment::Normal() { +cVect ShapeSegment::Normal() { return tovect( cpSegmentShapeGetNormal( mShape ) ); } -cpFloat cShapeSegment::Radius() { +cpFloat ShapeSegment::Radius() { return cpSegmentShapeGetRadius( mShape ); } -void cShapeSegment::Radius( const cpFloat& radius ) { +void ShapeSegment::Radius( const cpFloat& radius ) { cpSegmentShapeSetRadius( mShape, radius ); } -void cShapeSegment::Endpoints( const cVect& a, const cVect& b ) { +void ShapeSegment::Endpoints( const cVect& a, const cVect& b ) { cpSegmentShapeSetEndpoints( mShape, tocpv( a ), tocpv( b ) ); } -bool cShapeSegment::Query( cVect a, cVect b, cpSegmentQueryInfo * info ) { +bool ShapeSegment::Query( cVect a, cVect b, cpSegmentQueryInfo * info ) { return 0 != cpShapeSegmentQuery( mShape, tocpv( a ), tocpv( b ), info ); } -cVect cShapeSegment::QueryHitPoint( const cVect start, const cVect end, const cpSegmentQueryInfo info ) { +cVect ShapeSegment::QueryHitPoint( const cVect start, const cVect end, const cpSegmentQueryInfo info ) { return tovect( cpSegmentQueryHitPoint( tocpv( start ), tocpv( end ), info ) ); } -cpFloat cShapeSegment::QueryHitDist( const cVect start, const cVect end, const cpSegmentQueryInfo info ) { +cpFloat ShapeSegment::QueryHitDist( const cVect start, const cVect end, const cpSegmentQueryInfo info ) { return cpSegmentQueryHitDist( tocpv( start ), tocpv( end ), info ); } -void cShapeSegment::Draw( cSpace * space ) { +void ShapeSegment::Draw( Space * space ) { #ifdef PHYSICS_RENDERER_ENABLED static const float pillVAR[] = { 0.0000f, 1.0000f, 1.0f, @@ -116,7 +116,7 @@ void cShapeSegment::Draw( cSpace * space ) { GLi->VertexPointer( 3, GL_FLOAT, 0, pillVAR, pillVAR_count * sizeof(float) * 3 ); if( !seg->CP_PRIVATE(shape).sensor ) { - ColorA C = ColorForShape( mShape, space->Space() ); + ColorA C = ColorForShape( mShape, space->GetSpace() ); tcolors.assign( tcolors.size(), C ); diff --git a/src/eepp/physics/cspace.cpp b/src/eepp/physics/space.cpp similarity index 59% rename from src/eepp/physics/cspace.cpp rename to src/eepp/physics/space.cpp index db81f1480..eee43212d 100644 --- a/src/eepp/physics/cspace.cpp +++ b/src/eepp/physics/space.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #ifdef PHYSICS_RENDERER_ENABLED #include @@ -9,60 +9,60 @@ using namespace EE::Graphics; CP_NAMESPACE_BEGIN -cSpace * cSpace::New() { - return cpNew( cSpace, () ); +Space * Space::New() { + return cpNew( Space, () ); } -void cSpace::Free( cSpace * space ) { +void Space::Free( Space * space ) { cpSAFE_DELETE( space ); } -cSpace::cSpace() : +Space::Space() : mData( NULL ) { mSpace = cpSpaceNew(); mSpace->data = (void*)this; - mStaticBody = cpNew( cBody, ( mSpace->staticBody ) ); + mStatiBody = cpNew( Body, ( mSpace->staticBody ) ); - cPhysicsManager::instance()->RemoveBodyFree( mStaticBody ); - cPhysicsManager::instance()->AddSpace( this ); + PhysicsManager::instance()->RemoveBodyFree( mStatiBody ); + PhysicsManager::instance()->AddSpace( this ); } -cSpace::~cSpace() { +Space::~Space() { cpSpaceFree( mSpace ); - std::list::iterator itc = mConstraints.begin(); + std::list::iterator itc = mConstraints.begin(); for ( ; itc != mConstraints.end(); itc++ ) cpSAFE_DELETE( *itc ); - std::list::iterator its = mShapes.begin(); + std::list::iterator its = mShapes.begin(); for ( ; its != mShapes.end(); its++ ) cpSAFE_DELETE( *its ); - std::list::iterator itb = mBodys.begin(); + std::list::iterator itb = mBodys.begin(); for ( ; itb != mBodys.end(); itb++ ) cpSAFE_DELETE( *itb ); - mStaticBody->mBody = NULL; // The body has been released by cpSpaceFree( mSpace ) + mStatiBody->mBody = NULL; // The body has been released by cpSpaceFree( mSpace ) - cpSAFE_DELETE( mStaticBody ); + cpSAFE_DELETE( mStatiBody ); - cPhysicsManager::instance()->RemoveSpace( this ); + PhysicsManager::instance()->RemoveSpace( this ); } -void cSpace::Data( void * data ) { +void Space::Data( void * data ) { mData = data; } -void * cSpace::Data() const { +void * Space::Data() const { return mData; } -void cSpace::Step( const cpFloat& dt ) { +void Space::Step( const cpFloat& dt ) { cpSpaceStep( mSpace, dt ); } -void cSpace::Update() { +void Space::Update() { #ifdef PHYSICS_RENDERER_ENABLED Step( Window::Engine::instance()->Elapsed().AsSeconds() ); #else @@ -70,227 +70,227 @@ void cSpace::Update() { #endif } -const int& cSpace::Iterations() const { +const int& Space::Iterations() const { return mSpace->iterations; } -void cSpace::Iterations( const int& iterations ) { +void Space::Iterations( const int& iterations ) { mSpace->iterations = iterations; } -cVect cSpace::Gravity() const { +cVect Space::Gravity() const { return tovect( mSpace->gravity ); } -void cSpace::Gravity( const cVect& gravity ) { +void Space::Gravity( const cVect& gravity ) { mSpace->gravity = tocpv( gravity ); } -const cpFloat& cSpace::Damping() const { +const cpFloat& Space::Damping() const { return mSpace->damping; } -void cSpace::Damping( const cpFloat& damping ) { +void Space::Damping( const cpFloat& damping ) { mSpace->damping = damping; } -const cpFloat& cSpace::IdleSpeedThreshold() const { +const cpFloat& Space::IdleSpeedThreshold() const { return mSpace->idleSpeedThreshold; } -void cSpace::IdleSpeedThreshold( const cpFloat& idleSpeedThreshold ) { +void Space::IdleSpeedThreshold( const cpFloat& idleSpeedThreshold ) { mSpace->idleSpeedThreshold = idleSpeedThreshold; } -const cpFloat& cSpace::SleepTimeThreshold() const { +const cpFloat& Space::SleepTimeThreshold() const { return mSpace->sleepTimeThreshold; } -void cSpace::SleepTimeThreshold( const cpFloat& sleepTimeThreshold ) { +void Space::SleepTimeThreshold( const cpFloat& sleepTimeThreshold ) { mSpace->sleepTimeThreshold = sleepTimeThreshold; } -void cSpace::CollisionSlop( cpFloat slop ) { +void Space::CollisionSlop( cpFloat slop ) { mSpace->collisionSlop = slop; } -cpFloat cSpace::CollisionSlop() const { +cpFloat Space::CollisionSlop() const { return mSpace->collisionSlop; } -void cSpace::CollisionBias( cpFloat bias ) { +void Space::CollisionBias( cpFloat bias ) { mSpace->collisionBias = bias; } -cpFloat cSpace::CollisionBias() const { +cpFloat Space::CollisionBias() const { return mSpace->collisionBias; } -cpTimestamp cSpace::CollisionPersistence() { +cpTimestamp Space::CollisionPersistence() { return cpSpaceGetCollisionPersistence( mSpace ); } -void cSpace::CollisionPersistence( cpTimestamp value ) { +void Space::CollisionPersistence( cpTimestamp value ) { cpSpaceSetCollisionPersistence( mSpace, value ); } -bool cSpace::EnableContactGraph() { +bool Space::EnableContactGraph() { return cpTrue == cpSpaceGetEnableContactGraph( mSpace ); } -void cSpace::EnableContactGraph( bool value ) { +void Space::EnableContactGraph( bool value ) { cpSpaceSetEnableContactGraph( mSpace, value ); } -cBody * cSpace::StaticBody() const { - return mStaticBody; +Body * Space::StatiBody() const { + return mStatiBody; } -bool cSpace::Contains( cShape * shape ) { - return cpTrue == cpSpaceContainsShape( mSpace, shape->Shape() ); +bool Space::Contains( Shape * shape ) { + return cpTrue == cpSpaceContainsShape( mSpace, shape->GetShape() ); } -bool cSpace::Contains( cBody * body ) { - return cpTrue == cpSpaceContainsBody( mSpace, body->Body() ); +bool Space::Contains( Body * body ) { + return cpTrue == cpSpaceContainsBody( mSpace, body->GetBody() ); } -bool cSpace::Contains( cConstraint * constraint ) { - return cpTrue == cpSpaceContainsConstraint( mSpace, constraint->Constraint() ); +bool Space::Contains( Constraint * constraint ) { + return cpTrue == cpSpaceContainsConstraint( mSpace, constraint->GetConstraint() ); } -cShape * cSpace::AddShape( cShape * shape ) { - cpSpaceAddShape( mSpace, shape->Shape() ); +Shape * Space::AddShape( Shape * shape ) { + cpSpaceAddShape( mSpace, shape->GetShape() ); mShapes.push_back( shape ); - cPhysicsManager::instance()->RemoveShapeFree( shape ); + PhysicsManager::instance()->RemoveShapeFree( shape ); return shape; } -cShape * cSpace::AddStaticShape( cShape * shape ) { - cpSpaceAddStaticShape( mSpace, shape->Shape() ); +Shape * Space::AddStatiShape( Shape * shape ) { + cpSpaceAddStaticShape( mSpace, shape->GetShape() ); mShapes.push_back( shape ); - cPhysicsManager::instance()->RemoveShapeFree( shape ); + PhysicsManager::instance()->RemoveShapeFree( shape ); return shape; } -cBody * cSpace::AddBody( cBody * body ) { - cpSpaceAddBody( mSpace, body->Body() ); +Body * Space::AddBody( Body * body ) { + cpSpaceAddBody( mSpace, body->GetBody() ); mBodys.push_back( body ); - cPhysicsManager::instance()->RemoveBodyFree( body ); + PhysicsManager::instance()->RemoveBodyFree( body ); return body; } -cConstraint * cSpace::AddConstraint( cConstraint * constraint ) { - cpSpaceAddConstraint( mSpace, constraint->Constraint() ); +Constraint * Space::AddConstraint( Constraint * constraint ) { + cpSpaceAddConstraint( mSpace, constraint->GetConstraint() ); mConstraints.push_back( constraint ); - cPhysicsManager::instance()->RemoveConstraintFree( constraint ); + PhysicsManager::instance()->RemoveConstraintFree( constraint ); return constraint; } -void cSpace::RemoveShape( cShape * shape ) { +void Space::RemoveShape( Shape * shape ) { if ( NULL != shape ) { - cpSpaceRemoveShape( mSpace, shape->Shape() ); + cpSpaceRemoveShape( mSpace, shape->GetShape() ); mShapes.remove( shape ); - cPhysicsManager::instance()->AddShapeFree( shape ); + PhysicsManager::instance()->AddShapeFree( shape ); } } -void cSpace::RemoveStaticShape( cShape * shape ) { +void Space::RemoveStatiShape( Shape * shape ) { if ( NULL != shape ) { - cpSpaceRemoveStaticShape( mSpace, shape->Shape() ); + cpSpaceRemoveStaticShape( mSpace, shape->GetShape() ); mShapes.remove( shape ); - cPhysicsManager::instance()->AddShapeFree( shape ); + PhysicsManager::instance()->AddShapeFree( shape ); } } -void cSpace::RemoveBody( cBody * body ) { +void Space::RemoveBody( Body * body ) { if ( NULL != body ) { - cpSpaceRemoveBody( mSpace, body->Body() ); + cpSpaceRemoveBody( mSpace, body->GetBody() ); mBodys.remove( body ); - cPhysicsManager::instance()->RemoveBodyFree( body ); + PhysicsManager::instance()->RemoveBodyFree( body ); } } -void cSpace::RemoveConstraint( cConstraint * constraint ) { +void Space::RemoveConstraint( Constraint * constraint ) { if ( NULL != constraint ) { - cpSpaceRemoveConstraint( mSpace, constraint->Constraint() ); + cpSpaceRemoveConstraint( mSpace, constraint->GetConstraint() ); mConstraints.remove( constraint ); - cPhysicsManager::instance()->AddConstraintFree( constraint ); + PhysicsManager::instance()->AddConstraintFree( constraint ); } } -cShape * cSpace::PointQueryFirst( cVect point, cpLayers layers, cpGroup group ) { +Shape * Space::PointQueryFirst( cVect point, cpLayers layers, cpGroup group ) { cpShape * shape = cpSpacePointQueryFirst( mSpace, tocpv( point ), layers, group ); if ( NULL != shape ) { - return reinterpret_cast ( shape->data ); + return reinterpret_cast ( shape->data ); } return NULL; } -cShape * cSpace::SegmentQueryFirst( cVect start, cVect end, cpLayers layers, cpGroup group, cpSegmentQueryInfo * out ) { +Shape * Space::SegmentQueryFirst( cVect start, cVect end, cpLayers layers, cpGroup group, cpSegmentQueryInfo * out ) { cpShape * shape = cpSpaceSegmentQueryFirst( mSpace, tocpv( start ), tocpv( end ), layers, group, out ); if ( NULL != shape ) { - return reinterpret_cast ( shape->data ); + return reinterpret_cast ( shape->data ); } return NULL; } -cpSpace * cSpace::Space() const { +cpSpace * Space::GetSpace() const { return mSpace; } -void cSpace::ActivateShapesTouchingShape( cShape * shape ) { - cpSpaceActivateShapesTouchingShape( mSpace, shape->Shape() ); +void Space::ActivateShapesTouchingShape( Shape * shape ) { + cpSpaceActivateShapesTouchingShape( mSpace, shape->GetShape() ); } #ifdef PHYSICS_RENDERER_ENABLED static void drawObject( cpShape * shape, cpSpace * space ) { - reinterpret_cast ( shape->data )->Draw( reinterpret_cast( space->data ) ); + reinterpret_cast ( shape->data )->Draw( reinterpret_cast( space->data ) ); } static void drawObjectBorder( cpShape * shape, cpSpace * space ) { - reinterpret_cast ( shape->data )->DrawBorder( reinterpret_cast( space->data ) ); + reinterpret_cast ( shape->data )->DrawBorder( reinterpret_cast( space->data ) ); } static void drawBB( cpShape *shape, void * unused ) { - reinterpret_cast ( shape->data )->DrawBB(); + reinterpret_cast ( shape->data )->DrawBB(); } static void drawConstraint( cpConstraint *constraint ) { - reinterpret_cast ( constraint->data )->Draw(); + reinterpret_cast ( constraint->data )->Draw(); } #endif -void cSpace::Draw() { +void Space::Draw() { #ifdef PHYSICS_RENDERER_ENABLED BatchRenderer * BR = GlobalBatchRenderer::instance(); BR->SetBlendMode( ALPHA_NORMAL ); - cPhysicsManager::cDrawSpaceOptions * options = cPhysicsManager::instance()->GetDrawOptions(); + PhysicsManager::cDrawSpaceOptions * options = PhysicsManager::instance()->GetDrawOptions(); cpFloat lw = BR->GetLineWidth(); cpFloat ps = BR->GetPointSize(); @@ -365,58 +365,58 @@ void cSpace::Draw() { /** Collision Handling */ static cpBool RecieverCollisionBeginFunc( cpArbiter * arb, cpSpace * space, void * data ) { - cSpace * tspace = reinterpret_cast( space->data ); - cArbiter tarb( arb ); + Space * tspace = reinterpret_cast( space->data ); + Arbiter tarb( arb ); return tspace->OnCollisionBegin( &tarb, data ); } static cpBool RecieverCollisionPreSolveFunc( cpArbiter * arb, cpSpace * space, void * data ) { - cSpace * tspace = reinterpret_cast( space->data ); - cArbiter tarb( arb ); + Space * tspace = reinterpret_cast( space->data ); + Arbiter tarb( arb ); return tspace->OnCollisionPreSolve( &tarb, data ); } static void RecieverCollisionPostSolve( cpArbiter * arb, cpSpace * space, void * data ) { - cSpace * tspace = reinterpret_cast( space->data ); - cArbiter tarb( arb ); + Space * tspace = reinterpret_cast( space->data ); + Arbiter tarb( arb ); tspace->OnCollisionPostSolve( &tarb, data ); } static void RecieverCollisionSeparateFunc( cpArbiter * arb, cpSpace * space, void * data ) { - cSpace * tspace = reinterpret_cast( space->data ); - cArbiter tarb( arb ); + Space * tspace = reinterpret_cast( space->data ); + Arbiter tarb( arb ); tspace->OnCollisionSeparate( &tarb, data ); } static void RecieverPostStepCallback( cpSpace * space, void * obj, void * data ) { - cSpace * tspace = reinterpret_cast( space->data ); + Space * tspace = reinterpret_cast( space->data ); tspace->OnPostStepCallback( obj, data ); } static void RecieverBBQueryFunc( cpShape * shape, void * data ) { - cSpace::cBBQuery * query = reinterpret_cast( data ); + Space::cBBQuery * query = reinterpret_cast( data ); - query->Space->OnBBQuery( reinterpret_cast( shape->data ), query ); + query->Space->OnBBQuery( reinterpret_cast( shape->data ), query ); } static void RecieverSegmentQueryFunc( cpShape *shape, cpFloat t, cpVect n, void * data ) { - cSpace::cSegmentQuery * query = reinterpret_cast( data ); + Space::cSegmentQuery * query = reinterpret_cast( data ); - query->Space->OnSegmentQuery( reinterpret_cast( shape->data ), t, tovect( n ), query ); + query->Space->OnSegmentQuery( reinterpret_cast( shape->data ), t, tovect( n ), query ); } static void RecieverPointQueryFunc( cpShape * shape, void * data ) { - cSpace::cPointQuery * query = reinterpret_cast( data ); + Space::cPointQuery * query = reinterpret_cast( data ); - query->Space->OnPointQuery( reinterpret_cast( shape->data ), query ); + query->Space->OnPointQuery( reinterpret_cast( shape->data ), query ); } -cpBool cSpace::OnCollisionBegin( cArbiter * arb, void * data ) { +cpBool Space::OnCollisionBegin( Arbiter * arb, void * data ) { cpHashValue hash = (cpHashValue)data; //if ( NULL != data ) { @@ -435,7 +435,7 @@ cpBool cSpace::OnCollisionBegin( cArbiter * arb, void * data ) { return 1; } -cpBool cSpace::OnCollisionPreSolve( cArbiter * arb, void * data ) { +cpBool Space::OnCollisionPreSolve( Arbiter * arb, void * data ) { cpHashValue hash = (cpHashValue)data; //if ( NULL != data ) { @@ -454,7 +454,7 @@ cpBool cSpace::OnCollisionPreSolve( cArbiter * arb, void * data ) { return 1; } -void cSpace::OnCollisionPostSolve( cArbiter * arb, void * data ) { +void Space::OnCollisionPostSolve( Arbiter * arb, void * data ) { cpHashValue hash = (cpHashValue)data; //if ( NULL != data ) { @@ -472,7 +472,7 @@ void cSpace::OnCollisionPostSolve( cArbiter * arb, void * data ) { } } -void cSpace::OnCollisionSeparate( cArbiter * arb, void * data ) { +void Space::OnCollisionSeparate( Arbiter * arb, void * data ) { cpHashValue hash = (cpHashValue)data; //if ( NULL != data ) { @@ -490,7 +490,7 @@ void cSpace::OnCollisionSeparate( cArbiter * arb, void * data ) { } } -void cSpace::OnPostStepCallback( void * obj, void * data ) { +void Space::OnPostStepCallback( void * obj, void * data ) { cPostStepCallback * Cb = reinterpret_cast ( data ); if ( Cb->Callback.IsSet() ) { @@ -501,25 +501,25 @@ void cSpace::OnPostStepCallback( void * obj, void * data ) { cpSAFE_DELETE( Cb ); } -void cSpace::OnBBQuery( cShape * shape, cBBQuery * query ) { +void Space::OnBBQuery( Shape * shape, cBBQuery * query ) { if ( query->Func.IsSet() ) { query->Func( shape, query->Data ); } } -void cSpace::OnSegmentQuery( cShape * shape, cpFloat t, cVect n , cSegmentQuery * query ) { +void Space::OnSegmentQuery( Shape * shape, cpFloat t, cVect n , cSegmentQuery * query ) { if ( query->Func.IsSet() ) { query->Func( shape, t, n, query->Data ); } } -void cSpace::OnPointQuery( cShape * shape, cPointQuery * query ) { +void Space::OnPointQuery( Shape * shape, cPointQuery * query ) { if ( query->Func.IsSet() ) { query->Func( shape, query->Data ); } } -void cSpace::AddCollisionHandler( const cCollisionHandler& handler ) { +void Space::AddCollisionHandler( const cCollisionHandler& handler ) { cpHashValue hash = CP_HASH_PAIR( handler.a, handler.b ); cpCollisionBeginFunc f1 = ( handler.begin.IsSet() ) ? &RecieverCollisionBeginFunc : NULL; @@ -533,13 +533,13 @@ void cSpace::AddCollisionHandler( const cCollisionHandler& handler ) { mCollisions[ hash ] = handler; } -void cSpace::RemoveCollisionHandler( cpCollisionType a, cpCollisionType b ) { +void Space::RemoveCollisionHandler( cpCollisionType a, cpCollisionType b ) { cpSpaceRemoveCollisionHandler( mSpace, a, b ); mCollisions.erase( CP_HASH_PAIR( a, b ) ); } -void cSpace::SetDefaultCollisionHandler( const cCollisionHandler& handler ) { +void Space::SetDefaultCollisionHandler( const cCollisionHandler& handler ) { cpCollisionBeginFunc f1 = ( handler.begin.IsSet() ) ? &RecieverCollisionBeginFunc : NULL; cpCollisionPreSolveFunc f2 = ( handler.preSolve.IsSet() ) ? &RecieverCollisionPreSolveFunc : NULL; cpCollisionPostSolveFunc f3 = ( handler.postSolve.IsSet() ) ? &RecieverCollisionPostSolve : NULL; @@ -550,7 +550,7 @@ void cSpace::SetDefaultCollisionHandler( const cCollisionHandler& handler ) { mCollisionsDefault = handler; } -void cSpace::AddPostStepCallback( PostStepCallback postStep, void * obj, void * data ) { +void Space::AddPostStepCallback( PostStepCallback postStep, void * obj, void * data ) { cPostStepCallback * PostStepCb = cpNew( cPostStepCallback, () ); PostStepCb->Callback = postStep, PostStepCb->Data = data; @@ -559,7 +559,7 @@ void cSpace::AddPostStepCallback( PostStepCallback postStep, void * obj, void * mPostStepCallbacks.push_back( PostStepCb ); } -void cSpace::BBQuery( cBB bb, cpLayers layers, cpGroup group, BBQueryFunc func, void * data ) { +void Space::BBQuery( cBB bb, cpLayers layers, cpGroup group, BBQueryFunc func, void * data ) { cBBQuery tBBQuery; tBBQuery.Space = this; tBBQuery.Data = data; @@ -568,7 +568,7 @@ void cSpace::BBQuery( cBB bb, cpLayers layers, cpGroup group, BBQueryFunc func, cpSpaceBBQuery( mSpace, tocpbb( bb ), layers, group, &RecieverBBQueryFunc, reinterpret_cast( &tBBQuery ) ); } -void cSpace::SegmentQuery( cVect start, cVect end, cpLayers layers, cpGroup group, SegmentQueryFunc func, void * data ) { +void Space::SegmentQuery( cVect start, cVect end, cpLayers layers, cpGroup group, SegmentQueryFunc func, void * data ) { cSegmentQuery tSegmentQuery; tSegmentQuery.Space = this; @@ -578,7 +578,7 @@ void cSpace::SegmentQuery( cVect start, cVect end, cpLayers layers, cpGroup grou cpSpaceSegmentQuery( mSpace, tocpv( start ), tocpv( end ), layers, group, &RecieverSegmentQueryFunc, reinterpret_cast( &tSegmentQuery ) ); } -void cSpace::PointQuery( cVect point, cpLayers layers, cpGroup group, PointQueryFunc func, void * data ) { +void Space::PointQuery( cVect point, cpLayers layers, cpGroup group, PointQueryFunc func, void * data ) { cPointQuery tPointQuery; tPointQuery.Space = this; tPointQuery.Data = data; @@ -587,60 +587,60 @@ void cSpace::PointQuery( cVect point, cpLayers layers, cpGroup group, PointQuery cpSpacePointQuery( mSpace, tocpv( point ), layers, group, &RecieverPointQueryFunc, reinterpret_cast( &tPointQuery ) ); } -void cSpace::ReindexShape( cShape * shape ) { - cpSpaceReindexShape( mSpace, shape->Shape() ); +void Space::ReindexShape( Shape * shape ) { + cpSpaceReindexShape( mSpace, shape->GetShape() ); } -void cSpace::ReindexShapesForBody( cBody *body ) { - cpSpaceReindexShapesForBody( mSpace, body->Body() ); +void Space::ReindexShapesForBody( Body *body ) { + cpSpaceReindexShapesForBody( mSpace, body->GetBody() ); } -void cSpace::ReindexStatic() { +void Space::ReindexStatic() { cpSpaceReindexStatic( mSpace ); } -void cSpace::UseSpatialHash( cpFloat dim, int count ) { +void Space::UseSpatialHash( cpFloat dim, int count ) { cpSpaceUseSpatialHash( mSpace, dim, count ); } static void SpaceBodyIteratorFunc( cpBody * body, void *data ) { - cSpace::cBodyIterator * it = reinterpret_cast ( data ); - it->Space->OnEachBody( reinterpret_cast( body->data ), it ); + Space::BodyIterator * it = reinterpret_cast ( data ); + it->Space->OnEachBody( reinterpret_cast( body->data ), it ); } -void cSpace::EachBody( BodyIteratorFunc Func, void * data ) { - cBodyIterator it( this, data, Func ); +void Space::EachBody( BodyIteratorFunc Func, void * data ) { + BodyIterator it( this, data, Func ); cpSpaceEachBody( mSpace, &SpaceBodyIteratorFunc, (void*)&it ); } -void cSpace::OnEachBody( cBody * Body, cBodyIterator * it ) { +void Space::OnEachBody( Body * Body, BodyIterator * it ) { if ( it->Func.IsSet() ) { it->Func( it->Space, Body, it->Data ); } } static void SpaceShapeIteratorFunc ( cpShape * shape, void * data ) { - cSpace::cShapeIterator * it = reinterpret_cast ( data ); - it->Space->OnEachShape( reinterpret_cast( shape->data ), it ); + Space::ShapeIterator * it = reinterpret_cast ( data ); + it->Space->OnEachShape( reinterpret_cast( shape->data ), it ); } -void cSpace::EachShape( ShapeIteratorFunc Func, void * data ) { - cShapeIterator it( this, data, Func ); +void Space::EachShape( ShapeIteratorFunc Func, void * data ) { + ShapeIterator it( this, data, Func ); cpSpaceEachShape( mSpace, &SpaceShapeIteratorFunc, (void*)&it ); } -void cSpace::OnEachShape( cShape * Shape, cShapeIterator * it ) { +void Space::OnEachShape( Shape * Shape, ShapeIterator * it ) { if ( it->Func.IsSet() ) { it->Func( it->Space, Shape, it->Data ); } } -void cSpace::ConvertBodyToDynamic( cBody * body, cpFloat mass, cpFloat moment ) { - cpSpaceConvertBodyToDynamic( mSpace, body->Body(), mass, moment ); +void Space::ConvertBodyToDynamic( Body * body, cpFloat mass, cpFloat moment ) { + cpSpaceConvertBodyToDynamic( mSpace, body->GetBody(), mass, moment ); } -void cSpace::ConvertBodyToStatic(cBody * body ) { - cpSpaceConvertBodyToStatic( mSpace, body->Body() ); +void Space::ConvertBodyToStatic(Body * body ) { + cpSpaceConvertBodyToStatic( mSpace, body->GetBody() ); } CP_NAMESPACE_END diff --git a/src/eepp/window/engine.cpp b/src/eepp/window/engine.cpp index b32be50bd..2f6c028d4 100755 --- a/src/eepp/window/engine.cpp +++ b/src/eepp/window/engine.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include @@ -49,7 +49,7 @@ Engine::Engine() : } Engine::~Engine() { - Physics::cPhysicsManager::DestroySingleton(); + Physics::PhysicsManager::DestroySingleton(); Graphics::Private::FrameBufferManager::DestroySingleton(); diff --git a/src/examples/physics/physics.cpp b/src/examples/physics/physics.cpp index a3650614c..3706b2f74 100644 --- a/src/examples/physics/physics.cpp +++ b/src/examples/physics/physics.cpp @@ -16,25 +16,25 @@ struct physicDemo { std::vector mDemo; int mCurDemo = eeINDEX_NOT_FOUND; -cSpace * mSpace; -cBody * mMouseBody; +Space * mSpace; +Body * mMouseBody; cVect mMousePoint; cVect mMousePoint_last; -cConstraint * mMouseJoint; +Constraint * mMouseJoint; #define GRABABLE_MASK_BIT (1<<31) #define NOT_GRABABLE_MASK (~GRABABLE_MASK_BIT) void CreateJointAndBody() { mMouseJoint = NULL; - mMouseBody = eeNew( cBody, ( INFINITY, INFINITY ) ); + mMouseBody = eeNew( Body, ( INFINITY, INFINITY ) ); } EE::Window::Window * mWindow; Input * KM; void DefaultDrawOptions() { - cPhysicsManager::cDrawSpaceOptions * DSO = cPhysicsManager::instance()->GetDrawOptions(); + PhysicsManager::cDrawSpaceOptions * DSO = PhysicsManager::instance()->GetDrawOptions(); DSO->DrawBBs = false; DSO->DrawShapes = true; DSO->DrawShapesBorders = true; @@ -92,12 +92,12 @@ int get_pixel(int x, int y) { return (image_bitmap[(x>>3) + y*image_row_length]>>(~x&0x7)) & 1; } -cShape * make_ball( cpFloat x, cpFloat y ) { - cBody * body = cBody::New( 1.0, INFINITY ); +Shape * make_ball( cpFloat x, cpFloat y ) { + Body * body = Body::New( 1.0, INFINITY ); body->Pos( cVectNew( x, y ) ); - cShapePoint * shape = cShapePoint::New( body, 0.95, cVectZero ); + ShapePoint * shape = ShapePoint::New( body, 0.95, cVectZero ); shape->DrawRadius( 4 ); shape->Elasticity( 0.0 ); @@ -115,7 +115,7 @@ void Demo1Create() { mWindow->Caption( "eepp - Physics - Logo Smash" ); - mSpace = Physics::cSpace::New(); + mSpace = Physics::Space::New(); mSpace->Iterations( 1 ); // The space will contain a very large number of similary sized objects. @@ -125,8 +125,8 @@ void Demo1Create() { bodyCount = 0; - cBody * body; - cShape * shape; + Body * body; + Shape * shape; Float pX = mWindow->GetWidth() / 2 - ( image_width * 4 ) / 2; Float pY = mWindow->GetHeight() / 2 - ( image_height * 4 ) / 2; @@ -144,11 +144,11 @@ void Demo1Create() { } } - body = mSpace->AddBody( cBody::New( INFINITY, INFINITY ) ); + body = mSpace->AddBody( Body::New( INFINITY, INFINITY ) ); body->Pos( cVectNew( 0, mWindow->GetHeight() / 2 + 16 ) ); body->Vel( cVectNew( 400, 0 ) ); - shape = mSpace->AddShape( cShapeCircle::New( body, 8.0f, cVectZero ) ); + shape = mSpace->AddShape( ShapeCircle::New( body, 8.0f, cVectZero ) ); shape->Elasticity( 0.0 ); shape->Friction( 0.0 ); shape->Layers( NOT_GRABABLE_MASK ); @@ -170,31 +170,31 @@ void Demo2Create() { mWindow->Caption( "eepp - Physics - Pyramid Stack" ); - cShape::ResetShapeIdCounter(); + Shape::ResetShapeIdCounter(); - mSpace = Physics::cSpace::New(); + mSpace = Physics::Space::New(); mSpace->Gravity( cVectNew( 0, 100 ) ); mSpace->SleepTimeThreshold( 0.5f ); - cBody *body, *staticBody = mSpace->StaticBody(); - cShape * shape; + Body *body, *statiBody = mSpace->StatiBody(); + Shape * shape; - shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( 0, mWindow->GetHeight() ), cVectNew( mWindow->GetWidth(), mWindow->GetHeight() ), 0.0f ) ); + shape = mSpace->AddShape( ShapeSegment::New( statiBody, cVectNew( 0, mWindow->GetHeight() ), cVectNew( mWindow->GetWidth(), mWindow->GetHeight() ), 0.0f ) ); shape->e( 1.0f ); shape->u( 1.0f ); shape->Layers( NOT_GRABABLE_MASK ); - shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( mWindow->GetWidth(), 0 ), cVectNew( mWindow->GetWidth(), mWindow->GetHeight() ), 0.0f ) ); + shape = mSpace->AddShape( ShapeSegment::New( statiBody, cVectNew( mWindow->GetWidth(), 0 ), cVectNew( mWindow->GetWidth(), mWindow->GetHeight() ), 0.0f ) ); shape->e( 1.0f ); shape->u( 1.0f ); shape->Layers( NOT_GRABABLE_MASK ); - shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( 0, 0 ), cVectNew( 0, mWindow->GetHeight() ), 0.0f ) ); + shape = mSpace->AddShape( ShapeSegment::New( statiBody, cVectNew( 0, 0 ), cVectNew( 0, mWindow->GetHeight() ), 0.0f ) ); shape->e( 1.0f ); shape->u( 1.0f ); shape->Layers( NOT_GRABABLE_MASK ); - shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( 0, 0 ), cVectNew( mWindow->GetWidth(), 0 ), 0.0f ) ); + shape = mSpace->AddShape( ShapeSegment::New( statiBody, cVectNew( 0, 0 ), cVectNew( mWindow->GetWidth(), 0 ), 0.0f ) ); shape->e( 1.0f ); shape->u( 1.0f ); shape->Layers( NOT_GRABABLE_MASK ); @@ -203,10 +203,10 @@ void Demo2Create() { for(int i=0; i<14; i++){ for(int j=0; j<=i; j++){ - body = mSpace->AddBody( cBody::New( 1.0f, Moment::ForBox( 1.0f, 30.0f, 30.0f ) ) ); + body = mSpace->AddBody( Body::New( 1.0f, Moment::ForBox( 1.0f, 30.0f, 30.0f ) ) ); body->Pos( cVectNew( hw + j * 32 - i * 16, 100 + i * 32 ) ); - shape = mSpace->AddShape( cShapePoly::New( body, 30.f, 30.f ) ); + shape = mSpace->AddShape( ShapePoly::New( body, 30.f, 30.f ) ); shape->e( 0.0f ); shape->u( 0.8f ); } @@ -214,10 +214,10 @@ void Demo2Create() { cpFloat radius = 15.0f; - body = mSpace->AddBody( cBody::New( 10.0f, Moment::ForCircle( 10.0f, 0.0f, radius, cVectZero ) ) ); + body = mSpace->AddBody( Body::New( 10.0f, Moment::ForCircle( 10.0f, 0.0f, radius, cVectZero ) ) ); body->Pos( cVectNew( hw, mWindow->GetHeight() - radius - 5 ) ); - shape = mSpace->AddShape( cShapeCircle::New( body, radius, cVectZero ) ); + shape = mSpace->AddShape( ShapeCircle::New( body, radius, cVectZero ) ); shape->e( 0.0f ); shape->u( 0.9f ); } @@ -242,8 +242,8 @@ struct Emitter { }; Emitter emitterInstance; -cpBool blockerBegin( cArbiter *arb, cSpace *space, void *unused ) { - cShape * a, * b; +cpBool blockerBegin( Arbiter *arb, Space *space, void *unused ) { + Shape * a, * b; arb->GetShapes( &a, &b ); Emitter *emitter = (Emitter *) a->Data(); @@ -253,8 +253,8 @@ cpBool blockerBegin( cArbiter *arb, cSpace *space, void *unused ) { return cpFalse; // Return values from sensors callbacks are ignored, } -void blockerSeparate( cArbiter *arb, cSpace * space, void *unused ) { - cShape * a, * b; +void blockerSeparate( Arbiter *arb, Space * space, void *unused ) { + Shape * a, * b; arb->GetShapes( &a, &b ); Emitter *emitter = (Emitter *) a->Data(); @@ -262,8 +262,8 @@ void blockerSeparate( cArbiter *arb, cSpace * space, void *unused ) { emitter->blocked--; } -void postStepRemove( cSpace *space, void * tshape, void * unused ) { - cShape * shape = reinterpret_cast( tshape ); +void postStepRemove( Space *space, void * tshape, void * unused ) { + Shape * shape = reinterpret_cast( tshape ); if ( NULL != mMouseJoint && ( mMouseJoint->A() == shape->Body() || mMouseJoint->B() == shape->Body() ) ) { space->RemoveConstraint( mMouseJoint ); @@ -273,11 +273,11 @@ void postStepRemove( cSpace *space, void * tshape, void * unused ) { space->RemoveBody( shape->Body() ); space->RemoveShape( shape ); - cShape::Free( shape, true ); + Shape::Free( shape, true ); } -cpBool catcherBarBegin(cArbiter *arb, cSpace *space, void *unused) { - cShape * a, * b; +cpBool catcherBarBegin(Arbiter *arb, Space *space, void *unused) { + Shape * a, * b; arb->GetShapes( &a, &b ); Emitter *emitter = (Emitter *) a->Data(); @@ -296,31 +296,31 @@ void Demo3Create() { mWindow->Caption( "eepp - Physics - Sensor" ); - cShape::ResetShapeIdCounter(); + Shape::ResetShapeIdCounter(); - mSpace = Physics::cSpace::New(); + mSpace = Physics::Space::New(); mSpace->Iterations( 10 ); mSpace->Gravity( cVectNew( 0, 100 ) ); - cBody * staticBody = mSpace->StaticBody(); - cShape * shape; + Body * statiBody = mSpace->StatiBody(); + Shape * shape; emitterInstance.queue = 5; emitterInstance.blocked = 0; emitterInstance.position = cVectNew( mWindow->GetWidth() / 2 , 150); - shape = mSpace->AddShape( cShapeCircle::New( staticBody, 15.0f, emitterInstance.position ) ); + shape = mSpace->AddShape( ShapeCircle::New( statiBody, 15.0f, emitterInstance.position ) ); shape->Sensor( 1 ); shape->CollisionType( BLOCKING_SENSOR_TYPE ); shape->Data( &emitterInstance ); // Create our catch sensor to requeue the balls when they reach the bottom of the screen - shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew(-4000, 600), cVectNew(4000, 600), 15.0f ) ); + shape = mSpace->AddShape( ShapeSegment::New( statiBody, cVectNew(-4000, 600), cVectNew(4000, 600), 15.0f ) ); shape->Sensor( 1 ); shape->CollisionType( CATCH_SENSOR_TYPE ); shape->Data( &emitterInstance ); - cSpace::cCollisionHandler handler; + Space::cCollisionHandler handler; handler.a = BLOCKING_SENSOR_TYPE; handler.b = BALL_TYPE; handler.begin = cb::Make3( &blockerBegin ); @@ -339,11 +339,11 @@ void Demo3Update() { if( !emitterInstance.blocked && emitterInstance.queue ){ emitterInstance.queue--; - cBody * body = mSpace->AddBody( cBody::New( 1.0f, Moment::ForCircle(1.0f, 15.0f, 0.0f, cVectZero ) ) ); + Body * body = mSpace->AddBody( Body::New( 1.0f, Moment::ForCircle(1.0f, 15.0f, 0.0f, cVectZero ) ) ); body->Pos( emitterInstance.position ); body->Vel( cVectNew( Math::Randf(-1,1), Math::Randf(-1,1) ) * (cpFloat)100 ); - cShape *shape = mSpace->AddShape( cShapeCircle::New( body, 15.0f, cVectZero ) ); + Shape *shape = mSpace->AddShape( ShapeCircle::New( body, 15.0f, cVectZero ) ); shape->CollisionType( BALL_TYPE ); } } @@ -358,13 +358,13 @@ enum { #define STICK_SENSOR_THICKNESS 2.5f -void PostStepAddJoint(cSpace *space, void *key, void *data) +void PostStepAddJoint(Space *space, void *key, void *data) { - cConstraint *joint = (cConstraint *)key; + Constraint *joint = (Constraint *)key; space->AddConstraint( joint ); } -cpBool StickyPreSolve( cArbiter *arb, cSpace *space, void *data ) +cpBool StickyPreSolve( Arbiter *arb, Space *space, void *data ) { // We want to fudge the collisions a bit to allow shapes to overlap more. // This simulates their squishy sticky surface, and more importantly @@ -392,11 +392,11 @@ cpBool StickyPreSolve( cArbiter *arb, cSpace *space, void *data ) // joint that sticks them together at the first contact point. if(!arb->UserData() && deepest <= 0.0f){ - cBody *bodyA, *bodyB; + Body *bodyA, *bodyB; arb->GetBodies( &bodyA, &bodyB ); // Create a joint at the contact point to hold the body in place. - cPivotJoint * joint = cpNew( cPivotJoint, ( bodyA, bodyB, tovect( contacts.points[0].point ) ) ); + PivotJoint * joint = cpNew( PivotJoint, ( bodyA, bodyB, tovect( contacts.points[0].point ) ) ); // Dont draw the constraint joint->DrawPointSize( 0 ); @@ -423,16 +423,16 @@ cpBool StickyPreSolve( cArbiter *arb, cSpace *space, void *data ) // * Track a joint for each contact point. (more complicated since you only get one data pointer). } -void PostStepRemoveJoint(cSpace *space, void *key, void *data) +void PostStepRemoveJoint(Space *space, void *key, void *data) { - cConstraint *joint = (cConstraint *)key; + Constraint *joint = (Constraint *)key; space->RemoveConstraint( joint ); - cConstraint::Free( joint ); + Constraint::Free( joint ); } -void StickySeparate(cArbiter *arb, cSpace *space, void *data) +void StickySeparate(Arbiter *arb, Space *space, void *data) { - cConstraint *joint = (cConstraint *)arb->UserData(); + Constraint *joint = (Constraint *)arb->UserData(); if(joint){ // The joint won't be removed until the step is done. @@ -450,7 +450,7 @@ void StickySeparate(cArbiter *arb, cSpace *space, void *data) } void Demo4Create() { - cPhysicsManager::cDrawSpaceOptions * DSO = cPhysicsManager::instance()->GetDrawOptions(); + PhysicsManager::cDrawSpaceOptions * DSO = PhysicsManager::instance()->GetDrawOptions(); DSO->DrawBBs = false; DSO->DrawShapes = true; DSO->DrawShapesBorders = false; @@ -460,38 +460,38 @@ void Demo4Create() { CreateJointAndBody(); - mWindow->Caption( "eepp - Physics - Sticky collisions using the cArbiter data pointer." ); + mWindow->Caption( "eepp - Physics - Sticky collisions using the Arbiter data pointer." ); - mSpace = cSpace::New(); + mSpace = Space::New(); mSpace->Iterations( 10 ); mSpace->Gravity( cVectNew( 0, 1000 ) ); mSpace->CollisionSlop( 2.0 ); - cBody * staticBody = mSpace->StaticBody(); - cShape * shape; + Body * statiBody = mSpace->StatiBody(); + Shape * shape; cpFloat x = 500; cpFloat y = 400; - shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( x + -340, y -260 ), cVectNew( x -340, y + 260 ), 20.0f ) ); + shape = mSpace->AddShape( ShapeSegment::New( statiBody, cVectNew( x + -340, y -260 ), cVectNew( x -340, y + 260 ), 20.0f ) ); shape->Elasticity( 1.0f ); shape->Friction( 1.0f ); shape->CollisionType( COLLIDE_STICK_SENSOR ); shape->Layers( NOT_GRABABLE_MASK ); - shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( x + 340, y -260 ), cVectNew( x + 340, y + 260 ), 20.0f ) ); + shape = mSpace->AddShape( ShapeSegment::New( statiBody, cVectNew( x + 340, y -260 ), cVectNew( x + 340, y + 260 ), 20.0f ) ); shape->Elasticity( 1.0f ); shape->Friction( 1.0f ); shape->CollisionType( COLLIDE_STICK_SENSOR ); shape->Layers( NOT_GRABABLE_MASK ); - shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( x -340, y -260 ), cVectNew( x + 340, y -260 ), 20.0f ) ); + shape = mSpace->AddShape( ShapeSegment::New( statiBody, cVectNew( x -340, y -260 ), cVectNew( x + 340, y -260 ), 20.0f ) ); shape->Elasticity( 1.0f ); shape->Friction( 1.0f ); shape->CollisionType( COLLIDE_STICK_SENSOR ); shape->Layers( NOT_GRABABLE_MASK ); - shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( x -340, y + 260 ), cVectNew( x + 340, y + 260 ), 20.0f ) ); + shape = mSpace->AddShape( ShapeSegment::New( statiBody, cVectNew( x -340, y + 260 ), cVectNew( x + 340, y + 260 ), 20.0f ) ); shape->Elasticity( 1.0f ); shape->Friction( 1.0f ); shape->CollisionType( COLLIDE_STICK_SENSOR ); @@ -501,17 +501,17 @@ void Demo4Create() { cpFloat mass = 0.15f; cpFloat radius = 10.0f; - cBody * body = mSpace->AddBody( cBody::New( mass, Moment::ForCircle( mass, 0.0f, radius, cVectZero ) ) ); + Body * body = mSpace->AddBody( Body::New( mass, Moment::ForCircle( mass, 0.0f, radius, cVectZero ) ) ); body->Pos( cVectNew( x + easing::LinearInterpolation( Math::Randf(), -150.0f, 150.0f, 1 ), y + easing::LinearInterpolation( Math::Randf(), -150.0f, 150.0f, 1 ) ) ); - cShape * shape = mSpace->AddShape( cShapeCircle::New( body, radius + STICK_SENSOR_THICKNESS, cVectZero ) ); + Shape * shape = mSpace->AddShape( ShapeCircle::New( body, radius + STICK_SENSOR_THICKNESS, cVectZero ) ); shape->Friction( 0.9f ); shape->CollisionType( COLLIDE_STICK_SENSOR ); } - cSpace::cCollisionHandler c; + Space::cCollisionHandler c; c.a = COLLIDE_STICK_SENSOR; c.b = COLLIDE_STICK_SENSOR; c.preSolve = cb::Make3( &StickyPreSolve ); @@ -540,7 +540,7 @@ void ChangeDemo( int num ) { void PhysicsCreate() { // Initialize the physics engine - cPhysicsManager::CreateSingleton(); + PhysicsManager::CreateSingleton(); mDemo.clear(); @@ -582,10 +582,10 @@ void PhysicsUpdate() { if ( NULL == mMouseJoint ) { cVect point = cVectNew( KM->GetMousePosf().x, KM->GetMousePosf().y ); - cShape * shape = mSpace->PointQueryFirst( point, GRABABLE_MASK_BIT, CP_NO_GROUP ); + Shape * shape = mSpace->PointQueryFirst( point, GRABABLE_MASK_BIT, CP_NO_GROUP ); if( NULL != shape ){ - mMouseJoint = eeNew( cPivotJoint, ( mMouseBody, shape->Body(), cVectZero, shape->Body()->World2Local( point ) ) ); + mMouseJoint = eeNew( PivotJoint, ( mMouseBody, shape->Body(), cVectZero, shape->Body()->World2Local( point ) ) ); mMouseJoint->MaxForce( 50000.0f ); mSpace->AddConstraint( mMouseJoint ); diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 249790c51..9eb6794c6 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -1549,11 +1549,11 @@ void cEETest::Particles() { void cEETest::CreateJointAndBody() { #ifndef EE_PLATFORM_TOUCH mMouseJoint = NULL; - mMouseBody = eeNew( cBody, ( INFINITY, INFINITY ) ); + mMouseBody = eeNew( Body, ( INFINITY, INFINITY ) ); #else for ( Uint32 i = 0; i < EE_MAX_FINGERS; i++ ) { mMouseJoint[i] = NULL; - mMouseBody[i] = eeNew( cBody, ( INFINITY, INFINITY ) ); + mMouseBody[i] = eeNew( Body, ( INFINITY, INFINITY ) ); } #endif } @@ -1561,31 +1561,31 @@ void cEETest::CreateJointAndBody() { void cEETest::Demo1Create() { CreateJointAndBody(); - cShape::ResetShapeIdCounter(); + Shape::ResetShapeIdCounter(); - mSpace = Physics::cSpace::New(); + mSpace = Physics::Space::New(); mSpace->Gravity( cVectNew( 0, 100 ) ); mSpace->SleepTimeThreshold( 0.5f ); - cBody *body, *staticBody = mSpace->StaticBody(); - cShape * shape; + Body *body, *statiBody = mSpace->StatiBody(); + Shape * shape; - shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( 0, mWindow->GetHeight() ), cVectNew( mWindow->GetWidth(), mWindow->GetHeight() ), 0.0f ) ); + shape = mSpace->AddShape( ShapeSegment::New( statiBody, cVectNew( 0, mWindow->GetHeight() ), cVectNew( mWindow->GetWidth(), mWindow->GetHeight() ), 0.0f ) ); shape->e( 1.0f ); shape->u( 1.0f ); shape->Layers( NOT_GRABABLE_MASK ); - shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( mWindow->GetWidth(), 0 ), cVectNew( mWindow->GetWidth(), mWindow->GetHeight() ), 0.0f ) ); + shape = mSpace->AddShape( ShapeSegment::New( statiBody, cVectNew( mWindow->GetWidth(), 0 ), cVectNew( mWindow->GetWidth(), mWindow->GetHeight() ), 0.0f ) ); shape->e( 1.0f ); shape->u( 1.0f ); shape->Layers( NOT_GRABABLE_MASK ); - shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( 0, 0 ), cVectNew( 0, mWindow->GetHeight() ), 0.0f ) ); + shape = mSpace->AddShape( ShapeSegment::New( statiBody, cVectNew( 0, 0 ), cVectNew( 0, mWindow->GetHeight() ), 0.0f ) ); shape->e( 1.0f ); shape->u( 1.0f ); shape->Layers( NOT_GRABABLE_MASK ); - shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew( 0, 0 ), cVectNew( mWindow->GetWidth(), 0 ), 0.0f ) ); + shape = mSpace->AddShape( ShapeSegment::New( statiBody, cVectNew( 0, 0 ), cVectNew( mWindow->GetWidth(), 0 ), 0.0f ) ); shape->e( 1.0f ); shape->u( 1.0f ); shape->Layers( NOT_GRABABLE_MASK ); @@ -1594,11 +1594,11 @@ void cEETest::Demo1Create() { for(int i=0; i<14; i++){ for(int j=0; j<=i; j++){ - body = mSpace->AddBody( cBody::New( 1.0f, Moment::ForBox( 1.0f, 30.0f, 30.0f ) ) ); + body = mSpace->AddBody( Body::New( 1.0f, Moment::ForBox( 1.0f, 30.0f, 30.0f ) ) ); body->Pos( cVectNew( hw + j * 32 - i * 16, 100 + i * 32 ) ); - //shape = mSpace->AddShape( cShapePolySprite::New( body, 30.f, 30.f, mBoxSprite ) ); - shape = mSpace->AddShape( cShapePoly::New( body, 30.f, 30.f ) ); + //shape = mSpace->AddShape( ShapePolySprite::New( body, 30.f, 30.f, mBoxSprite ) ); + shape = mSpace->AddShape( ShapePoly::New( body, 30.f, 30.f ) ); shape->e( 0.0f ); shape->u( 0.8f ); } @@ -1606,11 +1606,11 @@ void cEETest::Demo1Create() { cpFloat radius = 15.0f; - body = mSpace->AddBody( cBody::New( 10.0f, Moment::ForCircle( 10.0f, 0.0f, radius, cVectZero ) ) ); + body = mSpace->AddBody( Body::New( 10.0f, Moment::ForCircle( 10.0f, 0.0f, radius, cVectZero ) ) ); body->Pos( cVectNew( hw, mWindow->GetHeight() - radius - 5 ) ); - //shape = mSpace->AddShape( cShapeCircleSprite::New( body, radius, cVectZero, mCircleSprite ) ); - shape = mSpace->AddShape( cShapeCircle::New( body, radius, cVectZero ) ); + //shape = mSpace->AddShape( ShapeCircleSprite::New( body, radius, cVectZero, mCircleSprite ) ); + shape = mSpace->AddShape( ShapeCircle::New( body, radius, cVectZero ) ); shape->e( 0.0f ); shape->u( 0.9f ); } @@ -1635,8 +1635,8 @@ void cEETest::Demo1Destroy() { eeSAFE_DELETE( mSpace ); } -cpBool cEETest::blockerBegin( cArbiter *arb, cSpace *space, void *unused ) { - cShape * a, * b; +cpBool cEETest::blockerBegin( Arbiter *arb, Space *space, void *unused ) { + Shape * a, * b; arb->GetShapes( &a, &b ); Emitter *emitter = (Emitter *) a->Data(); @@ -1646,8 +1646,8 @@ cpBool cEETest::blockerBegin( cArbiter *arb, cSpace *space, void *unused ) { return cpFalse; // Return values from sensors callbacks are ignored, } -void cEETest::blockerSeparate( cArbiter *arb, cSpace * space, void *unused ) { - cShape * a, * b; +void cEETest::blockerSeparate( Arbiter *arb, Space * space, void *unused ) { + Shape * a, * b; arb->GetShapes( &a, &b ); Emitter *emitter = (Emitter *) a->Data(); @@ -1655,8 +1655,8 @@ void cEETest::blockerSeparate( cArbiter *arb, cSpace * space, void *unused ) { emitter->blocked--; } -void cEETest::postStepRemove( cSpace *space, void * tshape, void * unused ) { - cShape * shape = reinterpret_cast( tshape ); +void cEETest::postStepRemove( Space *space, void * tshape, void * unused ) { + Shape * shape = reinterpret_cast( tshape ); #ifndef EE_PLATFORM_TOUCH if ( NULL != mMouseJoint && ( mMouseJoint->A() == shape->Body() || mMouseJoint->B() == shape->Body() ) ) { @@ -1674,11 +1674,11 @@ void cEETest::postStepRemove( cSpace *space, void * tshape, void * unused ) { mSpace->RemoveBody( shape->Body() ); mSpace->RemoveShape( shape ); - cShape::Free( shape, true ); + Shape::Free( shape, true ); } -cpBool cEETest::catcherBarBegin(cArbiter *arb, Physics::cSpace *space, void *unused) { - cShape * a, * b; +cpBool cEETest::catcherBarBegin(Arbiter *arb, Physics::Space *space, void *unused) { + Shape * a, * b; arb->GetShapes( &a, &b ); Emitter *emitter = (Emitter *) a->Data(); @@ -1693,31 +1693,31 @@ cpBool cEETest::catcherBarBegin(cArbiter *arb, Physics::cSpace *space, void *unu void cEETest::Demo2Create() { CreateJointAndBody(); - cShape::ResetShapeIdCounter(); + Shape::ResetShapeIdCounter(); - mSpace = Physics::cSpace::New(); + mSpace = Physics::Space::New(); mSpace->Iterations( 10 ); mSpace->Gravity( cVectNew( 0, 100 ) ); - cBody * staticBody = mSpace->StaticBody(); - cShape * shape; + Body * statiBody = mSpace->StatiBody(); + Shape * shape; emitterInstance.queue = 5; emitterInstance.blocked = 0; emitterInstance.position = cVectNew( mWindow->GetWidth() / 2 , 150); - shape = mSpace->AddShape( cShapeCircle::New( staticBody, 15.0f, emitterInstance.position ) ); + shape = mSpace->AddShape( ShapeCircle::New( statiBody, 15.0f, emitterInstance.position ) ); shape->Sensor( 1 ); shape->CollisionType( BLOCKING_SENSOR_TYPE ); shape->Data( &emitterInstance ); // Create our catch sensor to requeue the balls when they reach the bottom of the screen - shape = mSpace->AddShape( cShapeSegment::New( staticBody, cVectNew(-4000, 600), cVectNew(4000, 600), 15.0f ) ); + shape = mSpace->AddShape( ShapeSegment::New( statiBody, cVectNew(-4000, 600), cVectNew(4000, 600), 15.0f ) ); shape->Sensor( 1 ); shape->CollisionType( CATCH_SENSOR_TYPE ); shape->Data( &emitterInstance ); - cSpace::cCollisionHandler handler; + Space::cCollisionHandler handler; handler.a = BLOCKING_SENSOR_TYPE; handler.b = BALL_TYPE; handler.begin = cb::Make3( this, &cEETest::blockerBegin ); @@ -1736,11 +1736,11 @@ void cEETest::Demo2Update() { if( !emitterInstance.blocked && emitterInstance.queue ){ emitterInstance.queue--; - cBody * body = mSpace->AddBody( cBody::New( 1.0f, Moment::ForCircle(1.0f, 15.0f, 0.0f, cVectZero ) ) ); + Body * body = mSpace->AddBody( Body::New( 1.0f, Moment::ForCircle(1.0f, 15.0f, 0.0f, cVectZero ) ) ); body->Pos( emitterInstance.position ); body->Vel( cVectNew( Math::Randf(-1,1), Math::Randf(-1,1) ) * (cpFloat)100 ); - cShape *shape = mSpace->AddShape( cShapeCircle::New( body, 15.0f, cVectZero ) ); + Shape *shape = mSpace->AddShape( ShapeCircle::New( body, 15.0f, cVectZero ) ); shape->CollisionType( BALL_TYPE ); } } @@ -1762,9 +1762,9 @@ void cEETest::ChangeDemo( Uint32 num ) { } void cEETest::PhysicsCreate() { - cPhysicsManager::CreateSingleton(); - cPhysicsManager * PM = cPhysicsManager::instance(); - cPhysicsManager::cDrawSpaceOptions * DSO = PM->GetDrawOptions(); + PhysicsManager::CreateSingleton(); + PhysicsManager * PM = PhysicsManager::instance(); + PhysicsManager::cDrawSpaceOptions * DSO = PM->GetDrawOptions(); DSO->DrawBBs = false; DSO->DrawShapes = true; @@ -1801,10 +1801,10 @@ void cEETest::PhysicsUpdate() { if ( NULL == mMouseJoint ) { cVect point = cVectNew( KM->GetMousePosf().x, KM->GetMousePosf().y ); - cShape * shape = mSpace->PointQueryFirst( point, GRABABLE_MASK_BIT, CP_NO_GROUP ); + Shape * shape = mSpace->PointQueryFirst( point, GRABABLE_MASK_BIT, CP_NO_GROUP ); if( NULL != shape ){ - mMouseJoint = eeNew( cPivotJoint, ( mMouseBody, shape->Body(), cVectZero, shape->Body()->World2Local( point ) ) ); + mMouseJoint = eeNew( PivotJoint, ( mMouseBody, shape->Body(), cVectZero, shape->Body()->World2Local( point ) ) ); mMouseJoint->MaxForce( 50000.0f ); mSpace->AddConstraint( mMouseJoint ); @@ -1827,10 +1827,10 @@ void cEETest::PhysicsUpdate() { if ( NULL == mMouseJoint[i] ) { cVect point = cVectNew( Finger->x, Finger->y ); - cShape * shape = mSpace->PointQueryFirst( point, GRABABLE_MASK_BIT, CP_NO_GROUP ); + Shape * shape = mSpace->PointQueryFirst( point, GRABABLE_MASK_BIT, CP_NO_GROUP ); if( NULL != shape ){ - mMouseJoint[i] = eeNew( cPivotJoint, ( mMouseBody[i], shape->Body(), cVectZero, shape->Body()->World2Local( point ) ) ); + mMouseJoint[i] = eeNew( PivotJoint, ( mMouseBody[i], shape->Body(), cVectZero, shape->Body()->World2Local( point ) ) ); mMouseJoint[i]->MaxForce( 50000.0f ); mSpace->AddConstraint( mMouseJoint[i] ); diff --git a/src/test/eetest.hpp b/src/test/eetest.hpp index b54d35a75..05c6b75e5 100644 --- a/src/test/eetest.hpp +++ b/src/test/eetest.hpp @@ -226,18 +226,18 @@ class cEETest : private Thread { TextCache mFBOText; TextCache mInfoText; - cSpace * mSpace; + Space * mSpace; #ifndef EE_PLATFORM_TOUCH - cBody * mMouseBody; + Body * mMouseBody; cVect mMousePoint; cVect mMousePoint_last; - cConstraint * mMouseJoint; + Constraint * mMouseJoint; #else - cBody * mMouseBody[ EE_MAX_FINGERS ]; + Body * mMouseBody[ EE_MAX_FINGERS ]; cVect mMousePoint[ EE_MAX_FINGERS ]; cVect mMousePoint_last[ EE_MAX_FINGERS ]; - cConstraint * mMouseJoint[ EE_MAX_FINGERS ]; + Constraint * mMouseJoint[ EE_MAX_FINGERS ]; #endif void PhysicsCreate(); @@ -246,10 +246,10 @@ class cEETest : private Thread { void SetScreen( Uint32 num ); - cpBool blockerBegin( cArbiter *arb, cSpace *space, void *unused ); - void blockerSeparate( cArbiter *arb, cSpace *space, void *unused ); - void postStepRemove( cSpace *space, void * tshape, void *unused ); - cpBool catcherBarBegin( cArbiter *arb, cSpace *space, void *unused ); + cpBool blockerBegin( Arbiter *arb, Space *space, void *unused ); + void blockerSeparate( Arbiter *arb, Space *space, void *unused ); + void postStepRemove( Space *space, void * tshape, void *unused ); + cpBool catcherBarBegin( Arbiter *arb, Space *space, void *unused ); void Demo1Create(); void Demo1Update();