A body affect by physics. More...
Inherits Component.
Public Member Functions | |
virtual PhysicsShape * | addShape (PhysicsShape *shape, bool addMassAndMoment=true) |
Add a shape to body. More... | |
void | removeShape (PhysicsShape *shape, bool reduceMassAndMoment=true) |
Remove a shape from body. More... | |
void | removeShape (int tag, bool reduceMassAndMoment=true) |
Remove a shape from body. More... | |
void | removeAllShapes (bool reduceMassAndMoment=true) |
Remove all shapes. More... | |
const Vector< PhysicsShape * > & | getShapes () const |
Get the body shapes. More... | |
PhysicsShape * | getFirstShape () const |
Get the first shape of the body shapes. More... | |
PhysicsShape * | getShape (int tag) const |
get the shape of the body. More... | |
virtual void | applyForce (const Vec2 &force, const Vec2 &offset=Vec2::ZERO) |
Applies a continuous force to body. More... | |
virtual void | resetForces () |
reset all the force applied to body. | |
virtual void | applyImpulse (const Vec2 &impulse, const Vec2 &offset=Vec2::ZERO) |
Applies a immediate force to body. More... | |
virtual void | applyTorque (float torque) |
Applies a torque force to body. More... | |
virtual void | setVelocity (const Vec2 &velocity) |
Set the velocity of a body. More... | |
virtual Vec2 | getVelocity () |
Get the velocity of a body. | |
virtual void | setAngularVelocity (float velocity) |
Set the angular velocity of a body. More... | |
virtual Vec2 | getVelocityAtLocalPoint (const Vec2 &point) |
Get the angular velocity of a body at a local point. | |
virtual Vec2 | getVelocityAtWorldPoint (const Vec2 &point) |
get the angular velocity of a body at a world point | |
virtual float | getAngularVelocity () |
get the angular velocity of a body | |
virtual void | setVelocityLimit (float limit) |
set the max of velocity | |
virtual float | getVelocityLimit () |
get the max of velocity | |
virtual void | setAngularVelocityLimit (float limit) |
set the max of angular velocity | |
virtual float | getAngularVelocityLimit () |
get the max of angular velocity | |
void | removeFromWorld () |
remove the body from the world it added to | |
PhysicsWorld * | getWorld () const |
get the world body added to. | |
const std::vector< PhysicsJoint * > & | getJoints () const |
get all joints the body have | |
Node * | getNode () const |
get the node the body set to. | |
void | setCategoryBitmask (int bitmask) |
A mask that defines which categories this physics body belongs to. More... | |
void | setContactTestBitmask (int bitmask) |
A mask that defines which categories of bodies cause intersection notifications with this physics body. More... | |
void | setCollisionBitmask (int bitmask) |
A mask that defines which categories of physics bodies can collide with this physics body. More... | |
int | getCategoryBitmask () const |
Return bitmask of first shape. More... | |
int | getContactTestBitmask () const |
Return bitmask of first shape. More... | |
int | getCollisionBitmask () const |
Return bitmask of first shape. More... | |
void | setGroup (int group) |
Set the group of body. More... | |
int | getGroup () const |
Return group of first shape. More... | |
Vec2 | getPosition () const |
get the body position. | |
float | getRotation () |
get the body rotation. | |
void | setPositionOffset (const Vec2 &position) |
set body position offset, it's the position witch relative to node | |
const Vec2 & | getPositionOffset () const |
get body position offset. | |
void | setRotationOffset (float rotation) |
set body rotation offset, it's the rotation witch relative to node | |
float | getRotationOffset () const |
set the body rotation offset | |
bool | isDynamic () const |
Test the body is dynamic or not. More... | |
void | setDynamic (bool dynamic) |
Set dynamic to body. More... | |
void | setMass (float mass) |
Set the body mass. More... | |
float | getMass () const |
Get the body mass. | |
void | addMass (float mass) |
Add mass to body. More... | |
void | setMoment (float moment) |
Set the body moment of inertia. More... | |
float | getMoment () const |
Get the body moment of inertia. | |
void | addMoment (float moment) |
Add moment of inertia to body. More... | |
float | getLinearDamping () const |
get linear damping. | |
void | setLinearDamping (float damping) |
Set linear damping. More... | |
float | getAngularDamping () const |
Get angular damping. | |
void | setAngularDamping (float damping) |
Set angular damping. More... | |
bool | isResting () const |
Whether the body is at rest. | |
void | setResting (bool rest) const |
set body to rest | |
virtual void | setEnabled (bool enable) override |
Set the enable value. More... | |
bool | isRotationEnabled () const |
Whether the body can rotation. | |
void | setRotationEnable (bool enable) |
Set the body is allow rotation or not. | |
bool | isGravityEnabled () const |
Whether this physics body is affected by the physics world's gravitational force. | |
void | setGravityEnable (bool enable) |
Set the body is affected by the physics world's gravitational force or not. | |
int | getTag () const |
Get the body's tag. | |
void | setTag (int tag) |
set the body's tag. | |
Vec2 | world2Local (const Vec2 &point) |
Convert the world point to local. | |
Vec2 | local2World (const Vec2 &point) |
Convert the local point to world. | |
cpBody * | getCPBody () const |
Get the rigid body of chipmunk. | |
Static Public Member Functions | |
static PhysicsBody * | create () |
Create a body with default mass and moment. More... | |
static PhysicsBody * | create (float mass) |
Create a body with mass and default moment. More... | |
static PhysicsBody * | create (float mass, float moment) |
Create a body with mass and moment. More... | |
static PhysicsBody * | createCircle (float radius, const PhysicsMaterial &material=PHYSICSBODY_MATERIAL_DEFAULT, const Vec2 &offset=Vec2::ZERO) |
Create a body contains a circle. More... | |
static PhysicsBody * | createBox (const Size &size, const PhysicsMaterial &material=PHYSICSBODY_MATERIAL_DEFAULT, const Vec2 &offset=Vec2::ZERO) |
Create a body contains a box shape. More... | |
static PhysicsBody * | createPolygon (const Vec2 *points, int count, const PhysicsMaterial &material=PHYSICSBODY_MATERIAL_DEFAULT, const Vec2 &offset=Vec2::ZERO) |
Create a body contains a polygon shape. More... | |
static PhysicsBody * | createEdgeSegment (const Vec2 &a, const Vec2 &b, const PhysicsMaterial &material=PHYSICSBODY_MATERIAL_DEFAULT, float border=1) |
Create a body contains a EdgeSegment shape. More... | |
static PhysicsBody * | createEdgeBox (const Size &size, const PhysicsMaterial &material=PHYSICSBODY_MATERIAL_DEFAULT, float border=1, const Vec2 &offset=Vec2::ZERO) |
Create a body contains a EdgeBox shape. More... | |
static PhysicsBody * | createEdgePolygon (const Vec2 *points, int count, const PhysicsMaterial &material=PHYSICSBODY_MATERIAL_DEFAULT, float border=1) |
Create a body contains a EdgePolygon shape. More... | |
static PhysicsBody * | createEdgeChain (const Vec2 *points, int count, const PhysicsMaterial &material=PHYSICSBODY_MATERIAL_DEFAULT, float border=1) |
Create a body contains a EdgeChain shape. More... | |
A body affect by physics.
It can attach one or more shapes. If you create body with createXXX, it will automatically compute mass and moment with density your specified(which is PHYSICSBODY_MATERIAL_DEFAULT by default, and the density value is 0.1f), and it based on the formula: mass = density * area. If you create body with createEdgeXXX, the mass and moment will be PHYSICS_INFINITY by default. And it's a static body. You can change mass and moment with setMass() and setMoment(). And you can change the body to be dynamic or static by use function setDynamic().
|
static |
Create a body with default mass and moment.
This default mass value is 1.0. This default moment value is 200.
|
static |
Create a body with mass and default moment.
mass | This body's mass. |
|
static |
Create a body with mass and moment.
mass | This body's mass. |
moment | This body's moment. |
|
static |
Create a body contains a circle.
radius | A float number, it is the circle's radius. |
material | A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT. |
offset | A Vec2 object, it is the offset from the body's center of gravity in body local coordinates. |
|
static |
Create a body contains a box shape.
size | Size contains this box's width and height. |
material | A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT. |
offset | A Vec2 object, it is the offset from the body's center of gravity in body local coordinates. |
|
static |
Create a body contains a polygon shape.
points | Points is an array of Vec2 structs defining a convex hull with a clockwise winding. |
count | An integer number, contains the count of the points array. |
material | A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT. |
offset | A Vec2 object, it is the offset from the body's center of gravity in body local coordinates. |
|
static |
Create a body contains a EdgeSegment shape.
a | It's the edge's begin position. |
b | It's the edge's end position. |
material | A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT. |
border | It's a edge's border width. |
|
static |
Create a body contains a EdgeBox shape.
size | Size contains this box's width and height. |
material | A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT. |
border | It's a edge's border width. |
offset | A Vec2 object, it is the offset from the body's center of gravity in body local coordinates. |
|
static |
Create a body contains a EdgePolygon shape.
points | Points is an array of Vec2 structs defining a convex hull with a clockwise winding. |
count | An integer number, contains the count of the points array. |
material | A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT. |
border | It's a edge's border width. |
|
static |
Create a body contains a EdgeChain shape.
points | A Vec2 object pointer, it contains an array of points. |
count | An integer number, contains the count of the points array. |
material | A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT. |
border | It's a edge's border width. |
|
virtual |
Add a shape to body.
shape | The shape to be added. |
addMassAndMoment | If this is true, the shape's mass and moment will be added to body. The default is true. |
void removeShape | ( | PhysicsShape * | shape, |
bool | reduceMassAndMoment = true |
||
) |
Remove a shape from body.
shape | Shape the shape to be removed. |
reduceMassAndMoment | If this is true, the body mass and moment will be reduced by shape. The default is true. |
void removeShape | ( | int | tag, |
bool | reduceMassAndMoment = true |
||
) |
Remove a shape from body.
tag | The tag of the shape to be removed. |
reduceMassAndMoment | If this is true, the body mass and moment will be reduced by shape. The default is true. |
void removeAllShapes | ( | bool | reduceMassAndMoment = true | ) |
Remove all shapes.
reduceMassAndMoment | If this is true, the body mass and moment will be reduced by shape. The default is true. |
|
inline |
Get the body shapes.
|
inline |
Get the first shape of the body shapes.
PhysicsShape* getShape | ( | int | tag | ) | const |
get the shape of the body.
tag | An integer number that identifies a PhysicsShape object. |
|
virtual |
Applies a continuous force to body.
force | The force is applies to this body. |
offset | A Vec2 object, it is the offset from the body's center of gravity in world coordinates. |
|
virtual |
Applies a immediate force to body.
impulse | The impulse is applies to this body. |
offset | A Vec2 object, it is the offset from the body's center of gravity in world coordinates. |
|
virtual |
Applies a torque force to body.
torque | The torque is applies to this body. |
|
virtual |
Set the velocity of a body.
velocity | The velocity is set to this body. |
|
virtual |
Set the angular velocity of a body.
velocity | The angular velocity is set to this body. |
void setCategoryBitmask | ( | int | bitmask | ) |
A mask that defines which categories this physics body belongs to.
Every physics body in a scene can be assigned to up to 32 different categories, each corresponding to a bit in the bit mask. You define the mask values used in your game. In conjunction with the collisionBitMask and contactTestBitMask properties, you define which physics bodies interact with each other and when your game is notified of these interactions.
bitmask | An integer number, the default value is 0xFFFFFFFF (all bits set). |
void setContactTestBitmask | ( | int | bitmask | ) |
A mask that defines which categories of bodies cause intersection notifications with this physics body.
When two bodies share the same space, each body's category mask is tested against the other body's contact mask by performing a logical AND operation. If either comparison results in a non-zero value, an PhysicsContact object is created and passed to the physics world’s delegate. For best performance, only set bits in the contacts mask for interactions you are interested in.
bitmask | An integer number, the default value is 0x00000000 (all bits cleared). |
void setCollisionBitmask | ( | int | bitmask | ) |
A mask that defines which categories of physics bodies can collide with this physics body.
When two physics bodies contact each other, a collision may occur. This body's collision mask is compared to the other body's category mask by performing a logical AND operation. If the result is a non-zero value, then this body is affected by the collision. Each body independently chooses whether it wants to be affected by the other body. For example, you might use this to avoid collision calculations that would make negligible changes to a body's velocity.
bitmask | An integer number, the default value is 0xFFFFFFFF (all bits set). |
int getCategoryBitmask | ( | ) | const |
Return bitmask of first shape.
int getContactTestBitmask | ( | ) | const |
Return bitmask of first shape.
int getCollisionBitmask | ( | ) | const |
Return bitmask of first shape.
void setGroup | ( | int | group | ) |
Set the group of body.
Collision groups let you specify an integral group index. You can have all fixtures with the same group index always collide (positive index) or never collide (negative index). It have high priority than bit masks.
int getGroup | ( | ) | const |
Return group of first shape.
|
inline |
Test the body is dynamic or not.
A dynamic body will effect with gravity.
void setDynamic | ( | bool | dynamic | ) |
Set dynamic to body.
A dynamic body will effect with gravity.
void setMass | ( | float | mass | ) |
void addMass | ( | float | mass | ) |
Add mass to body.
mass | If _mass(mass of the body) == PHYSICS_INFINITY, it remains. if mass == PHYSICS_INFINITY, _mass will be PHYSICS_INFINITY. if mass == -PHYSICS_INFINITY, _mass will not change. if mass + _mass <= 0, _mass will equal to MASS_DEFAULT(1.0) other wise, mass = mass + _mass; |
void setMoment | ( | float | moment | ) |
Set the body moment of inertia.
void addMoment | ( | float | moment | ) |
Add moment of inertia to body.
moment | If _moment(moment of the body) == PHYSICS_INFINITY, it remains. if moment == PHYSICS_INFINITY, _moment will be PHYSICS_INFINITY. if moment == -PHYSICS_INFINITY, _moment will not change. if moment + _moment <= 0, _moment will equal to MASS_DEFAULT(1.0) other wise, moment = moment + _moment; |
|
inline |
Set linear damping.
it is used to simulate fluid or air friction forces on the body.
damping | The value is 0.0f to 1.0f. |
|
inline |
Set angular damping.
It is used to simulate fluid or air friction forces on the body.
damping | The value is 0.0f to 1.0f. |
|
overridevirtual |
Set the enable value.
If the body it isn't enabled, it will not has simulation by world.