Shape Class
Base class for shapes.
Constructor
Shape
-
type
Parameters:
-
type
Number
Item Index
Properties
- area
- boundingRadius
- CAPSULE static
- CIRCLE static
- collisionGroup
- collisionMask
- CONVEX static
- HEIGHTFIELD static
- id
- LINE static
- material
- PARTICLE static
- PLANE static
- RECTANGLE static
- sensor
- type
Methods
computeAABB
-
out
-
position
-
angle
Compute the world axis-aligned bounding box (AABB) of this shape.
Parameters:
-
out
AABBThe resulting AABB.
-
position
Array -
angle
Number
computeMomentOfInertia
-
mass
Should return the moment of inertia around the Z axis of the body given the total mass. See Wikipedia's list of moments of inertia.
Parameters:
-
mass
Number
Returns:
If the inertia is infinity or if the object simply isn't possible to rotate, return 0.
updateArea
()
Update the .area property of the shape.
updateBoundingRadius
()
Number
Returns the bounding circle radius of this shape.
Returns:
Properties
area
Number
Area of this shape.
boundingRadius
Number
Bounding circle radius of this shape
CAPSULE
Number
static
CIRCLE
Number
static
collisionGroup
Number
Collision group that this shape belongs to (bit mask). See this tutorial.
Example:
// Setup bits for each available group
var PLAYER = Math.pow(2,0),
ENEMY = Math.pow(2,1),
GROUND = Math.pow(2,2)
// Put shapes into their groups
player1Shape.collisionGroup = PLAYER;
player2Shape.collisionGroup = PLAYER;
enemyShape .collisionGroup = ENEMY;
groundShape .collisionGroup = GROUND;
// Assign groups that each shape collide with.
// Note that the players can collide with ground and enemies, but not with other players.
player1Shape.collisionMask = ENEMY | GROUND;
player2Shape.collisionMask = ENEMY | GROUND;
enemyShape .collisionMask = PLAYER | GROUND;
groundShape .collisionMask = PLAYER | ENEMY;
// How collision check is done
if(shapeA.collisionGroup & shapeB.collisionMask)!=0 && (shapeB.collisionGroup & shapeA.collisionMask)!=0){
// The shapes will collide
}
collisionMask
Number
Collision mask of this shape. See .collisionGroup.
CONVEX
Number
static
HEIGHTFIELD
Number
static
id
Number
Shape object identifier.
LINE
Number
static
material
Material
Material to use in collisions for this Shape. If this is set to null, the world will use default material properties instead.
PARTICLE
Number
static
PLANE
Number
static
RECTANGLE
Number
static
sensor
Boolean
Set to true if you want this shape to be a sensor. A sensor does not generate contacts, but it still reports contact events. This is good if you want to know if a shape is overlapping another shape, without them generating contacts.
type
Number
The type of the shape. One of: