An PhysicsWorld object simulates collisions and other physical properties. More...
#include <CCPhysicsWorld.h>
Public Member Functions | |
| virtual void | addJoint (PhysicsJoint *joint) |
| Adds a joint to this physics world. More... | |
| var | addJoint ( var joint) |
| Adds a joint to this physics world. More... | |
| local | addJoint ( local joint) |
| Adds a joint to this physics world. More... | |
| virtual void | removeJoint (PhysicsJoint *joint, bool destroy=true) |
| Remove a joint from this physics world. More... | |
| local | removeJoint ( local joint, local true) |
| Remove a joint from this physics world. More... | |
| virtual void | removeAllJoints (bool destroy=true) |
| Remove all joints from this physics world. More... | |
| virtual void | removeBody (PhysicsBody *body) |
| Remove a body from this physics world. More... | |
| local | removeBody ( local body) |
| Remove a body from this physics world. More... | |
| virtual void | removeBody (int tag) |
| Remove body by tag. More... | |
| var | removeBody ( var tag) |
| Remove body by tag. More... | |
| local | removeBody ( local tag) |
| Remove body by tag. More... | |
| virtual void | removeAllBodies () |
| Remove all bodies from physics world. More... | |
| void | rayCast (PhysicsRayCastCallbackFunc func, const Vec2 &start, const Vec2 &end, void *data) |
| Searches for physics shapes that intersects the ray. More... | |
| local | rayCast ( local func, local start, local end, local data) |
| Searches for physics shapes that intersects the ray. More... | |
| void | queryRect (PhysicsQueryRectCallbackFunc func, const Rect &rect, void *data) |
| Searches for physics shapes that contains in the rect. More... | |
| void | queryPoint (PhysicsQueryPointCallbackFunc func, const Vec2 &point, void *data) |
| Searches for physics shapes that contains the point. More... | |
| Vector< PhysicsShape * > | getShapes (const Vec2 &point) const |
| Get phsyics shapes that contains the point. More... | |
| PhysicsShape * | getShape (const Vec2 &point) const |
| Get the nearest phsyics shape that contains the point. More... | |
| const Vector< PhysicsBody * > & | getAllBodies () const |
| Get all the bodys that in this physics world. More... | |
| PhysicsBody * | getBody (int tag) const |
| Get a body by tag. More... | |
| local | getBody ( local tag) |
| Get a body by tag. More... | |
| Scene & | getScene () const |
| Get a scene contain this physics world. More... | |
| Vect | getGravity () const |
| Get the gravity value of this physics world. More... | |
| void | setGravity (const Vect &gravity) |
| set the gravity value of this physics world. More... | |
| local | setGravity ( local gravity) |
| set the gravity value of this physics world. More... | |
| void | setSpeed (float speed) |
| Set the speed of this physics world. More... | |
| float | getSpeed () |
| Get the speed of this physics world. More... | |
| void | setUpdateRate (int rate) |
| Set the update rate of this physics world. More... | |
| local | setUpdateRate ( local rate) |
| Set the update rate of this physics world. More... | |
| int | getUpdateRate () |
| Get the update rate of this physics world. More... | |
| void | setSubsteps (int steps) |
| set the number of substeps in an update of the physics world. More... | |
| int | getSubsteps () const |
| Get the number of substeps of this physics world. More... | |
| void | setDebugDrawMask (int mask) |
| Set the debug draw mask of this physics world. More... | |
| int | getDebugDrawMask () |
| Get the bebug draw mask. More... | |
| void | setAutoStep (bool autoStep) |
| To control the step of physics. More... | |
| bool | isAutoStep () |
| Get the auto step of this physics world. More... | |
| void | step (float delta) |
| The step for physics world. More... | |
Static Public Attributes | |
| static const int | DEBUGDRAW_NONE |
| draw nothing More... | |
| static const int | DEBUGDRAW_SHAPE |
| draw shapes More... | |
| var | DEBUGDRAW_SHAPE |
| draw shapes More... | |
| local | DEBUGDRAW_SHAPE |
| draw shapes More... | |
| static const int | DEBUGDRAW_JOINT |
| draw joints More... | |
| local | DEBUGDRAW_JOINT |
| draw joints More... | |
| static const int | DEBUGDRAW_CONTACT |
| draw contact More... | |
| var | DEBUGDRAW_CONTACT |
| draw contact More... | |
| local | DEBUGDRAW_CONTACT |
| draw contact More... | |
| static const int | DEBUGDRAW_ALL |
| draw all More... | |
Protected Member Functions | |
| bool | init (Scene &scene) |
| virtual void | addBody (PhysicsBody *body) |
| var | addBody ( var body) |
| local | addBody ( local body) |
| virtual void | addShape (PhysicsShape *shape) |
| virtual void | removeShape (PhysicsShape *shape) |
| var | removeShape ( var shape) |
| local | removeShape ( local shape) |
| virtual void | update (float delta, bool userCall=false) |
| local | update ( local delta, local false) |
| virtual void | debugDraw () |
| virtual int | collisionBeginCallback (PhysicsContact &contact) |
| local | collisionBeginCallback ( local contact) |
| virtual int | collisionPreSolveCallback (PhysicsContact &contact) |
| virtual void | collisionPostSolveCallback (PhysicsContact &contact) |
| local | collisionPostSolveCallback ( local contact) |
| virtual void | collisionSeparateCallback (PhysicsContact &contact) |
| var | collisionSeparateCallback ( var contact) |
| local | collisionSeparateCallback ( local contact) |
| 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) |
| var | removeBodyOrDelay ( var body) |
| local | removeBodyOrDelay ( local body) |
| virtual void | updateBodies () |
| virtual void | updateJoints () |
| PhysicsWorld () | |
| virtual | ~PhysicsWorld () |
Static Protected Member Functions | |
| static PhysicsWorld * | construct (Scene &scene) |
Protected Attributes | |
| Vect | _gravity |
| float | _speed |
| int | _updateRate |
| int | _updateRateCount |
| float | _updateTime |
| int | _substeps |
| cpSpace * | _cpSpace |
| bool | _updateBodyTransform |
| Vector< PhysicsBody * > | _bodies |
| std::list< PhysicsJoint * > | _joints |
| var | _joints |
| local | _joints |
| Scene * | _scene |
| bool | _autoStep |
| PhysicsDebugDraw * | _debugDraw |
| int | _debugDrawMask |
| Vector< PhysicsBody * > | _delayAddBodies |
| var | _delayAddBodies |
| local | _delayAddBodies |
| Vector< PhysicsBody * > | _delayRemoveBodies |
| var | _delayRemoveBodies |
| local | _delayRemoveBodies |
| std::vector< PhysicsJoint * > | _delayAddJoints |
| std::vector< PhysicsJoint * > | _delayRemoveJoints |
| var | _delayRemoveJoints |
| local | _delayRemoveJoints |
Friends | |
| class | Node |
| class | Sprite |
| class | Scene |
| class | Director |
| class | PhysicsBody |
| class | PhysicsShape |
| class | PhysicsJoint |
| class | PhysicsWorldCallback |
| class | PhysicsDebugDraw |
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.
|
protected |
|
protected |
|
protected |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
virtual |
Adds a joint to this physics world.
This joint will be added to this physics world at next frame.
| joint | A pointer to an existing PhysicsJoint object. |
|
virtual |
Adds a joint to this physics world.
This joint will be added to this physics world at next frame.
| joint | A pointer to an existing PhysicsJoint object. |
|
virtual |
Adds a joint to this physics world.
This joint will be added to this physics world at next frame.
| joint | A pointer to an existing PhysicsJoint object. |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
| const Vector<PhysicsBody*> & getAllBodies |
( | ) | const |
Get all the bodys that in this physics world.
| var getAllBodies | ( | ) |
Get all the bodys that in this physics world.
| local getAllBodies | ( | ) |
Get all the bodys that in this physics world.
| PhysicsBody* getBody | ( | int | tag | ) | const |
Get a body by tag.
| tag | An interger number that identifies a PhysicsBody object. |
| var getBody | ( | var | tag | ) |
Get a body by tag.
| tag | An interger number that identifies a PhysicsBody object. |
| local getBody | ( | local | tag | ) |
Get a body by tag.
| tag | An interger number that identifies a PhysicsBody object. |
|
inline |
Get the bebug draw mask.
|
inline |
Get the bebug draw mask.
|
inline |
Get the bebug draw mask.
|
inline |
Get the gravity value of this physics world.
|
inline |
Get the gravity value of this physics world.
|
inline |
Get the gravity value of this physics world.
|
inline |
Get a scene contain this physics world.
|
inline |
Get a scene contain this physics world.
|
inline |
Get a scene contain this physics world.
| PhysicsShape* getShape | ( | const Vec2 & | point | ) | const |
Get the nearest phsyics shape that contains the point.
Query this physics world at point and return the closest shape.
| point | A Vec2 object contains the position of the point. |
| var getShape | ( | var | point | ) |
Get the nearest phsyics shape that contains the point.
Query this physics world at point and return the closest shape.
| point | A Vec2 object contains the position of the point. |
| local getShape | ( | local | point | ) |
Get the nearest phsyics shape that contains the point.
Query this physics world at point and return the closest shape.
| point | A Vec2 object contains the position of the point. |
| Vector<PhysicsShape*> getShapes | ( | const Vec2 & | point | ) | const |
Get phsyics shapes that contains the point.
All shapes contains the point will be pushed in a Vector<PhysicsShape*> object.
| point | A Vec2 object contains the position of the point. |
| var getShapes | ( | var | point | ) |
Get phsyics shapes that contains the point.
All shapes contains the point will be pushed in a Vector<PhysicsShape*> object.
| point | A Vec2 object contains the position of the point. |
| local getShapes | ( | local | point | ) |
Get phsyics shapes that contains the point.
All shapes contains the point will be pushed in a Vector<PhysicsShape*> object.
| point | A Vec2 object contains the position of the point. |
|
inline |
Get the speed of this physics world.
|
inline |
Get the speed of this physics world.
|
inline |
Get the speed of this physics world.
|
inline |
Get the number of substeps of this physics world.
|
inline |
Get the number of substeps of this physics world.
|
inline |
Get the number of substeps of this physics world.
|
inline |
Get the update rate of this physics world.
|
inline |
Get the update rate of this physics world.
|
inline |
Get the update rate of this physics world.
|
protected |
|
protected |
|
protected |
|
inline |
Get the auto step of this physics world.
|
inline |
Get the auto step of this physics world.
|
inline |
Get the auto step of this physics world.
| void queryPoint | ( | PhysicsQueryPointCallbackFunc | func, |
| const Vec2 & | point, | ||
| void * | data | ||
| ) |
Searches for physics shapes that contains the point.
| func | Func is called for each shape contains the point. |
| point | A Vec2 object contains the position of the point. |
| data | User defined data, it is passed to func. |
| var queryPoint | ( | var | func, |
| var | point, | ||
| var | data | ||
| ) |
Searches for physics shapes that contains the point.
| func | Func is called for each shape contains the point. |
| point | A Vec2 object contains the position of the point. |
| data | User defined data, it is passed to func. |
| local queryPoint | ( | local | func, |
| local | point, | ||
| local | data | ||
| ) |
Searches for physics shapes that contains the point.
| func | Func is called for each shape contains the point. |
| point | A Vec2 object contains the position of the point. |
| data | User defined data, it is passed to func. |
| void queryRect | ( | PhysicsQueryRectCallbackFunc | func, |
| const Rect & | rect, | ||
| void * | data | ||
| ) |
Searches for physics shapes that contains in the rect.
Query this physics world to find all shapes overlap rect.
| func | Func is called for each shape whose bounding box overlaps rect. |
| rect | A Rect object contains a rectangle's x, y, width and height. |
| data | User defined data, it is passed to func. |
| var queryRect | ( | var | func, |
| var | rect, | ||
| var | data | ||
| ) |
Searches for physics shapes that contains in the rect.
Query this physics world to find all shapes overlap rect.
| func | Func is called for each shape whose bounding box overlaps rect. |
| rect | A Rect object contains a rectangle's x, y, width and height. |
| data | User defined data, it is passed to func. |
| local queryRect | ( | local | func, |
| local | rect, | ||
| local | data | ||
| ) |
Searches for physics shapes that contains in the rect.
Query this physics world to find all shapes overlap rect.
| func | Func is called for each shape whose bounding box overlaps rect. |
| rect | A Rect object contains a rectangle's x, y, width and height. |
| data | User defined data, it is passed to func. |
| void rayCast | ( | PhysicsRayCastCallbackFunc | func, |
| const Vec2 & | start, | ||
| const Vec2 & | end, | ||
| void * | data | ||
| ) |
Searches for physics shapes that intersects the ray.
Query this physics world along the line segment from start to end.
| var rayCast | ( | var | func, |
| var | start, | ||
| var | end, | ||
| var | data | ||
| ) |
Searches for physics shapes that intersects the ray.
Query this physics world along the line segment from start to end.
| local rayCast | ( | local | func, |
| local | start, | ||
| local | end, | ||
| local | data | ||
| ) |
Searches for physics shapes that intersects the ray.
Query this physics world along the line segment from start to end.
|
virtual |
Remove all bodies from physics world.
If this world is not locked, those body are removed immediately, otherwise at next frame.
|
virtual |
Remove all bodies from physics world.
If this world is not locked, those body are removed immediately, otherwise at next frame.
|
virtual |
Remove all bodies from physics world.
If this world is not locked, those body are removed immediately, otherwise at next frame.
|
virtual |
Remove all joints from this physics world.
| destroy | true all joints will be destroyed after remove from this world, false otherwise. |
|
virtual |
Remove all joints from this physics world.
| destroy | true all joints will be destroyed after remove from this world, false otherwise. |
|
virtual |
Remove all joints from this physics world.
| destroy | true all joints will be destroyed after remove from this world, false otherwise. |
|
virtual |
Remove a body from this physics world.
If this world is not locked, the body is removed immediately, otherwise at next frame.
| body | A pointer to an existing PhysicsBody object. |
|
virtual |
Remove a body from this physics world.
If this world is not locked, the body is removed immediately, otherwise at next frame.
| body | A pointer to an existing PhysicsBody object. |
|
virtual |
Remove a body from this physics world.
If this world is not locked, the body is removed immediately, otherwise at next frame.
| body | A pointer to an existing PhysicsBody object. |
|
virtual |
Remove body by tag.
If this world is not locked, the object is removed immediately, otherwise at next frame.
| tag | An interger number that identifies a PhysicsBody object. |
|
virtual |
Remove body by tag.
If this world is not locked, the object is removed immediately, otherwise at next frame.
| tag | An interger number that identifies a PhysicsBody object. |
|
virtual |
Remove body by tag.
If this world is not locked, the object is removed immediately, otherwise at next frame.
| tag | An interger number that identifies a PhysicsBody object. |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
virtual |
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.
| joint | A pointer to an existing PhysicsJoint object. |
| destroy | true this joint will be destroyed after remove from this world, false otherwise. |
|
virtual |
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.
| joint | A pointer to an existing PhysicsJoint object. |
| destroy | true this joint will be destroyed after remove from this world, false otherwise. |
|
virtual |
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.
| joint | A pointer to an existing PhysicsJoint object. |
| destroy | true this joint will be destroyed after remove from this world, false otherwise. |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
inline |
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.
| autoStep | A bool object, defaut value is true. |
|
inline |
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.
| autoStep | A bool object, defaut value is true. |
|
inline |
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.
| autoStep | A bool object, defaut value is true. |
| void setDebugDrawMask | ( | int | mask | ) |
Set the debug draw mask of this physics world.
This physics world will draw shapes and joints by DrawNode acoording to mask.
| mask | Mask has four value:DEBUGDRAW_NONE, DEBUGDRAW_SHAPE, DEBUGDRAW_JOINT, DEBUGDRAW_CONTACT and DEBUGDRAW_ALL, default is DEBUGDRAW_NONE |
| var setDebugDrawMask | ( | var | mask | ) |
Set the debug draw mask of this physics world.
This physics world will draw shapes and joints by DrawNode acoording to mask.
| mask | Mask has four value:DEBUGDRAW_NONE, DEBUGDRAW_SHAPE, DEBUGDRAW_JOINT, DEBUGDRAW_CONTACT and DEBUGDRAW_ALL, default is DEBUGDRAW_NONE |
| local setDebugDrawMask | ( | local | mask | ) |
Set the debug draw mask of this physics world.
This physics world will draw shapes and joints by DrawNode acoording to mask.
| mask | Mask has four value:DEBUGDRAW_NONE, DEBUGDRAW_SHAPE, DEBUGDRAW_JOINT, DEBUGDRAW_CONTACT and DEBUGDRAW_ALL, default is DEBUGDRAW_NONE |
| void setGravity | ( | const Vect & | gravity | ) |
set the gravity value of this physics world.
| gravity | A gravity value of this physics world. |
| var setGravity | ( | var | gravity | ) |
set the gravity value of this physics world.
| gravity | A gravity value of this physics world. |
| local setGravity | ( | local | gravity | ) |
set the gravity value of this physics world.
| gravity | A gravity value of this physics world. |
|
inline |
Set the speed of this physics world.
| speed | A float number. Speed is the rate at which the simulation executes. default value is 1.0. |
|
inline |
Set the speed of this physics world.
| speed | A float number. Speed is the rate at which the simulation executes. default value is 1.0. |
|
inline |
Set the speed of this physics world.
| speed | A float number. Speed is the rate at which the simulation executes. default value is 1.0. |
| void setSubsteps | ( | int | steps | ) |
set the number of substeps in an update of the physics world.
One physics update will be divided into several substeps to increase its accuracy.
| steps | An interger number, default value is 1. |
| var setSubsteps | ( | var | steps | ) |
set the number of substeps in an update of the physics world.
One physics update will be divided into several substeps to increase its accuracy.
| steps | An interger number, default value is 1. |
| local setSubsteps | ( | local | steps | ) |
set the number of substeps in an update of the physics world.
One physics update will be divided into several substeps to increase its accuracy.
| steps | An interger number, default value is 1. |
|
inline |
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.
| rate | An interger number, default value is 1.0. |
|
inline |
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.
| rate | An interger number, default value is 1.0. |
|
inline |
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.
| rate | An interger number, default value is 1.0. |
| void step | ( | float | delta | ) |
The step for physics world.
The times passing for simulate the physics.
| delta | A float number. |
| var step | ( | var | delta | ) |
The step for physics world.
The times passing for simulate the physics.
| delta | A float number. |
| local step | ( | local | delta | ) |
The step for physics world.
The times passing for simulate the physics.
| delta | A float number. |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
static |
draw all
|
static |
draw all
|
static |
draw all
|
static |
draw contact
|
static |
draw contact
|
static |
draw contact
|
static |
draw joints
|
static |
draw joints
|
static |
draw joints
|
static |
draw nothing
|
static |
draw nothing
|
static |
draw nothing
|
static |
draw shapes
|
static |
draw shapes
|
static |
draw shapes