PackageBox2D.Collision.Shapes
Classpublic class b2PolygonShape
Inheritanceb2PolygonShape Inheritance b2Shape
Sourceb2PolygonShape.as

Convex polygon. The vertices must be in CCW order for a right-handed coordinate system with the z-axis coming out of the screen.

See also

b2PolygonDef


Public Methods
 MethodDefined by
  
Get the centroid and apply the supplied transform.
b2PolygonShape
  
ComputeAABB(aabb:b2AABB, xf:b2XForm):void
Given a transform, compute the associated axis aligned bounding box for this shape.
b2PolygonShape
  
ComputeCentroid(vs:Array, count:int):b2Vec2
[static] Computes the centroid of the given polygon
b2PolygonShape
  
ComputeMass(massData:b2MassData):void
Compute the mass properties of this shape using its dimensions and density.
b2PolygonShape
  
ComputeSweptAABB(aabb:b2AABB, transform1:b2XForm, transform2:b2XForm):void
Given two transforms, compute the associated swept axis aligned bounding box for this shape.
b2PolygonShape
 Inherited
Get the parent body of this shape.
b2Shape
  
Get local centroid relative to the parent body.
b2PolygonShape
  
Get the core vertices in local coordinates.
b2PolygonShape
 Inherited
Get the contact filtering data.
b2Shape
  
Get the first vertex and apply the supplied transform.
b2PolygonShape
 Inherited
GetFriction():Number
Get the coefficient of friction.
b2Shape
 Inherited
Get the next shape in the parent body's shape list.
b2Shape
  
GetNormals():Array
Get the edge normal vectors.
b2PolygonShape
  
Get the oriented bounding box relative to the parent body.
b2PolygonShape
 Inherited
GetRestitution():Number
Get the coefficient of restitution.
b2Shape
 Inherited
GetSweepRadius():Number
Get the maximum radius about the parent body's center of mass.
b2Shape
 Inherited
GetType():int
Get the type of this shape.
b2Shape
 Inherited
Get the user data that was assigned in the shape definition.
b2Shape
  
Get the vertex count.
b2PolygonShape
  
GetVertices():Array
Get the vertices in local coordinates.
b2PolygonShape
 Inherited
IsSensor():Boolean
Is this shape a sensor (non-solid)?
b2Shape
 Inherited
Set the contact filtering data.
b2Shape
 Inherited
SetFriction(friction:Number):void
Set the coefficient of friction.
b2Shape
 Inherited
SetRestitution(restitution:Number):void
Set the coefficient of restitution.
b2Shape
 Inherited
SetUserData(data:*):void
Set the user data.
b2Shape
  
Support(xf:b2XForm, dX:Number, dY:Number):b2Vec2
Get the support point in the given world direction.
b2PolygonShape
  
TestPoint(xf:b2XForm, p:b2Vec2):Boolean
Test a point for containment in this shape.
b2PolygonShape
  
TestSegment(xf:b2XForm, lambda:Array, normal:b2Vec2, segment:b2Segment, maxLambda:Number):int
Perform a ray cast against this shape.
b2PolygonShape
Public Constants
 ConstantDefined by
 Inheritede_hitCollide : int = 1
[static] Return value for TestSegment indicating a hit.
b2Shape
 Inheritede_missCollide : int = 0
[static] Return value for TestSegment indicating a miss.
b2Shape
 Inheritede_startsInsideCollide : int = -1
[static] Return value for TestSegment indicating that the segment starting point, p1, is already inside the shape.
b2Shape
Method detail
Centroid()method
public function Centroid(xf:b2XForm):b2Vec2

Get the centroid and apply the supplied transform.

Parameters
xf:b2XForm

Returns
b2Vec2
ComputeAABB()method 
public override 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.
ComputeCentroid()method 
public static function ComputeCentroid(vs:Array, count:int):b2Vec2

Computes the centroid of the given polygon

Parameters
vs:Array — array of b2Vec specifying a polygon
 
count:int — length of vs

Returns
b2Vec2 — the polygon centroid
ComputeMass()method 
public override 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 override function ComputeSweptAABB(aabb:b2AABB, transform1:b2XForm, transform2:b2XForm):void

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

Parameters
aabb:b2AABB — returns the axis aligned box.
 
transform1:b2XForm — the starting shape world transform.
 
transform2:b2XForm — the ending shape world transform.
GetCentroid()method 
public function GetCentroid():b2Vec2

Get local centroid relative to the parent body.

Returns
b2Vec2
GetCoreVertices()method 
public function GetCoreVertices():Array

Get the core vertices in local coordinates. These vertices represent a smaller polygon that is used for time of impact computations.

Returns
Array
GetFirstVertex()method 
public function GetFirstVertex(xf:b2XForm):b2Vec2

Get the first vertex and apply the supplied transform.

Parameters
xf:b2XForm

Returns
b2Vec2
GetNormals()method 
public function GetNormals():Array

Get the edge normal vectors. There is one for each vertex.

Returns
Array
GetOBB()method 
public function GetOBB():b2OBB

Get the oriented bounding box relative to the parent body.

Returns
b2OBB
GetVertexCount()method 
public function GetVertexCount():int

Get the vertex count.

Returns
int
GetVertices()method 
public function GetVertices():Array

Get the vertices in local coordinates.

Returns
Array
Support()method 
public function Support(xf:b2XForm, dX:Number, dY:Number):b2Vec2

Get the support point in the given world direction. Use the supplied transform.

Parameters
xf:b2XForm
 
dX:Number
 
dY:Number

Returns
b2Vec2
TestPoint()method 
public override 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 override 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.