207 lines
5.4 KiB
Markdown
Raw Permalink Normal View History

2020-07-28 20:21:55 -07:00
[Planck.js API Doc](../README.md) › [Globals](../globals.md) › [Shape](shape.md)
2020-07-27 00:12:01 -07:00
2020-07-28 20:21:55 -07:00
# Class: Shape
2020-07-27 00:12:01 -07:00
2021-04-16 17:10:15 +02:00
A shape is used for collision detection. You can create a shape however you
like. Shapes used for simulation in World are created automatically when a
Fixture is created. Shapes may encapsulate one or more child shapes.
2020-07-27 00:12:01 -07:00
## Hierarchy
* **Shape**
↳ [CircleShape](circleshape.md)
↳ [EdgeShape](edgeshape.md)
↳ [PolygonShape](polygonshape.md)
↳ [ChainShape](chainshape.md)
2020-07-27 00:12:01 -07:00
## Index
2021-04-16 17:10:15 +02:00
### Properties
* [m_radius](shape.md#m_radius)
* [m_type](shape.md#m_type)
2020-07-27 00:12:01 -07:00
### Methods
2021-04-16 17:10:15 +02:00
* [computeAABB](shape.md#abstract-computeaabb)
* [computeDistanceProxy](shape.md#abstract-computedistanceproxy)
* [computeMass](shape.md#abstract-computemass)
* [getChildCount](shape.md#abstract-getchildcount)
2020-07-27 00:12:01 -07:00
* [getRadius](shape.md#getradius)
* [getType](shape.md#gettype)
2021-04-16 17:10:15 +02:00
* [rayCast](shape.md#abstract-raycast)
* [testPoint](shape.md#abstract-testpoint)
* [isValid](shape.md#static-isvalid)
## Properties
### m_radius
• **m_radius**: *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/Shape.ts:39](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/Shape.ts#L39)*
2021-04-16 17:10:15 +02:00
___
### m_type
• **m_type**: *[ShapeType](../globals.md#shapetype)*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/Shape.ts:38](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/Shape.ts#L38)*
2020-07-27 00:12:01 -07:00
## Methods
2021-04-16 17:10:15 +02:00
### `Abstract` computeAABB
▸ **computeAABB**(`aabb`: [AABB](aabb.md), `xf`: [Transform](transform.md), `childIndex`: number): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/Shape.ts:116](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/Shape.ts#L116)*
2021-04-16 17:10:15 +02:00
Given a transform, compute the associated axis aligned bounding box for a
child shape.
2020-07-27 00:12:01 -07:00
**Parameters:**
2021-04-16 17:10:15 +02:00
Name | Type | Description |
------ | ------ | ------ |
`aabb` | [AABB](aabb.md) | Returns the axis aligned box. |
`xf` | [Transform](transform.md) | The world transform of the shape. |
`childIndex` | number | The child shape |
**Returns:** *void*
2020-07-27 00:12:01 -07:00
___
2021-04-16 17:10:15 +02:00
### `Abstract` computeDistanceProxy
2020-07-27 00:12:01 -07:00
2021-04-16 17:10:15 +02:00
▸ **computeDistanceProxy**(`proxy`: [DistanceProxy](distanceproxy.md), `childIndex`: number): *void*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/Shape.ts:127](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/Shape.ts#L127)*
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
`proxy` | [DistanceProxy](distanceproxy.md) |
2021-04-16 17:10:15 +02:00
`childIndex` | number |
**Returns:** *void*
2020-07-27 00:12:01 -07:00
___
2021-04-16 17:10:15 +02:00
### `Abstract` computeMass
2020-07-27 00:12:01 -07:00
2021-04-16 17:10:15 +02:00
▸ **computeMass**(`massData`: [MassData](massdata.md), `density?`: number): *void*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/Shape.ts:125](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/Shape.ts#L125)*
2021-04-16 17:10:15 +02:00
Compute the mass properties of this shape using its dimensions and density.
The inertia tensor is computed about the local origin.
2020-07-27 00:12:01 -07:00
**Parameters:**
2021-04-16 17:10:15 +02:00
Name | Type | Description |
------ | ------ | ------ |
`massData` | [MassData](massdata.md) | Returns the mass data for this shape. |
`density?` | number | The density in kilograms per meter squared. |
**Returns:** *void*
2020-07-27 00:12:01 -07:00
___
2021-04-16 17:10:15 +02:00
### `Abstract` getChildCount
2020-07-27 00:12:01 -07:00
▸ **getChildCount**(): *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/Shape.ts:87](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/Shape.ts#L87)*
2021-04-16 17:10:15 +02:00
Get the number of child primitives.
2020-07-27 00:12:01 -07:00
**Returns:** *number*
___
### getRadius
▸ **getRadius**(): *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/Shape.ts:62](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/Shape.ts#L62)*
2020-07-27 00:12:01 -07:00
**Returns:** *number*
___
### getType
2020-07-28 20:21:55 -07:00
▸ **getType**(): *[ShapeType](../globals.md#shapetype)*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/Shape.ts:72](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/Shape.ts#L72)*
2021-04-16 17:10:15 +02:00
Get the type of this shape. You can use this to down cast to the concrete
shape.
2020-07-27 00:12:01 -07:00
2020-07-28 20:21:55 -07:00
**Returns:** *[ShapeType](../globals.md#shapetype)*
2020-07-27 00:12:01 -07:00
2021-04-16 17:10:15 +02:00
the shape type.
2020-07-27 00:12:01 -07:00
___
2021-04-16 17:10:15 +02:00
### `Abstract` rayCast
▸ **rayCast**(`output`: [RayCastOutput](../interfaces/raycastoutput.md), `input`: [RayCastInput](../interfaces/raycastinput.md), `xf`: [Transform](transform.md), `childIndex`: number): *boolean*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/Shape.ts:106](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/Shape.ts#L106)*
2020-07-27 00:12:01 -07:00
2021-04-16 17:10:15 +02:00
Cast a ray against a child shape.
2020-07-27 00:12:01 -07:00
**Parameters:**
2021-04-16 17:10:15 +02:00
Name | Type | Description |
------ | ------ | ------ |
`output` | [RayCastOutput](../interfaces/raycastoutput.md) | The ray-cast results. |
`input` | [RayCastInput](../interfaces/raycastinput.md) | The ray-cast input parameters. |
`xf` | [Transform](transform.md) | The transform to be applied to the shape. |
`childIndex` | number | The child shape index |
**Returns:** *boolean*
___
### `Abstract` testPoint
▸ **testPoint**(`xf`: [Transform](transform.md), `p`: [Vec2](vec2.md)): *boolean*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/Shape.ts:96](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/Shape.ts#L96)*
2021-04-16 17:10:15 +02:00
Test a point for containment in this shape. This only works for convex
shapes.
**Parameters:**
Name | Type | Description |
------ | ------ | ------ |
`xf` | [Transform](transform.md) | The shape world transform. |
`p` | [Vec2](vec2.md) | A point in world coordinates. |
**Returns:** *boolean*
2020-07-27 00:12:01 -07:00
___
2021-04-16 17:10:15 +02:00
### `Static` isValid
2020-07-27 00:12:01 -07:00
2021-04-16 17:10:15 +02:00
▸ **isValid**(`shape`: [Shape](shape.md) | null | undefined): *shape is Shape*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/Shape.ts:58](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/Shape.ts#L58)*
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-04-16 17:10:15 +02:00
`shape` | [Shape](shape.md) | null | undefined |
2020-07-27 00:12:01 -07:00
2021-04-16 17:10:15 +02:00
**Returns:** *shape is Shape*