PackageBox2D.Collision.Shapes
Classpublic class b2Shape
Subclassesb2CircleShape, b2EdgeShape, b2PolygonShape
Sourceb2Shape.as

A shape is used for collision detection. Shapes are created in b2Body. You can use shape for collision detection before they are attached to the world.

Warning: you cannot reuse shapes.



Public Methods
 MethodDefined by
  
ComputeAABB(aabb:b2AABB, xf:b2XForm):void
Given a transform, compute the associated axis aligned bounding box for this shape.
b2Shape
  
ComputeMass(massData:b2MassData):void
Compute the mass properties of this shape using its dimensions and density.
b2Shape
  
ComputeSweptAABB(aabb:b2AABB, xf1:b2XForm, xf2:b2XForm):void
Given two transforms, compute the associated swept axis aligned bounding box for this shape.
b2Shape
  
Get the parent body of this shape.
b2Shape
  
Get the contact filtering data.
b2Shape
  
GetFriction():Number
Get the coefficient of friction.
b2Shape
  
Get the next shape in the parent body's shape list.
b2Shape
  
GetRestitution():Number
Get the coefficient of restitution.
b2Shape
  
GetSweepRadius():Number
Get the maximum radius about the parent body's center of mass.
b2Shape
  
GetType():int
Get the type of this shape.
b2Shape
  
Get the user data that was assigned in the shape definition.
b2Shape
  
IsSensor():Boolean
Is this shape a sensor (non-solid)?
b2Shape
  
Set the contact filtering data.
b2Shape
  
SetFriction(friction:Number):void
Set the coefficient of friction.
b2Shape
  
SetRestitution(restitution:Number):void
Set the coefficient of restitution.
b2Shape
  
SetUserData(data:*):void
Set the user data.
b2Shape
  
TestPoint(xf:b2XForm, p:b2Vec2):Boolean
Test a point for containment in this shape.
b2Shape
  
TestSegment(xf:b2XForm, lambda:Array, normal:b2Vec2, segment:b2Segment, maxLambda:Number):int
Perform a ray cast against this shape.
b2Shape
Public Constants
 ConstantDefined by
  e_hitCollide : int = 1
[static] Return value for TestSegment indicating a hit.
b2Shape
  e_missCollide : int = 0
[static] Return value for TestSegment indicating a miss.
b2Shape
  e_startsInsideCollide : int = -1
[static] Return value for TestSegment indicating that the segment starting point, p1, is already inside the shape.
b2Shape
Method detail
ComputeAABB()method
public function ComputeAABB(aabb:b2AABB, xf:b2XForm):void

Given a transform, compute the associated axis aligned bounding box for this shape.

Parameters
aabb:b2AABB — returns the axis aligned box.
 
xf:b2XForm — the world transform of the shape.
ComputeMass()method 
public function ComputeMass(massData:b2MassData):void

Compute the mass properties of this shape using its dimensions and density. The inertia tensor is computed about the local origin, not the centroid.

Parameters
massData:b2MassData — returns the mass data for this shape.
ComputeSweptAABB()method 
public function ComputeSweptAABB(aabb:b2AABB, xf1:b2XForm, xf2:b2XForm):void

Given two transforms, compute the associated swept axis aligned bounding box for this shape.

Parameters
aabb:b2AABB — returns the axis aligned box.
 
xf1:b2XForm — the starting shape world transform.
 
xf2:b2XForm — the ending shape world transform.
GetBody()method 
public function GetBody():b2Body

Get the parent body of this shape. This is NULL if the shape is not attached.

Returns
b2Body — the parent body.
GetFilterData()method 
public function GetFilterData():b2FilterData

Get the contact filtering data.

Returns
b2FilterData
GetFriction()method 
public function GetFriction():Number

Get the coefficient of friction.

Returns
Number
GetNext()method 
public function GetNext():b2Shape

Get the next shape in the parent body's shape list.

Returns
b2Shape — the next shape.
GetRestitution()method 
public function GetRestitution():Number

Get the coefficient of restitution.

Returns
Number
GetSweepRadius()method 
public function GetSweepRadius():Number

Get the maximum radius about the parent body's center of mass.

Returns
Number
GetType()method 
public function GetType():int

Get the type of this shape. You can use this to down cast to the concrete shape.

Returns
int — the shape type.
GetUserData()method 
public function GetUserData():*

Get the user data that was assigned in the shape definition. Use this to store your application specific data.

Returns
*
IsSensor()method 
public function IsSensor():Boolean

Is this shape a sensor (non-solid)?

Returns
Boolean — the true if the shape is a sensor.
SetFilterData()method 
public function SetFilterData(filter:b2FilterData):void

Set the contact filtering data. You must call b2World.Refilter to correct existing contacts/non-contacts.

Parameters
filter:b2FilterData

See also

SetFriction()method 
public function SetFriction(friction:Number):void

Set the coefficient of friction.

Parameters
friction:Number
SetRestitution()method 
public function SetRestitution(restitution:Number):void

Set the coefficient of restitution.

Parameters
restitution:Number
SetUserData()method 
public function SetUserData(data:*):void

Set the user data. Use this to store your application specific data.

Parameters
data:*
TestPoint()method 
public function TestPoint(xf:b2XForm, p:b2Vec2):Boolean

Test a point for containment in this shape. This only works for convex shapes.

Parameters
xf:b2XForm — the shape world transform.
 
p:b2Vec2 — a point in world coordinates.

Returns
Boolean
TestSegment()method 
public function TestSegment(xf:b2XForm, lambda:Array, normal:b2Vec2, segment:b2Segment, maxLambda:Number):int

Perform a ray cast against this shape.

Parameters
xf:b2XForm — the shape world transform.
 
lambda:Array — returns the hit fraction. You can use this to compute the contact point: p = (1 - lambda) segment.p1 + lambda segment.p2. lambda should be an array with one member. After calling TestSegment, you can retrieve the output value with lambda[0].
 
normal:b2Vec2 — returns the normal at the contact point. If there is no intersection, the normal is not set.
 
segment:b2Segment — defines the begin and end point of the ray cast.
 
maxLambda:Number — a number typically in the range [0,1].

Returns
int — b2Shape.e_hitCollide if there was an intersection, b2Shape.e_startsInsideCollide if the point is inside and b2Shape.e_missCollide otherwise.
Constant detail
e_hitCollideconstant
public static const e_hitCollide:int = 1

Return value for TestSegment indicating a hit.

e_missCollideconstant 
public static const e_missCollide:int = 0

Return value for TestSegment indicating a miss.

e_startsInsideCollideconstant 
public static const e_startsInsideCollide:int = -1

Return value for TestSegment indicating that the segment starting point, p1, is already inside the shape.