cocos2d-x  3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PhysicsWorld Class Reference

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 the physics world. More...
 
virtual void removeJoint (PhysicsJoint *joint, bool destroy=true)
 Remove a joint from physics world. More...
 
virtual void removeAllJoints (bool destroy=true)
 Remove all joints from physics world. More...
 
virtual void removeBody (PhysicsBody *body)
 Remove a body from physics world. More...
 
virtual void removeBody (int 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...
 
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...
 
PhysicsShapegetShape (const Vec2 &point) const
 return physics shape that contains the point. More...
 
const Vector< PhysicsBody * > & getAllBodies () const
 Get all the bodys that in the physics world. More...
 
PhysicsBodygetBody (int tag) const
 Get body by tag. More...
 
ScenegetScene () const
 Get scene contain this physics world. More...
 
Vect getGravity () const
 get the gravity value More...
 
void setGravity (const Vect &gravity)
 set the gravity value More...
 
void setSpeed (float speed)
 Set the speed of physics world, speed is the rate at which the simulation executes. More...
 
float getSpeed ()
 get the speed of physics world More...
 
void setUpdateRate (int rate)
 set the update rate of physics world, update rate is the value of EngineUpdateTimes/PhysicsWorldUpdateTimes. More...
 
int getUpdateRate ()
 get the update rate 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 More...
 
void setDebugDrawMask (int mask)
 set the debug draw mask More...
 
int getDebugDrawMask ()
 get the bebug draw mask More...
 
void setAutoStep (bool autoStep)
 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. More...
 
bool isAutoStep ()
 Get the auto step. More...
 
void step (float delta)
 The step for physics world, The times passing for simulate the physics. More...
 

Static Public Attributes

static const int DEBUGDRAW_NONE
 draw nothing More...
 
static const int DEBUGDRAW_SHAPE
 draw shapes More...
 
static const int DEBUGDRAW_JOINT
 draw joints More...
 
static const int 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)
 
virtual void addShape (PhysicsShape *shape)
 
virtual void removeShape (PhysicsShape *shape)
 
virtual void update (float delta, bool userCall=false)
 
virtual void debugDraw ()
 
virtual int collisionBeginCallback (PhysicsContact &contact)
 
virtual int collisionPreSolveCallback (PhysicsContact &contact)
 
virtual void collisionPostSolveCallback (PhysicsContact &contact)
 
virtual void collisionSeparateCallback (PhysicsContact &contact)
 
virtual void doAddBody (PhysicsBody *body)
 
virtual void doRemoveBody (PhysicsBody *body)
 
virtual void doAddJoint (PhysicsJoint *joint)
 
virtual void doRemoveJoint (PhysicsJoint *joint)
 
virtual void addBodyOrDelay (PhysicsBody *body)
 
virtual void removeBodyOrDelay (PhysicsBody *body)
 
virtual void addJointOrDelay (PhysicsJoint *joint)
 
virtual void removeJointOrDelay (PhysicsJoint *joint)
 
virtual void updateBodies ()
 
virtual void updateJoints ()
 
 PhysicsWorld ()
 
virtual ~PhysicsWorld ()
 

Static Protected Member Functions

static PhysicsWorldconstruct (Scene &scene)
 

Protected Attributes

Vect _gravity
 
float _speed
 
int _updateRate
 
int _updateRateCount
 
float _updateTime
 
int _substeps
 
PhysicsWorldInfo_info
 
Vector< PhysicsBody * > _bodies
 
std::list< PhysicsJoint * > _joints
 
Scene_scene
 
bool _delayDirty
 
bool _autoStep
 
PhysicsDebugDraw_debugDraw
 
int _debugDrawMask
 
Vector< PhysicsBody * > _delayAddBodies
 
Vector< PhysicsBody * > _delayRemoveBodies
 
std::vector< PhysicsJoint * > _delayAddJoints
 
std::vector< PhysicsJoint * > _delayRemoveJoints
 

Friends

class Node
 
class Sprite
 
class Scene
 
class PhysicsBody
 
class PhysicsShape
 
class PhysicsJoint
 
class PhysicsWorldCallback
 
class PhysicsDebugDraw
 

Detailed Description

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.

Constructor & Destructor Documentation

PhysicsWorld ( )
protected
virtual ~PhysicsWorld ( )
protectedvirtual

Member Function Documentation

virtual void addBody ( PhysicsBody body)
protectedvirtual
virtual void addBodyOrDelay ( PhysicsBody body)
protectedvirtual
virtual void addJoint ( PhysicsJoint joint)
virtual

Adds a joint to the physics world.

