cocos2d-x  3.3
 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 the type of this shape. More...
 
var getType ()
 Return the type of this shape. More...
 
local getType ()
 Return the type of this shape. More...
 
float getArea () const
 return the area of this shape More...
 
local getArea ()
 return the area of this shape More...
 
float getMoment () const
 get moment More...
 
local getMoment ()
 get moment More...
 
void setMoment (float moment)
 Set moment, it will change the body's moment this shape attaches. More...
 
var setMoment ( var moment)
 Set moment, it will change the body's moment this shape attaches. More...
 
local setMoment ( local moment)
 Set moment, it will change the body's moment this shape attaches. More...
 
void setTag (int tag)
int getTag () const
local getTag ()
float getMass () const
 get mass More...
 
var getMass ()
 get mass More...
 
local getMass ()
 get mass More...
 
void setMass (float mass)
 Set mass, it will change the body's mass this shape attaches. More...
 
var setMass ( var mass)
 Set mass, it will change the body's mass this shape attaches. More...
 
local setMass ( local mass)
 Set mass, it will change the body's mass this shape attaches. More...
 
float getDensity () const
local getDensity ()
void setDensity (float density)
local setDensity ( local density)
float getRestitution () const
local getRestitution ()
void setRestitution (float restitution)
local setRestitution ( local restitution)
float getFriction () const
var getFriction ()
local getFriction ()
void setFriction (float friction)
local setFriction ( local friction)
const PhysicsMaterialgetMaterial () const
void setMaterial (const PhysicsMaterial &material)
var setMaterial ( var material)
local setMaterial ( local material)
virtual float calculateDefaultMoment ()
 Calculate the default moment value. More...
 
var calculateDefaultMoment ()
 Calculate the default moment value. More...
 
local calculateDefaultMoment ()
 Calculate the default moment value. More...
 
virtual Vec2 getOffset ()
 Get offset. More...
 
local getOffset ()
 Get offset. More...
 
virtual Vec2 getCenter ()
 Get center of this shape. More...
 
var getCenter ()
 Get center of this shape. More...
 
local getCenter ()
 Get center of this shape. More...
 
bool containsPoint (const Vec2 &point) const
 Test point is in shape or not. More...
 
var containsPoint ( var point)
 Test point is in shape or not. More...
 
local containsPoint ( local point)
 Test point is in shape or not. More...
 
void setCategoryBitmask (int bitmask)
 A mask that defines which categories this physics body belongs to. More...
 
int getCategoryBitmask () const
void setContactTestBitmask (int bitmask)
 A mask that defines which categories of bodies cause intersection notifications with this physics body. More...
 
int getContactTestBitmask () const
var getContactTestBitmask ()
local getContactTestBitmask ()
void setCollisionBitmask (int bitmask)
 A mask that defines which categories of physics bodies can collide with this physics body. More...
 
int getCollisionBitmask () const
local getCollisionBitmask ()
void setGroup (int group)
 set the group of body Collision groups let you specify an integral group index. More...
 
var setGroup ( var group)
 set the group of body Collision groups let you specify an integral group index. More...
 
local setGroup ( local group)
 set the group of body Collision groups let you specify an integral group index. More...
 
int getGroup ()
var getGroup ()
local getGroup ()
- 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 ()

Static Public Member Functions

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

Protected Member Functions

bool init (Type type)
local init ( local type)
PhysicsBodyInfobodyInfo () const
 PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't. More...
 
var bodyInfo ()
 PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't. More...
 
local bodyInfo ()
 PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't. More...
 
void setBody (PhysicsBody *body)
virtual float calculateArea ()
 calculate the area of this shape More...
 
var calculateArea ()
 calculate the area of this shape More...
 
local calculateArea ()
 calculate the area of this shape More...
 
virtual void setScale (float scale)
local setScale ( local scale)
virtual void setScale (float scaleX, float scaleY)
var setScale ( var scaleX, var scaleY)
local setScale ( local scaleX, local scaleY)
virtual void setScaleX (float scaleX)
local setScaleX ( local scaleX)
virtual void setScaleY (float scaleY)
var setScaleY ( var scaleY)
local setScaleY ( local scaleY)
virtual void update (float delta)
var update ( var delta)
local update ( local delta)
 PhysicsShape ()
 PhysicsShape ()
virtual ~PhysicsShape ()=0
local ~PhysicsShape ()
- Protected Member Functions inherited from Ref
 Ref ()
 Constructor. More...
 

Protected Attributes

PhysicsBody_body
PhysicsShapeInfo_info
var _info
local _info
Type _type
var _type
local _type
float _area
var _area
local _area
float _mass
var _mass
local _mass
float _moment
var _moment
local _moment
float _scaleX
var _scaleX
local _scaleX
float _scaleY
var _scaleY
local _scaleY
float _newScaleX
var _newScaleX
local _newScaleX
float _newScaleY
var _newScaleY
local _newScaleY
bool _dirty
var _dirty
local _dirty
PhysicsMaterial _material
var _material
local _material
int _tag
var _tag
local _tag
int _categoryBitmask
var _categoryBitmask
local _categoryBitmask
int _collisionBitmask
local _collisionBitmask
int _contactTestBitmask
local _contactTestBitmask
int _group
local _group
- Protected Attributes inherited from Ref
unsigned int _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.

Member Enumeration Documentation

enum Type
strong
Enumerator
UNKNOWN 
CIRCLE 
BOX 
POLYGEN 
EDGESEGMENT 
EDGEBOX 
EDGEPOLYGEN 
EDGECHAIN 
var Type
strong
Enumerator
UNKNOWN 
CIRCLE 
BOX 
POLYGEN 
EDGESEGMENT 
EDGEBOX 
EDGEPOLYGEN 
EDGECHAIN 
local Type
strong
Enumerator
UNKNOWN 
CIRCLE 
BOX 
POLYGEN 
EDGESEGMENT 
EDGEBOX 
EDGEPOLYGEN 
EDGECHAIN 

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

PhysicsBodyInfo* bodyInfo ( ) const
protected

PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't.

so this method is use for subclasses to catch the bodyInfo from PhysicsBody.

var bodyInfo ( )
protected

PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't.

so this method is use for subclasses to catch the bodyInfo from PhysicsBody.

local bodyInfo ( )
protected

PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't.

so this method is use for subclasses to catch the bodyInfo from PhysicsBody.

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.

Reimplemented in PhysicsShapePolygon, and PhysicsShapeCircle.

var calculateDefaultMoment ( )
inlinevirtual

Calculate the default moment value.

Reimplemented in PhysicsShapePolygon, and PhysicsShapeCircle.

local calculateDefaultMoment ( )
inlinevirtual

Calculate the default moment value.

Reimplemented in PhysicsShapePolygon, and PhysicsShapeCircle.

bool containsPoint ( const Vec2 point) const

Test point is in shape or not.

var containsPoint ( var  point)

Test point is in shape or not.

local containsPoint ( local  point)

Test point is in shape or not.

float getArea ( ) const
inline

return the area of this shape

var getArea ( )
inline

return the area of this shape

local getArea ( )
inline

return the area of this shape

PhysicsBody* getBody ( ) const
inline

Get the body that this shape attaches.

var getBody ( )
inline

Get the body that this shape attaches.

local getBody ( )
inline

Get the body that this shape attaches.

int getCategoryBitmask ( ) const
inline
var getCategoryBitmask ( )
inline
local getCategoryBitmask ( )
inline
virtual Vec2 getCenter ( )
inlinevirtual
var getCenter ( )
inlinevirtual
local getCenter ( )
inlinevirtual
int getCollisionBitmask ( ) const
inline
var getCollisionBitmask ( )
inline
local getCollisionBitmask ( )
inline
int getContactTestBitmask ( ) const
inline
var getContactTestBitmask ( )
inline
local getContactTestBitmask ( )
inline
float getDensity ( ) const
inline
var getDensity ( )
inline
local getDensity ( )
inline
float getFriction ( ) const
inline
var getFriction ( )
inline
local getFriction ( )
inline
int getGroup ( )
inline
var getGroup ( )
inline
local getGroup ( )
inline
float getMass ( ) const
inline

get mass

var getMass ( )
inline

get mass

local getMass ( )
inline

get mass

const PhysicsMaterial& getMaterial ( ) const
inline
var getMaterial ( )
inline
local getMaterial ( )
inline
float getMoment ( ) const
inline

get moment

var getMoment ( )
inline

get moment

local getMoment ( )
inline

get moment

virtual Vec2 getOffset ( )
inlinevirtual

Get offset.

Reimplemented in PhysicsShapeEdgeBox, PhysicsShapeBox, and PhysicsShapeCircle.

var getOffset ( )
inlinevirtual

Get offset.

Reimplemented in PhysicsShapeEdgeBox, PhysicsShapeBox, and PhysicsShapeCircle.

