cocos2d-x  3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PhysicsShape Class Referenceabstract

A shape for body. More...

#include <CCPhysicsShape.h>

Inheritance diagram for PhysicsShape:
Ref PhysicsShapeCircle PhysicsShapeEdgeChain PhysicsShapeEdgePolygon PhysicsShapeEdgeSegment PhysicsShapePolygon PhysicsShapeEdgeBox PhysicsShapeBox

Public Types

enum  Type {
  UNKNOWN, CIRCLE, BOX, POLYGEN,
  EDGESEGMENT, EDGEBOX, EDGEPOLYGEN, EDGECHAIN
}
 

Public Member Functions

PhysicsBodygetBody () const
 Get the body that this shape attaches. More...
 
Type getType () const
 Return this shape's type. More...
 
float getArea () const
 Return this shape's area. More...
 
float getMoment () const
 Get this shape's moment. More...
 
void setMoment (float moment)
 Set this shape's moment. More...
 
void setTag (int tag)
 Set this shape's tag. More...
 
int getTag () const
 Get this shape's tag. More...
 
float getMass () const
 Get the mass of this shape. More...
 
void setMass (float mass)
 Set this shape's mass. More...
 
float getDensity () const
 Get this shape's density. More...
 
void setDensity (float density)
 Set this shape's density. More...
 
float getRestitution () const
 Get this shape's restitution. More...
 
void setRestitution (float restitution)
 Set this shape's restitution. More...
 
float getFriction () const
 Get this shape's friction. More...
 
void setFriction (float friction)
 Set this shape's friction. More...
 
const PhysicsMaterialgetMaterial () const
 Get this shape's PhysicsMaterial object. More...
 
local getMaterial ()
 Get this shape's PhysicsMaterial object. More...
 
void setMaterial (const PhysicsMaterial &material)
 Set this shape's material. More...
 
local setMaterial ( local material)
 Set this shape's material. More...
 
virtual float calculateDefaultMoment ()
 Calculate the default moment value. More...
 
virtual Vec2 getOffset ()
 Get this shape's position offset. More...
 
virtual Vec2 getCenter ()
 Get this shape's center position. More...
 
local getCenter ()
 Get this shape's center position. More...
 
bool containsPoint (const Vec2 &point) const
 Test point is inside this shape or not. More...
 
void setCategoryBitmask (int bitmask)
 Set a mask that defines which categories this physics body belongs to. More...
 
var setCategoryBitmask ( var bitmask)
 Set a mask that defines which categories this physics body belongs to. More...
 
local setCategoryBitmask ( local bitmask)
 Set a mask that defines which categories this physics body belongs to. More...
 
int getCategoryBitmask () const
 Get a mask that defines which categories this physics body belongs to. More...
 
var getCategoryBitmask ()
 Get a mask that defines which categories this physics body belongs to. More...
 
local getCategoryBitmask ()
 Get 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...
 
int getContactTestBitmask () const
 Get 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 getCollisionBitmask () const
 Get a mask that defines which categories of physics bodies can collide with this physics body. More...
 
void setGroup (int group)
 Set the group of body. More...
 
int getGroup ()
 Get the group of body. More...
 
- Public Member Functions inherited from Ref
void retain ()
 Retains the ownership. More...
 
void release ()
 Releases the ownership immediately. More...
 
Refautorelease ()
 Releases the ownership sometime soon automatically. More...
 
unsigned int getReferenceCount () const
 Returns the Ref's current reference count. More...
 
virtual ~Ref ()
 Destructor. More...
 

Static Public Member Functions

static void recenterPoints (Vec2 *points, int count, const Vec2 &center=Vec2::ZERO)
 Move the points to the center. More...
 
local recenterPoints ( local points, local count, local ZERO)
 Move the points to the center. More...
 
static Vec2 getPolyonCenter (const Vec2 *points, int count)
 Get center of the polyon points. More...
 

Protected Member Functions

void setBody (PhysicsBody *body)
virtual float calculateArea ()
 calculate the area of this shape More...
 
virtual void setScale (float scaleX, float scaleY)
local setScale ( local scaleX, local scaleY)
virtual void updateScale ()
void addShape (cpShape *shape)
 PhysicsShape ()
