API Docs for: 0.6.1
Show:

Convex Class

Extends Shape

Convex shape class.

Constructor

Convex

(
  • vertices
  • [axes]
)

Parameters:

  • vertices Array

    An array of vertices that span this shape. Vertices are given in counter-clockwise (CCW) direction.

  • [axes] Array optional

    An array of unit length vectors, representing the symmetry axes in the convex.

Example:

// Create a box
        var vertices = [[-1,-1], [1,-1], [1,1], [-1,1]];
        var convexShape = new Convex(vertices);
        body.addShape(convexShape);
        

Methods

computeAABB

(
  • out
  • position
  • angle
)

Inherited from Shape but overwritten in src/shapes/Convex.js:318

Parameters:

  • out AABB
  • position Array
  • angle Number

computeMomentOfInertia

(
  • mass
)
Number

Inherited from Shape but overwritten in src/shapes/Convex.js:243

Compute the mass moment of inertia of the Convex.

Parameters:

  • mass Number

Returns:

Number:

projectOntoAxis

(
  • offset
  • localAxis
  • result
)
static

Project a Convex onto a world-oriented axis

Parameters:

  • offset Array
  • localAxis Array
  • result Array

triangleArea

(
  • a
  • b
  • c
)
Number static

Get the area of the triangle spanned by the three points a, b, c. The area is positive if the points are given in counter-clockwise order, otherwise negative.

Parameters:

  • a Array
  • b Array
  • c Array

Returns:

Number:

updateArea

()

Inherited from Shape but overwritten in src/shapes/Convex.js:296

Update the .area

updateBoundingRadius

()

Inherited from Shape but overwritten in src/shapes/Convex.js:265

Updates the .boundingRadius property

updateCenterOfMass

()

Update the .centerOfMass property.

updateTriangles

()

Update the .triangles property

Properties

area

Number

Inherited from Shape: src/shapes/Shape.js:95

Area of this shape.

axes

Array

Axes defined in the local frame.

boundingRadius

Number

Inherited from Shape but overwritten in src/shapes/Convex.js:88

The bounding radius of the convex

centerOfMass

Array

The center of mass of the Convex

collisionGroup

Number

Inherited from Shape: src/shapes/Shape.js:41

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

Inherited from Shape: src/shapes/Shape.js:78

Collision mask of this shape. See .collisionGroup.

collisionResponse

Boolean

Inherited from Shape: src/shapes/Shape.js:72

Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled. That means that this shape will move through other body shapes, but it will still trigger contact events, etc.

id

Number

Inherited from Shape: src/shapes/Shape.js:27

Shape object identifier.

material

Material

Inherited from Shape: src/shapes/Shape.js:88

Material to use in collisions for this Shape. If this is set to null, the world will use default material properties instead.

sensor

Boolean

Inherited from Shape: src/shapes/Shape.js:102

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.

triangles

Array

Triangulated version of this convex. The structure is Array of 3-Arrays, and each subarray contains 3 integers, referencing the vertices.

vertices

Array

Vertices defined in the local frame.