virtual void addJointOrDelay ( PhysicsJoint joint)
protectedvirtual
virtual void addShape ( PhysicsShape shape)
protectedvirtual
virtual int collisionBeginCallback ( PhysicsContact contact)
protectedvirtual
virtual void collisionPostSolveCallback ( PhysicsContact contact)
protectedvirtual
virtual int collisionPreSolveCallback ( PhysicsContact contact)
protectedvirtual
virtual void collisionSeparateCallback ( PhysicsContact contact)
protectedvirtual
static PhysicsWorld* construct ( Scene scene)
staticprotected
virtual void debugDraw ( )
protectedvirtual
virtual void doAddBody ( PhysicsBody body)
protectedvirtual
virtual void doAddJoint ( PhysicsJoint joint)
protectedvirtual
virtual void doRemoveBody ( PhysicsBody body)
protectedvirtual
virtual void doRemoveJoint ( PhysicsJoint joint)
protectedvirtual
const Vector<PhysicsBody*>& getAllBodies ( ) const

Get all the bodys that in the physics world.

PhysicsBody* getBody ( int  tag) const

Get body by tag.

int getDebugDrawMask ( )
inline

get the bebug draw mask

Vect getGravity ( ) const
inline

get the gravity value

Scene& getScene ( ) const
inline

Get scene contain this physics world.

PhysicsShape* getShape ( const Vec2 point) const

return physics shape that contains the point.

Vector<PhysicsShape*> getShapes ( const Vec2 point) const

Get phsyics shapes that contains the point.

float getSpeed ( )
inline

get the speed of physics world

int getSubsteps ( ) const
inline

get the number of substeps

int getUpdateRate ( )
inline

get the update rate

bool init ( Scene scene)
protected
bool isAutoStep ( )
inline

Get the auto step.

void queryPoint ( PhysicsQueryPointCallbackFunc  func,
const Vec2 point,
void *  data 
)

Searches for physics shapes that contains the point.

void queryRect ( PhysicsQueryRectCallbackFunc  func,
const Rect rect,
void *  data 
)

Searches for physics shapes that contains in the rect.

void rayCast ( PhysicsRayCastCallbackFunc  func,
const Vec2 start,
const Vec2 end,
void *  data 
)

Searches for physics shapes that intersects the ray.

virtual void removeAllBodies ( )
virtual

Remove all bodies from physics world.

virtual void removeAllJoints ( bool  destroy = true)
virtual

Remove all joints from physics world.

virtual void removeBody ( PhysicsBody body)
virtual

Remove a body from physics world.

virtual void removeBody ( int  tag)
virtual

Remove body by tag.

virtual void removeBodyOrDelay ( PhysicsBody body)
protectedvirtual
virtual void removeJoint ( PhysicsJoint joint,
bool  destroy = true 
)
virtual

Remove a joint from physics world.

virtual void removeJointOrDelay ( PhysicsJoint joint)
protectedvirtual
virtual void removeShape ( PhysicsShape shape)
protectedvirtual
void setAutoStep ( bool  autoStep)
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.

Defaut value is true. Note: if you set auto step to false, setSpeed setSubsteps and setUpdateRate won't work, you need to control the time step by yourself.

void setDebugDrawMask ( int  mask)

set the debug draw mask

void setGravity ( const Vect gravity)

set the gravity value

void setSpeed ( float  speed)
inline

Set the speed of physics world, speed is the rate at which the simulation executes.

default value is 1.0 Note: if you setAutoStep(false), this won't work.

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. default value is 1

void setUpdateRate ( int  rate)
inline

set the update rate of 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. default value is 1.0 Note: if you setAutoStep(false), this won't work.

void step ( float  delta)

The step for physics world, The times passing for simulate the physics.

Note: you need to setAutoStep(false) first before it can work.

virtual void update ( float  delta,
bool  userCall = false 
)
protectedvirtual
virtual void updateBodies ( )
protectedvirtual
virtual void updateJoints ( )
protectedvirtual

Friends And Related Function Documentation

friend class Node
friend
friend class PhysicsBody
friend
friend class PhysicsDebugDraw
friend
friend class PhysicsJoint
friend
friend class PhysicsShape
friend
friend class PhysicsWorldCallback
friend
friend class Scene
friend
friend class Sprite
friend

Member Data Documentation

bool _autoStep
protected
Vector<PhysicsBody*> _bodies
protected
PhysicsDebugDraw* _debugDraw
protected
int _debugDrawMask
protected
Vector<PhysicsBody*> _delayAddBodies
protected
std::vector<PhysicsJoint*> _delayAddJoints
protected
bool _delayDirty
protected
Vector<PhysicsBody*> _delayRemoveBodies
protected
std::vector<PhysicsJoint*> _delayRemoveJoints
protected
Vect _gravity
protected
PhysicsWorldInfo* _info
protected
std::list<PhysicsJoint*> _joints
protected
Scene* _scene
protected
float _speed
protected
int _substeps
protected
int _updateRate
protected
int _updateRateCount
protected
float _updateTime
protected
const int DEBUGDRAW_ALL
static

draw all

const int DEBUGDRAW_CONTACT
static

draw contact

const int DEBUGDRAW_JOINT
static

draw joints

const int DEBUGDRAW_NONE
static

draw nothing

const int DEBUGDRAW_SHAPE
static

draw shapes


The documentation for this class was generated from the following file: