2013-09-09 06:29:02 +04:00
|
|
|
/****************************************************************************
|
2014-01-07 07:47:11 +04:00
|
|
|
Copyright (c) 2013 Chukong Technologies Inc.
|
2013-09-09 06:29:02 +04:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CCPHYSICS_WORLD_H__
|
|
|
|
#define __CCPHYSICS_WORLD_H__
|
|
|
|
|
2014-04-30 04:37:36 +04:00
|
|
|
#include "base/ccConfig.h"
|
2013-12-26 19:55:05 +04:00
|
|
|
#if CC_USE_PHYSICS
|
2013-11-06 10:51:56 +04:00
|
|
|
|
2014-04-26 21:35:57 +04:00
|
|
|
#include "base/CCVector.h"
|
2014-04-26 21:11:22 +04:00
|
|
|
#include "base/CCRef.h"
|
2014-04-30 04:37:36 +04:00
|
|
|
#include "math/CCGeometry.h"
|
2014-07-15 06:55:40 +04:00
|
|
|
#include "physics/CCPhysicsBody.h"
|
2013-12-07 06:48:02 +04:00
|
|
|
#include <list>
|
|
|
|
|
2015-01-06 05:29:07 +03:00
|
|
|
struct cpSpace;
|
|
|
|
|
2013-09-09 06:29:02 +04:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
class PhysicsBody;
|
|
|
|
class PhysicsJoint;
|
2013-09-16 17:22:22 +04:00
|
|
|
class PhysicsShape;
|
|
|
|
class PhysicsContact;
|
2013-09-09 06:29:02 +04:00
|
|
|
|
2014-05-14 21:07:09 +04:00
|
|
|
typedef Vec2 Vect;
|
2013-11-26 13:29:09 +04:00
|
|
|
|
2015-01-07 12:08:04 +03:00
|
|
|
class Director;
|
2014-02-26 06:53:41 +04:00
|
|
|
class Node;
|
2013-09-09 12:36:19 +04:00
|
|
|
class Sprite;
|
2014-05-02 03:42:35 +04:00
|
|
|
class Scene;
|
2013-09-16 17:22:22 +04:00
|
|
|
class DrawNode;
|
2013-11-08 10:25:03 +04:00
|
|
|
class PhysicsDebugDraw;
|
2013-09-16 17:22:22 +04:00
|
|
|
|
2013-10-21 19:16:21 +04:00
|
|
|
class PhysicsWorld;
|
|
|
|
|
2013-11-07 12:23:50 +04:00
|
|
|
typedef struct PhysicsRayCastInfo
|
2013-10-21 19:16:21 +04:00
|
|
|
{
|
2013-11-07 12:23:50 +04:00
|
|
|
PhysicsShape* shape;
|
2014-05-14 21:07:09 +04:00
|
|
|
Vec2 start;
|
|
|
|
Vec2 end; //< in lua, it's name is "ended"
|
|
|
|
Vec2 contact;
|
2013-11-07 12:23:50 +04:00
|
|
|
Vect normal;
|
|
|
|
float fraction;
|
|
|
|
void* data;
|
|
|
|
}PhysicsRayCastInfo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Called for each fixture found in the query. You control how the ray cast
|
|
|
|
* proceeds by returning a float:
|
|
|
|
* return true: continue
|
|
|
|
* return false: terminate the ray cast
|
|
|
|
* @param fixture the fixture hit by the ray
|
|
|
|
* @param point the point of initial intersection
|
|
|
|
* @param normal the normal vector at the point of intersection
|
|
|
|
* @return true to continue, false to terminate
|
|
|
|
*/
|
|
|
|
typedef std::function<bool(PhysicsWorld& world, const PhysicsRayCastInfo& info, void* data)> PhysicsRayCastCallbackFunc;
|
2013-12-13 12:26:26 +04:00
|
|
|
typedef std::function<bool(PhysicsWorld&, PhysicsShape&, void*)> PhysicsQueryRectCallbackFunc;
|
|
|
|
typedef PhysicsQueryRectCallbackFunc PhysicsQueryPointCallbackFunc;
|
2013-10-21 19:16:21 +04:00
|
|
|
|
2013-09-17 12:27:43 +04:00
|
|
|
/**
|
2015-05-28 10:47:03 +03:00
|
|
|
* @addtogroup physics
|
2015-03-18 11:35:38 +03:00
|
|
|
* @{
|
2015-06-15 05:28:37 +03:00
|
|
|
* @addtogroup physics_2d
|
|
|
|
* @{
|
2015-03-18 11:35:38 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class PhysicsWorld CCPhysicsWorld.h
|
2013-09-17 12:27:43 +04:00
|
|
|
* @brief An PhysicsWorld object simulates collisions and other physical properties. You do not create PhysicsWorld objects directly; instead, you can get it from an Scene object.
|
|
|
|
*/
|
2014-07-15 06:55:40 +04:00
|
|
|
class CC_DLL PhysicsWorld
|
2013-09-09 06:29:02 +04:00
|
|
|
{
|
2013-11-18 06:10:37 +04:00
|
|
|
public:
|
2013-12-13 13:36:58 +04:00
|
|
|
static const int DEBUGDRAW_NONE; ///< draw nothing
|
|
|
|
static const int DEBUGDRAW_SHAPE; ///< draw shapes
|
|
|
|
static const int DEBUGDRAW_JOINT; ///< draw joints
|
|
|
|
static const int DEBUGDRAW_CONTACT; ///< draw contact
|
|
|
|
static const int DEBUGDRAW_ALL; ///< draw all
|
2013-11-18 06:10:37 +04:00
|
|
|
|
2013-09-09 06:29:02 +04:00
|
|
|
public:
|
2015-03-18 11:35:38 +03:00
|
|
|
/**
|
|
|
|
* Adds a joint to this physics world.
|
|
|
|
*
|
|
|
|
* This joint will be added to this physics world at next frame.
|
|
|
|
* @attention If this joint is already added to another physics world, it will be removed from that world first and then add to this world.
|
|
|
|
* @param joint A pointer to an existing PhysicsJoint object.
|
|
|
|
*/
|
2013-11-04 15:26:34 +04:00
|
|
|
virtual void addJoint(PhysicsJoint* joint);
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a joint from this physics world.
|
|
|
|
*
|
|
|
|
* If this world is not locked, the joint is removed immediately, otherwise at next frame.
|
|
|
|
* If this joint is connected with a body, it will be removed from the body also.
|
|
|
|
* @param joint A pointer to an existing PhysicsJoint object.
|
|
|
|
* @param destroy true this joint will be destroyed after remove from this world, false otherwise.
|
|
|
|
*/
|
2014-02-26 06:53:41 +04:00
|
|
|
virtual void removeJoint(PhysicsJoint* joint, bool destroy = true);
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all joints from this physics world.
|
|
|
|
*
|
|
|
|
* @attention This function is invoked in the destructor of this physics world, you do not use this api in common.
|
|
|
|
* @param destroy true all joints will be destroyed after remove from this world, false otherwise.
|
|
|
|
*/
|
2014-02-26 06:53:41 +04:00
|
|
|
virtual void removeAllJoints(bool destroy = true);
|
2013-11-04 15:26:34 +04:00
|
|
|
|
2015-03-18 11:35:38 +03:00
|
|
|
/**
|
|
|
|
* Remove a body from this physics world.
|
|
|
|
*
|
|
|
|
* If this world is not locked, the body is removed immediately, otherwise at next frame.
|
|
|
|
* @attention If this body has joints, those joints will be removed also.
|
|
|
|
* @param body A pointer to an existing PhysicsBody object.
|
|
|
|
*/
|
2013-11-04 15:26:34 +04:00
|
|
|
virtual void removeBody(PhysicsBody* body);
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove body by tag.
|
|
|
|
*
|
|
|
|
* If this world is not locked, the object is removed immediately, otherwise at next frame.
|
|
|
|
* @attention If this body has joints, those joints will be removed also.
|
|
|
|
* @param tag An interger number that identifies a PhysicsBody object.
|
|
|
|
*/
|
2013-11-05 16:02:58 +04:00
|
|
|
virtual void removeBody(int tag);
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all bodies from physics world.
|
|
|
|
*
|
|
|
|
* If this world is not locked, those body are removed immediately, otherwise at next frame.
|
|
|
|
*/
|
2013-11-04 15:26:34 +04:00
|
|
|
virtual void removeAllBodies();
|
2013-09-09 06:29:02 +04:00
|
|
|
|
2015-03-18 11:35:38 +03:00
|
|
|
/**
|
|
|
|
* Searches for physics shapes that intersects the ray.
|
|
|
|
*
|
|
|
|
* Query this physics world along the line segment from start to end.
|
|
|
|
* @param func Func is called for each shape found.
|
|
|
|
* @param start A Vec2 object contains the begin position of the ray.
|
|
|
|
* @param end A Vec2 object contains the end position of the ray.
|
|
|
|
* @param data User defined data, it is passed to func.
|
|
|
|
*/
|
2014-05-14 21:07:09 +04:00
|
|
|
void rayCast(PhysicsRayCastCallbackFunc func, const Vec2& start, const Vec2& end, void* data);
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Searches for physics shapes that contains in the rect.
|
|
|
|
*
|
|
|
|
* Query this physics world to find all shapes overlap rect.
|
|
|
|
* @param func Func is called for each shape whose bounding box overlaps rect.
|
|
|
|
* @param rect A Rect object contains a rectangle's x, y, width and height.
|
|
|
|
* @param data User defined data, it is passed to func.
|
|
|
|
*/
|
2013-12-13 12:26:26 +04:00
|
|
|
void queryRect(PhysicsQueryRectCallbackFunc func, const Rect& rect, void* data);
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Searches for physics shapes that contains the point.
|
|
|
|
*
|
|
|
|
* @attention The point must lie inside a shape.
|
|
|
|
* @param func Func is called for each shape contains the point.
|
|
|
|
* @param point A Vec2 object contains the position of the point.
|
|
|
|
* @param data User defined data, it is passed to func.
|
|
|
|
*/
|
2014-05-14 21:07:09 +04:00
|
|
|
void queryPoint(PhysicsQueryPointCallbackFunc func, const Vec2& point, void* data);
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get phsyics shapes that contains the point.
|
|
|
|
*
|
|
|
|
* All shapes contains the point will be pushed in a Vector<PhysicsShape*> object.
|
|
|
|
* @attention The point must lie inside a shape.
|
|
|
|
* @param point A Vec2 object contains the position of the point.
|
|
|
|
* @return A Vector<PhysicsShape*> object contains all found PhysicsShape pointer.
|
|
|
|
*/
|
2014-05-14 21:07:09 +04:00
|
|
|
Vector<PhysicsShape*> getShapes(const Vec2& point) const;
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the nearest phsyics shape that contains the point.
|
|
|
|
*
|
|
|
|
* Query this physics world at point and return the closest shape.
|
|
|
|
* @param point A Vec2 object contains the position of the point.
|
|
|
|
* @return A PhysicsShape object pointer or nullptr if no shapes were found
|
|
|
|
*/
|
2014-05-14 21:07:09 +04:00
|
|
|
PhysicsShape* getShape(const Vec2& point) const;
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all the bodys that in this physics world.
|
|
|
|
*
|
|
|
|
* @return A Vector<PhysicsBody*>& object contains all bodies in this physics world.
|
|
|
|
*/
|
2013-12-07 06:48:02 +04:00
|
|
|
const Vector<PhysicsBody*>& getAllBodies() const;
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a body by tag.
|
|
|
|
*
|
|
|
|
* @param tag An interger number that identifies a PhysicsBody object.
|
|
|
|
* @return A PhysicsBody object pointer or nullptr if no shapes were found.
|
|
|
|
*/
|
2013-11-05 16:02:58 +04:00
|
|
|
PhysicsBody* getBody(int tag) const;
|
2013-09-09 06:29:02 +04:00
|
|
|
|
2015-03-18 11:35:38 +03:00
|
|
|
/**
|
|
|
|
* Get a scene contain this physics world.
|
|
|
|
*
|
|
|
|
* @attention This value is initialized in constructor
|
|
|
|
* @return A Scene object reference.
|
|
|
|
*/
|
2014-05-02 03:42:35 +04:00
|
|
|
inline Scene& getScene() const { return *_scene; }
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the gravity value of this physics world.
|
|
|
|
*
|
|
|
|
* @return A Vect object.
|
|
|
|
*/
|
2013-11-07 10:17:57 +04:00
|
|
|
inline Vect getGravity() const { return _gravity; }
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* set the gravity value of this physics world.
|
|
|
|
*
|
|
|
|
* @param gravity A gravity value of this physics world.
|
|
|
|
*/
|
2013-11-07 10:17:57 +04:00
|
|
|
void setGravity(const Vect& gravity);
|
2015-03-18 11:35:38 +03:00
|
|
|
|
2014-06-12 08:45:21 +04:00
|
|
|
/**
|
2015-03-18 11:35:38 +03:00
|
|
|
* Set the speed of this physics world.
|
|
|
|
*
|
|
|
|
* @attention if you setAutoStep(false), this won't work.
|
|
|
|
* @param speed A float number. Speed is the rate at which the simulation executes. default value is 1.0.
|
2014-06-12 08:45:21 +04:00
|
|
|
*/
|
2013-12-13 12:26:26 +04:00
|
|
|
inline void setSpeed(float speed) { if(speed >= 0.0f) { _speed = speed; } }
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the speed of this physics world.
|
|
|
|
*
|
|
|
|
* @return A float number.
|
|
|
|
*/
|
2013-12-13 12:26:26 +04:00
|
|
|
inline float getSpeed() { return _speed; }
|
2015-03-18 11:35:38 +03:00
|
|
|
|
2014-06-12 08:45:21 +04:00
|
|
|
/**
|
2015-03-18 11:35:38 +03:00
|
|
|
* Set the update rate of this physics world
|
|
|
|
*
|
|
|
|
* Update rate is the value of EngineUpdateTimes/PhysicsWorldUpdateTimes.
|
|
|
|
* Set it higher can improve performance, set it lower can improve accuracy of physics world simulation.
|
|
|
|
* @attention if you setAutoStep(false), this won't work.
|
|
|
|
* @param rate An interger number, default value is 1.0.
|
2013-12-13 12:26:26 +04:00
|
|
|
*/
|
|
|
|
inline void setUpdateRate(int rate) { if(rate > 0) { _updateRate = rate; } }
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the update rate of this physics world.
|
|
|
|
*
|
|
|
|
* @return An interger number.
|
|
|
|
*/
|
2013-12-13 12:26:26 +04:00
|
|
|
inline int getUpdateRate() { return _updateRate; }
|
2015-03-18 11:35:38 +03:00
|
|
|
|
2014-09-08 02:14:40 +04:00
|
|
|
/**
|
|
|
|
* set the number of substeps in an update of the physics world.
|
2015-03-18 11:35:38 +03:00
|
|
|
*
|
2014-09-08 02:14:40 +04:00
|
|
|
* One physics update will be divided into several substeps to increase its accuracy.
|
2015-03-18 11:35:38 +03:00
|
|
|
* @param steps An interger number, default value is 1.
|
2014-09-08 02:14:40 +04:00
|
|
|
*/
|
|
|
|
void setSubsteps(int steps);
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of substeps of this physics world.
|
|
|
|
*
|
|
|
|
* @return An interger number.
|
|
|
|
*/
|
2014-09-08 02:14:40 +04:00
|
|
|
inline int getSubsteps() const { return _substeps; }
|
|
|
|
|
2015-03-18 11:35:38 +03:00
|
|
|
/**
|
|
|
|
* Set the debug draw mask of this physics world.
|
|
|
|
*
|
|
|
|
* This physics world will draw shapes and joints by DrawNode acoording to mask.
|
|
|
|
* @param mask Mask has four value:DEBUGDRAW_NONE, DEBUGDRAW_SHAPE, DEBUGDRAW_JOINT, DEBUGDRAW_CONTACT and DEBUGDRAW_ALL, default is DEBUGDRAW_NONE
|
|
|
|
*/
|
2013-11-08 10:25:03 +04:00
|
|
|
void setDebugDrawMask(int mask);
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the bebug draw mask.
|
|
|
|
*
|
|
|
|
* @return An interger number.
|
|
|
|
*/
|
2013-11-08 10:25:03 +04:00
|
|
|
inline int getDebugDrawMask() { return _debugDrawMask; }
|
2013-09-16 17:22:22 +04:00
|
|
|
|
2014-06-12 08:45:21 +04:00
|
|
|
/**
|
2015-03-18 11:35:38 +03:00
|
|
|
* To control the step of physics.
|
|
|
|
*
|
|
|
|
* If you want control it by yourself( fixed-timestep for example ), you can set this to false and call step by yourself.
|
|
|
|
* @attention If you set auto step to false, setSpeed setSubsteps and setUpdateRate won't work, you need to control the time step by yourself.
|
|
|
|
* @param autoStep A bool object, defaut value is true.
|
2014-06-12 08:45:21 +04:00
|
|
|
*/
|
|
|
|
void setAutoStep(bool autoStep){ _autoStep = autoStep; }
|
2015-03-18 11:35:38 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the auto step of this physics world.
|
|
|
|
*
|
|
|
|
* @return A bool object.
|
|
|
|
*/
|
2014-06-12 08:45:21 +04:00
|
|
|
bool isAutoStep() { return _autoStep; }
|
2015-03-18 11:35:38 +03:00
|
|
|
|
2014-06-12 08:45:21 +04:00
|
|
|
/**
|
2015-03-18 11:35:38 +03:00
|
|
|
* The step for physics world.
|
|
|
|
*
|
|
|
|
* The times passing for simulate the physics.
|
|
|
|
* @attention You need to setAutoStep(false) first before it can work.
|
|
|
|
* @param delta A float number.
|
2014-06-12 08:45:21 +04:00
|
|
|
*/
|
|
|
|
void step(float delta);
|
|
|
|
|
2013-09-09 06:29:02 +04:00
|
|
|
protected:
|
2014-05-02 03:42:35 +04:00
|
|
|
static PhysicsWorld* construct(Scene& scene);
|
|
|
|
bool init(Scene& scene);
|
2013-09-16 17:22:22 +04:00
|
|
|
|
2013-11-07 10:40:09 +04:00
|
|
|
virtual void addBody(PhysicsBody* body);
|
|
|
|
virtual void addShape(PhysicsShape* shape);
|
2013-09-29 05:39:20 +04:00
|
|
|
virtual void removeShape(PhysicsShape* shape);
|
2014-06-12 08:45:21 +04:00
|
|
|
virtual void update(float delta, bool userCall = false);
|
2013-09-16 17:22:22 +04:00
|
|
|
|
|
|
|
virtual void debugDraw();
|
|
|
|
|
2013-10-18 11:34:13 +04:00
|
|
|
virtual int collisionBeginCallback(PhysicsContact& contact);
|
2013-10-25 06:31:22 +04:00
|
|
|
virtual int collisionPreSolveCallback(PhysicsContact& contact);
|
|
|
|
virtual void collisionPostSolveCallback(PhysicsContact& contact);
|
2013-10-18 11:34:13 +04:00
|
|
|
virtual void collisionSeparateCallback(PhysicsContact& contact);
|
2013-09-09 06:29:02 +04:00
|
|
|
|
2013-11-07 11:12:13 +04:00
|
|
|
virtual void doAddBody(PhysicsBody* body);
|
|
|
|
virtual void doRemoveBody(PhysicsBody* body);
|
|
|
|
virtual void doRemoveJoint(PhysicsJoint* joint);
|
|
|
|
virtual void addBodyOrDelay(PhysicsBody* body);
|
|
|
|
virtual void removeBodyOrDelay(PhysicsBody* body);
|
2013-11-04 15:26:34 +04:00
|
|
|
virtual void updateBodies();
|
|
|
|
virtual void updateJoints();
|
|
|
|
|
2013-09-09 06:29:02 +04:00
|
|
|
protected:
|
2013-11-07 10:17:57 +04:00
|
|
|
Vect _gravity;
|
2013-09-09 06:29:02 +04:00
|
|
|
float _speed;
|
2013-12-13 12:26:26 +04:00
|
|
|
int _updateRate;
|
|
|
|
int _updateRateCount;
|
|
|
|
float _updateTime;
|
2014-09-08 02:14:40 +04:00
|
|
|
int _substeps;
|
2015-01-06 05:29:07 +03:00
|
|
|
cpSpace* _cpSpace;
|
2013-09-09 06:29:02 +04:00
|
|
|
|
2015-01-27 11:13:45 +03:00
|
|
|
bool _updateBodyTransform;
|
2013-12-07 06:48:02 +04:00
|
|
|
Vector<PhysicsBody*> _bodies;
|
2013-09-29 05:39:20 +04:00
|
|
|
std::list<PhysicsJoint*> _joints;
|
2014-05-02 03:42:35 +04:00
|
|
|
Scene* _scene;
|
2013-09-16 17:22:22 +04:00
|
|
|
|
2014-06-12 08:45:21 +04:00
|
|
|
bool _autoStep;
|
2013-11-08 10:25:03 +04:00
|
|
|
PhysicsDebugDraw* _debugDraw;
|
|
|
|
int _debugDrawMask;
|
|
|
|
|
2013-09-09 06:29:02 +04:00
|
|
|
|
2013-12-07 06:48:02 +04:00
|
|
|
Vector<PhysicsBody*> _delayAddBodies;
|
|
|
|
Vector<PhysicsBody*> _delayRemoveBodies;
|
2013-11-04 15:26:34 +04:00
|
|
|
std::vector<PhysicsJoint*> _delayAddJoints;
|
|
|
|
std::vector<PhysicsJoint*> _delayRemoveJoints;
|
|
|
|
|
2013-09-09 06:29:02 +04:00
|
|
|
protected:
|
|
|
|
PhysicsWorld();
|
|
|
|
virtual ~PhysicsWorld();
|
2013-09-09 12:36:19 +04:00
|
|
|
|
2014-02-26 06:53:41 +04:00
|
|
|
friend class Node;
|
2013-09-09 12:36:19 +04:00
|
|
|
friend class Sprite;
|
2014-05-02 03:42:35 +04:00
|
|
|
friend class Scene;
|
2015-01-07 12:08:04 +03:00
|
|
|
friend class Director;
|
2013-09-16 17:22:22 +04:00
|
|
|
friend class PhysicsBody;
|
2013-09-29 05:39:20 +04:00
|
|
|
friend class PhysicsShape;
|
2013-11-07 10:17:57 +04:00
|
|
|
friend class PhysicsJoint;
|
2013-10-21 19:16:21 +04:00
|
|
|
friend class PhysicsWorldCallback;
|
2013-11-08 10:25:03 +04:00
|
|
|
friend class PhysicsDebugDraw;
|
|
|
|
};
|
|
|
|
|
2015-03-19 12:58:08 +03:00
|
|
|
/** A physics helper class. Draw physics shape, joint in debug mode.
|
|
|
|
|
|
|
|
* You do not create PhysicsDebugDraw objects directly; Instead, you can activate it by PhysicsWorld::setDebugDrawMask.
|
|
|
|
*/
|
2014-07-17 16:58:50 +04:00
|
|
|
class CC_DLL PhysicsDebugDraw
|
2013-11-08 10:25:03 +04:00
|
|
|
{
|
2013-11-08 12:17:56 +04:00
|
|
|
protected:
|
2013-11-08 10:25:03 +04:00
|
|
|
virtual bool begin();
|
|
|
|
virtual void end();
|
|
|
|
virtual void drawShape(PhysicsShape& shape);
|
|
|
|
virtual void drawJoint(PhysicsJoint& joint);
|
|
|
|
virtual void drawContact();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PhysicsDebugDraw(PhysicsWorld& world);
|
|
|
|
virtual ~PhysicsDebugDraw();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
DrawNode* _drawNode;
|
|
|
|
PhysicsWorld& _world;
|
|
|
|
|
|
|
|
friend class PhysicsWorld;
|
2013-09-09 06:29:02 +04:00
|
|
|
};
|
2014-07-15 08:00:31 +04:00
|
|
|
extern const float CC_DLL PHYSICS_INFINITY;
|
2013-09-09 06:29:02 +04:00
|
|
|
|
2015-03-18 11:35:38 +03:00
|
|
|
/** @} */
|
2015-06-15 05:28:37 +03:00
|
|
|
/** @} */
|
|
|
|
|
2013-09-09 06:29:02 +04:00
|
|
|
NS_CC_END
|
|
|
|
|
2013-09-10 13:36:49 +04:00
|
|
|
#endif // CC_USE_PHYSICS
|
2013-11-06 10:51:56 +04:00
|
|
|
#endif // __CCPHYSICS_WORLD_H__
|