virtual ~PhysicsShape ()=0
local ~PhysicsShape ()
- Protected Member Functions inherited from Ref
 Ref ()
 Constructor. More...
 
 Ref ()
 Constructor. More...
 

Protected Attributes

PhysicsBody_body
std::vector< cpShape * > _cpShapes
Type _type
float _area
float _mass
float _moment
float _scaleX
float _scaleY
float _newScaleX
float _newScaleY
PhysicsMaterial _material
int _tag
int _categoryBitmask
int _collisionBitmask
int _contactTestBitmask
int _group
- Protected Attributes inherited from Ref
unsigned int _referenceCount
 count of references More...
 
local _referenceCount
 count of references More...
 

Friends

class PhysicsWorld
class PhysicsBody
class PhysicsJoint
class PhysicsDebugDraw

Detailed Description

A shape for body.

You do not create PhysicsWorld objects directly, instead, you can view PhysicsBody to see how to create it.

Constructor & Destructor Documentation

PhysicsShape ( )
protected
var PhysicsShape ( )
protected
local PhysicsShape ( )
protected
virtual ~PhysicsShape ( )
protectedpure virtual
var ~PhysicsShape ( )
protectedpure virtual
local ~PhysicsShape ( )
protectedpure virtual

Member Function Documentation

void addShape ( cpShape *  shape)
protected
var addShape ( var  shape)
protected
local addShape ( local  shape)
protected
virtual float calculateArea ( )
inlineprotectedvirtual

calculate the area of this shape

Reimplemented in PhysicsShapePolygon, and PhysicsShapeCircle.

var calculateArea ( )
inlineprotectedvirtual

calculate the area of this shape

Reimplemented in PhysicsShapePolygon, and PhysicsShapeCircle.

local calculateArea ( )
inlineprotectedvirtual

calculate the area of this shape

Reimplemented in PhysicsShapePolygon, and PhysicsShapeCircle.

virtual float
calculateDefaultMoment
( )
inlinevirtual

Calculate the default moment value.

This function should be overrided in inherit classes.

Returns
A float number, equals 0.0.

Reimplemented in PhysicsShapePolygon, and PhysicsShapeCircle.

var calculateDefaultMoment ( )
inlinevirtual

Calculate the default moment value.

This function should be overrided in inherit classes.

Returns
A float number, equals 0.0.

Reimplemented in PhysicsShapePolygon, and PhysicsShapeCircle.

local calculateDefaultMoment ( )
inlinevirtual

Calculate the default moment value.

This function should be overrided in inherit classes.

Returns
A float number, equals 0.0.

Reimplemented in PhysicsShapePolygon, and PhysicsShapeCircle.

bool containsPoint ( const Vec2 point) const

Test point is inside this shape or not.

Parameters
pointA Vec2 object.
Returns
A bool object.
var containsPoint ( var  point)

Test point is inside this shape or not.

Parameters
pointA Vec2 object.
Returns
A bool object.
local containsPoint ( local  point)

Test point is inside this shape or not.

Parameters
pointA Vec2 object.
Returns
A bool object.
float getArea ( ) const
inline

Return this shape's area.

Returns
A float number.
var getArea ( )
inline

Return this shape's area.

Returns
A float number.
local getArea ( )
inline

Return this shape's area.

Returns
A float number.
PhysicsBody* getBody ( ) const
inline

Get the body that this shape attaches.

Returns
A PhysicsBody object pointer.
var getBody ( )
inline

Get the body that this shape attaches.

Returns
A PhysicsBody object pointer.
local getBody ( )
inline

Get the body that this shape attaches.

Returns
A PhysicsBody object pointer.
int getCategoryBitmask ( ) const
inline

Get a mask that defines which categories this physics body belongs to.

Returns
An interger number.
var getCategoryBitmask ( )
inline

Get a mask that defines which categories this physics body belongs to.

Returns
An interger number.
local getCategoryBitmask ( )
inline

Get a mask that defines which categories this physics body belongs to.

Returns
An interger number.
virtual Vec2 getCenter ( )
inlinevirtual

Get this shape's center position.

This function should be overrided in inherit classes.

Returns
A Vec2 object.