local getOffset ( )
inlinevirtual

Get offset.

Reimplemented in PhysicsShapeEdgeBox, PhysicsShapeBox, and PhysicsShapeCircle.

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

get center of the polyon points

var getPolyonCenter ( var  points,
var  count 
)
static

get center of the polyon points

local getPolyonCenter ( local  points,
local  count 
)
static

get center of the polyon points

float getRestitution ( ) const
inline
var getRestitution ( )
inline
local getRestitution ( )
inline
int getTag ( ) const
inline
var getTag ( )
inline
local getTag ( )
inline
Type getType ( ) const
inline

Return the type of this shape.

var getType ( )
inline

Return the type of this shape.

local getType ( )
inline

Return the type of this shape.

bool init ( Type  type)
protected
var init ( var  type)
protected
local init ( local  type)
protected
static void recenterPoints ( Vec2 points,
int  count,
const Vec2 center = Vec2::ZERO 
)
static

move the points to the center

var recenterPoints ( var  points,
var  count,
var  center = Vec2::ZERO 
)
static

move the points to the center

local recenterPoints ( local  points,
local  count,
local  center = Vec2::ZERO 
)
static

move the points to the center

void setBody ( PhysicsBody body)
protected
var setBody ( var  body)
protected
local setBody ( local  body)
protected
void setCategoryBitmask ( int  bitmask)
inline

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. The default value is 0xFFFFFFFF (all bits set).

var setCategoryBitmask ( var  bitmask)
inline

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. The default value is 0xFFFFFFFF (all bits set).

local setCategoryBitmask ( local  bitmask)
inline

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. 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. 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. 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. 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. 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. 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. The default value is 0x00000000 (all bits cleared).

void setDensity ( float  density)
var setDensity ( var  density)
local setDensity ( local  density)
void setFriction ( float  friction)
var setFriction ( var  friction)
local setFriction ( local  friction)
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

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) 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) it have high priority than bit masks

void setMass ( float  mass)

Set mass, it will change the body's mass this shape attaches.

var setMass ( var  mass)

Set mass, it will change the body's mass this shape attaches.

local setMass ( local  mass)

Set mass, it will change the body's mass this shape attaches.

void setMaterial ( const PhysicsMaterial material)
var setMaterial ( var  material)
local setMaterial ( local  material)
void setMoment ( float  moment)

Set moment, it will change the body's moment this shape attaches.

var setMoment ( var  moment)

Set moment, it will change the body's moment this shape attaches.

local setMoment ( local  moment)

Set moment, it will change the body's moment this shape attaches.

void setRestitution ( float  restitution)
var setRestitution ( var  restitution)
local setRestitution ( local  restitution)
virtual void setScale ( float  scale)
protectedvirtual

Reimplemented in PhysicsShapeCircle.

var setScale ( var  scale)
protectedvirtual

Reimplemented in PhysicsShapeCircle.

local setScale ( local  scale)
protectedvirtual

Reimplemented in PhysicsShapeCircle.

virtual void setScale ( float  scaleX,
float  scaleY 
)
protectedvirtual

Reimplemented in PhysicsShapeCircle.

var setScale ( var  scaleX,
var  scaleY 
)
protectedvirtual

Reimplemented in PhysicsShapeCircle.

local setScale ( local  scaleX,
local  scaleY 
)
protectedvirtual

Reimplemented in PhysicsShapeCircle.

virtual void setScaleX ( float  scaleX)
protectedvirtual

Reimplemented in PhysicsShapeCircle.

var setScaleX ( var  scaleX)
protectedvirtual

Reimplemented in PhysicsShapeCircle.

local setScaleX ( local  scaleX)
protectedvirtual

Reimplemented in PhysicsShapeCircle.

virtual void setScaleY ( float  scaleY)
protectedvirtual

Reimplemented in PhysicsShapeCircle.

var setScaleY ( var  scaleY)
protectedvirtual

Reimplemented in PhysicsShapeCircle.

local setScaleY ( local  scaleY)
protectedvirtual

Reimplemented in PhysicsShapeCircle.

void setTag ( int  tag)
inline
var setTag ( var  tag)
inline
local setTag ( local  tag)
inline
virtual void update ( float  delta)
protectedvirtual
var update ( var  delta)
protectedvirtual
local update ( local  delta)
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
bool _dirty
protected
var _dirty
protected
local _dirty
protected
int _group
protected
var _group
protected
local _group
protected
PhysicsShapeInfo* _info
protected
var _info
protected
local _info
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: