Class Cylinder

Cylinder class.

Example

const radiusTop = 0.5
const radiusBottom = 0.5
const height = 2
const numSegments = 12
const cylinderShape = new CANNON.Cylinder(radiusTop, radiusBottom, height, numSegments)
const cylinderBody = new CANNON.Body({ mass: 1, shape: cylinderShape })
world.addBody(cylinderBody)

Hierarchy (view full)

Constructors

  • Parameters

    • Optional radiusTop: number

      The radius of the top of the Cylinder.

    • Optional radiusBottom: number

      The radius of the bottom of the Cylinder.

    • Optional height: number

      The height of the Cylinder.

    • Optional numSegments: number

      The number of segments to build the cylinder out of.

    Returns Cylinder

Properties

body: Body

The body to which the shape is added to.

boundingSphereRadius: number

The local bounding sphere radius of this shape.

collisionFilterGroup: number

Default

1
collisionFilterMask: number

Default

-1
collisionResponse: boolean

Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

Default

true
faceNormals: Vec3[]

faceNormals

faces: number[][]

Array of integer arrays, indicating which vertices each face consists of

height: number

The height of the Cylinder.

id: number

Identifier of the Shape.

material: Material

Optional material of the shape that regulates contact properties.

numSegments: number

The number of segments to build the cylinder out of.

radiusBottom: number

The radius of the bottom of the Cylinder.

radiusTop: number

The radius of the top of the Cylinder.

type: 0 | ShapeType

The type of this shape. Must be set to an int > 0 by subclasses.

uniqueAxes: Vec3[]

If given, these locally defined, normalized axes are the only ones being checked when doing separating axis check.

uniqueEdges: Vec3[]

uniqueEdges

vertices: Vec3[]

vertices

worldFaceNormals: Vec3[]

worldFaceNormals

worldFaceNormalsNeedsUpdate: boolean

worldFaceNormalsNeedsUpdate

worldVertices: Vec3[]

worldVertices

worldVerticesNeedsUpdate: boolean

worldVerticesNeedsUpdate

idCounter: number
types: {
    BOX: 4;
    COMPOUND: 8;
    CONVEXPOLYHEDRON: 16;
    CYLINDER: 128;
    HEIGHTFIELD: 32;
    PARTICLE: 64;
    PLANE: 2;
    SPHERE: 1;
    TRIMESH: 256;
}

All the Shape types.

Type declaration

  • Readonly BOX: 4

    BOX

  • Readonly COMPOUND: 8

    COMPOUND

  • Readonly CONVEXPOLYHEDRON: 16

    CONVEXPOLYHEDRON

  • Readonly CYLINDER: 128

    CYLINDER

  • Readonly HEIGHTFIELD: 32

    HEIGHTFIELD

  • Readonly PARTICLE: 64

    PARTICLE

  • Readonly PLANE: 2

    PLANE

  • Readonly SPHERE: 1

    SPHERE

  • Readonly TRIMESH: 256

    TRIMESH

Methods

  • Clip a face in a hull against the back of a plane.

    Parameters

    • inVertices: Vec3[]
    • outVertices: Vec3[]
    • planeNormal: Vec3
    • planeConstant: number

      The constant in the mathematical plane equation

    Returns Vec3[]

  • Compute the normals of the faces. Will reuse existing Vec3 objects in the faceNormals array if they exist.

    Returns void

  • Find the separating axis between this hull and another

    Parameters

    Returns boolean

    Returns false if a separation is found, else true

  • Compute the normal of a face from its vertices

    Parameters

    • i: number
    • target: Vec3

    Returns void

  • Checks whether p is inside the polyhedra. Must be in local coords. The point lies outside of the convex hull of the other points if and only if the direction of all the vectors from it to those other points are on less than one half of a sphere around it.

    Parameters

    • p: Vec3

      A point given in local coordinates

    Returns false | 1 | -1

  • Test separating axis against two hulls. Both hulls are projected onto the axis and the overlap size is returned if there is one.

    Parameters

    Returns number | false

    The overlap depth, or FALSE if no penetration.

  • Get max and min dot product of a convex hull at position (pos,quat) projected onto an axis. Results are saved in the array maxmin.

    Parameters

    Returns void