Reimplemented in PhysicsShapeEdgeChain, PhysicsShapeEdgePolygon, PhysicsShapeEdgeSegment, and PhysicsShapePolygon.

var getCenter ( )
inlinevirtual

Get this shape's center position.

This function should be overrided in inherit classes.

Returns
A Vec2 object.

Reimplemented in PhysicsShapeEdgeChain, PhysicsShapeEdgePolygon, PhysicsShapeEdgeSegment, and PhysicsShapePolygon.

local getCenter ( )
inlinevirtual

Get this shape's center position.

This function should be overrided in inherit classes.

Returns
A Vec2 object.

Reimplemented in PhysicsShapeEdgeChain, PhysicsShapeEdgePolygon, PhysicsShapeEdgeSegment, and PhysicsShapePolygon.

int getCollisionBitmask ( ) const
inline

Get a mask that defines which categories of physics bodies can collide with this physics body.

Returns
An interger number.
var getCollisionBitmask ( )
inline

Get a mask that defines which categories of physics bodies can collide with this physics body.

Returns
An interger number.
local getCollisionBitmask ( )
inline

Get a mask that defines which categories of physics bodies can collide with this physics body.

Returns
An interger number.
int getContactTestBitmask ( ) const
inline

Get a mask that defines which categories of bodies cause intersection notifications with this physics body.

Returns
An interger number.
var getContactTestBitmask ( )
inline

Get a mask that defines which categories of bodies cause intersection notifications with this physics body.

Returns
An interger number.
local getContactTestBitmask ( )
inline

Get a mask that defines which categories of bodies cause intersection notifications with this physics body.

Returns
An interger number.
float getDensity ( ) const
inline

Get this shape's density.

Returns
A float number.
var getDensity ( )
inline

Get this shape's density.

Returns
A float number.
local getDensity ( )
inline

Get this shape's density.

Returns
A float number.
float getFriction ( ) const
inline

Get this shape's friction.

Returns
A float number.
var getFriction ( )
inline

Get this shape's friction.

Returns
A float number.
local getFriction ( )
inline

Get this shape's friction.

Returns
A float number.
int getGroup ( )
inline

Get the group of body.

Returns
An interger number.
var getGroup ( )
inline

Get the group of body.

Returns
An interger number.
local getGroup ( )
inline

Get the group of body.

Returns
An interger number.
float getMass ( ) const
inline

Get the mass of this shape.

Returns
A float number.
var getMass ( )
inline

Get the mass of this shape.

Returns
A float number.
local getMass ( )
inline

Get the mass of this shape.

Returns
A float number.
const PhysicsMaterial& getMaterial ( ) const
inline

Get this shape's PhysicsMaterial object.

Returns
A PhysicsMaterial object reference.
var getMaterial ( )
inline

Get this shape's PhysicsMaterial object.

Returns
A PhysicsMaterial object reference.
local getMaterial ( )
inline

Get this shape's PhysicsMaterial object.

Returns
A PhysicsMaterial object reference.
float getMoment ( ) const
inline

Get this shape's moment.

Returns
A float number.
var getMoment ( )
inline

Get this shape's moment.

Returns
A float number.
local getMoment ( )
inline

Get this shape's moment.

Returns
A float number.
virtual Vec2 getOffset ( )
inlinevirtual

Get this shape's position offset.

This function should be overrided in inherit classes.

Returns
A Vec2 object.

Reimplemented in PhysicsShapeEdgeBox, PhysicsShapeBox, and PhysicsShapeCircle.

var getOffset ( )
inlinevirtual

Get this shape's position offset.

This function should be overrided in inherit classes.

Returns
A Vec2 object.

Reimplemented in PhysicsShapeEdgeBox, PhysicsShapeBox, and PhysicsShapeCircle.

local getOffset ( )
inlinevirtual

Get this shape's position offset.

This function should be overrided in inherit classes.

Returns
A Vec2 object.

Reimplemented in PhysicsShapeEdgeBox, PhysicsShapeBox, and PhysicsShapeCircle.

static Vec2 getPolyonCenter ( const Vec2 points,
int  count 
)
static

Get center of the polyon points.

Parameters
pointsA Vec2 object pointer.
countAn interger number.
Returns
A Vec2 object.
var getPolyonCenter ( var  points,
var  count 
)
static

Get center of the polyon points.

Parameters
pointsA Vec2 object pointer.
countAn interger number.
Returns
A Vec2 object.
local getPolyonCenter ( local  points,
local  count 
)
static

Get center of the polyon points.

Parameters
pointsA Vec2 object pointer.
countAn interger number.
Returns
A Vec2 object.
float getRestitution ( ) const
inline

Get this shape's restitution.

Returns
A float number.
var getRestitution ( )
inline

Get this shape's restitution.

Returns
A float number.
local getRestitution ( )
inline

Get this shape's restitution.

Returns
A float number.
int getTag ( ) const
inline

Get this shape's tag.

Returns
An interger number.
var getTag ( )
inline

Get this shape's tag.

Returns
An interger number.
local getTag ( )
inline

Get this shape's tag.

Returns
An interger number.
Type getType ( ) const
inline

Return this shape's type.

Returns
A Type object.
var getType ( )
inline

Return this shape's type.

Returns
A Type object.
local getType ( )
inline

Return this shape's type.

Returns
A Type object.
static void recenterPoints ( Vec2 points,
int  count,
const Vec2 center = Vec2::ZERO 
)
static

Move the points to the center.

Parameters
pointsA Vec2 object pointer.
countAn interger number.
centerA Vec2 object, default value is Vec2(0,0).
var recenterPoints ( var  points,
var  count,
var  center = Vec2::ZERO 
)
static

Move the points to the center.

Parameters
pointsA Vec2 object pointer.
countAn interger number.
centerA Vec2 object, default value is Vec2(0,0).
local recenterPoints ( local  points,
local  count,
local  center = Vec2::ZERO 
)
static

Move the points to the center.

Parameters
pointsA Vec2 object pointer.
countAn interger number.
centerA Vec2 object, default value is Vec2(0,0).
void setBody ( PhysicsBody body)
protected
var setBody ( var  body)
protected
local setBody ( local  body)
protected
void setCategoryBitmask ( int  bitmask)
inline

Set 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.

Parameters
bitmaskAn interger number, the default value is 0xFFFFFFFF (all bits set).
var setCategoryBitmask ( var  bitmask)
inline

Set 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.

Parameters
bitmaskAn interger number, the default value is 0xFFFFFFFF (all bits set).
local setCategoryBitmask ( local  bitmask)
inline

Set 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.

Parameters
bitmaskAn interger number, the default value is 0xFFFFFFFF (all bits set).
void setCollisionBitmask ( int  bitmask)
inline

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.

Parameters
bitmaskAn interger number, the default value is 0xFFFFFFFF (all bits set).
var setCollisionBitmask ( var  bitmask)
inline

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.

Parameters
bitmaskAn interger number, the default value is 0xFFFFFFFF (all bits set).
local setCollisionBitmask ( local  bitmask)
inline

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.

Parameters
bitmaskAn interger number, the default value is 0xFFFFFFFF (all bits set).
void setContactTestBitmask ( int  bitmask)
inline

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.

Parameters
bitmaskAn interger number, the default value is 0x00000000 (all bits cleared).
var setContactTestBitmask ( var  bitmask)
inline

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.

Parameters
bitmaskAn interger number, the default value is 0x00000000 (all bits cleared).
local setContactTestBitmask ( local  bitmask)
inline

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.

Parameters
bitmaskAn interger number, the default value is 0x00000000 (all bits cleared).
void setDensity ( float  density)

Set this shape's density.

It will change the body's mass this shape attaches.

Parameters
densityA float number.
var setDensity ( var  density)

Set this shape's density.

It will change the body's mass this shape attaches.

Parameters
densityA float number.
local setDensity ( local  density)

Set this shape's density.

It will change the body's mass this shape attaches.

Parameters
densityA float number.
void setFriction ( float  friction)

Set this shape's friction.

It will change the shape's friction.

Parameters
frictionA float number.
var setFriction ( var  friction)

Set this shape's friction.

It will change the shape's friction.

Parameters
frictionA float number.
local setFriction ( local  friction)

Set this shape's friction.

It will change the shape's friction.

Parameters
frictionA float number.
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).

Parameters
groupAn interger number, it have high priority than bit masks.
var setGroup ( var  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).

Parameters
groupAn interger number, it have high priority than bit masks.
local setGroup ( local  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).

Parameters
groupAn interger number, it have high priority than bit masks.
void setMass ( float  mass)

Set this shape's mass.

It will change the body's mass this shape attaches.

Parameters
massA float number.
var setMass ( var  mass)

Set this shape's mass.

It will change the body's mass this shape attaches.

Parameters
massA float number.
local setMass ( local  mass)

Set this shape's mass.

It will change the body's mass this shape attaches.

Parameters
massA float number.
void setMaterial ( const PhysicsMaterial material)

Set this shape's material.

It will change the shape's mass, elasticity and friction.

Parameters
materialA PhysicsMaterial object.
var setMaterial ( var  material)

Set this shape's material.

It will change the shape's mass, elasticity and friction.

Parameters
materialA PhysicsMaterial object.
local setMaterial ( local  material)

Set this shape's material.

It will change the shape's mass, elasticity and friction.

Parameters
materialA PhysicsMaterial object.
void setMoment ( float  moment)

Set this shape's moment.

It will change the body's moment this shape attaches.

Parameters
momentA float number.
var setMoment ( var  moment)

Set this shape's moment.

It will change the body's moment this shape attaches.

Parameters
momentA float number.
local setMoment ( local  moment)

Set this shape's moment.

It will change the body's moment this shape attaches.

Parameters
momentA float number.
void setRestitution ( float  restitution)

Set this shape's restitution.

It will change the shape's elasticity.

Parameters
restitutionA float number.
var setRestitution ( var  restitution)

Set this shape's restitution.

It will change the shape's elasticity.

Parameters
restitutionA float number.
local setRestitution ( local  restitution)

Set this shape's restitution.

It will change the shape's elasticity.

Parameters
restitutionA float number.
virtual void setScale ( float  scaleX,
float  scaleY 
)
protectedvirtual
var setScale ( var  scaleX,
var  scaleY 
)
protectedvirtual
local setScale ( local  scaleX,
local  scaleY 
)
protectedvirtual
void setTag ( int  tag)
inline

Set this shape's tag.

Parameters
tagAn interger number that identifies a shape object.
var setTag ( var  tag)
inline

Set this shape's tag.

Parameters
tagAn interger number that identifies a shape object.
local setTag ( local  tag)
inline

Set this shape's tag.

Parameters
tagAn interger number that identifies a shape object.
virtual void updateScale ( )
protectedvirtual
local updateScale ( )
protectedvirtual

Friends And Related Function Documentation

friend class PhysicsBody
friend
var PhysicsBody
friend
local PhysicsBody
friend
friend class PhysicsDebugDraw
friend
var PhysicsDebugDraw
friend
local PhysicsDebugDraw
friend
friend class PhysicsJoint
friend
var PhysicsJoint
friend
local PhysicsJoint
friend
friend class PhysicsWorld
friend
var PhysicsWorld
friend
local PhysicsWorld
friend

Member Data Documentation

float _area
protected
var _area
protected
local _area
protected
PhysicsBody* _body
protected
int _categoryBitmask
protected
var _categoryBitmask
protected
local _categoryBitmask
protected
int _collisionBitmask
protected
var _collisionBitmask
protected
local _collisionBitmask
protected
int _contactTestBitmask
protected
var _contactTestBitmask
protected
local _contactTestBitmask
protected
std::vector<cpShape*> _cpShapes
protected
var _cpShapes
protected
local _cpShapes
protected
int _group
protected
var _group
protected
local _group
protected
float _mass
protected
var _mass
protected
local _mass
protected
PhysicsMaterial _material
protected
var _material
protected
local _material
protected
float _moment
protected
var _moment
protected
local _moment
protected
float _newScaleX
protected
var _newScaleX
protected
local _newScaleX
protected
float _newScaleY
protected
var _newScaleY
protected
local _newScaleY
protected
float _scaleX
protected
var _scaleX
protected
local _scaleX
protected
float _scaleY
protected
var _scaleY
protected
local _scaleY
protected
int _tag
protected
var _tag
protected
local _tag
protected
Type _type
protected
var _type
protected
local _type
protected

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