491 lines
11 KiB
Markdown
Raw Permalink Normal View History

2020-07-28 20:21:55 -07:00
[Planck.js API Doc](../README.md) › [Globals](../globals.md) › [Contact](contact.md)
2020-07-27 00:12:01 -07:00
2020-07-28 20:21:55 -07:00
# Class: Contact
2020-07-27 00:12:01 -07:00
2021-04-16 17:10:15 +02:00
The class manages contact between two shapes. A contact exists for each
overlapping AABB in the broad-phase (except if filtered). Therefore a contact
object may exist that has no contact points.
2020-07-27 00:12:01 -07:00
## Hierarchy
* **Contact**
## Index
2020-07-28 20:21:55 -07:00
### Constructors
* [constructor](contact.md#constructor)
2020-07-27 00:12:01 -07:00
### Methods
* [evaluate](contact.md#evaluate)
* [flagForFiltering](contact.md#flagforfiltering)
* [getChildIndexA](contact.md#getchildindexa)
* [getChildIndexB](contact.md#getchildindexb)
* [getFixtureA](contact.md#getfixturea)
* [getFixtureB](contact.md#getfixtureb)
* [getFriction](contact.md#getfriction)
* [getManifold](contact.md#getmanifold)
* [getNext](contact.md#getnext)
* [getRestitution](contact.md#getrestitution)
* [getTangentSpeed](contact.md#gettangentspeed)
* [getWorldManifold](contact.md#getworldmanifold)
* [initConstraint](contact.md#initconstraint)
* [initVelocityConstraint](contact.md#initvelocityconstraint)
* [isEnabled](contact.md#isenabled)
* [isTouching](contact.md#istouching)
* [resetFriction](contact.md#resetfriction)
* [resetRestitution](contact.md#resetrestitution)
* [setEnabled](contact.md#setenabled)
* [setFriction](contact.md#setfriction)
* [setRestitution](contact.md#setrestitution)
* [setTangentSpeed](contact.md#settangentspeed)
* [solvePositionConstraint](contact.md#solvepositionconstraint)
* [solvePositionConstraintTOI](contact.md#solvepositionconstrainttoi)
* [solveVelocityConstraint](contact.md#solvevelocityconstraint)
* [storeConstraintImpulses](contact.md#storeconstraintimpulses)
* [update](contact.md#update)
* [warmStartConstraint](contact.md#warmstartconstraint)
2020-07-28 20:21:55 -07:00
## Constructors
### constructor
\+ **new Contact**(`fA`: [Fixture](fixture.md), `indexA`: number, `fB`: [Fixture](fixture.md), `indexB`: number, `evaluateFcn`: [EvaluateFunction](../globals.md#evaluatefunction)): *[Contact](contact.md)*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:196](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L196)*
2020-07-28 20:21:55 -07:00
**Parameters:**
Name | Type |
------ | ------ |
`fA` | [Fixture](fixture.md) |
`indexA` | number |
`fB` | [Fixture](fixture.md) |
`indexB` | number |
`evaluateFcn` | [EvaluateFunction](../globals.md#evaluatefunction) |
**Returns:** *[Contact](contact.md)*
2020-07-27 00:12:01 -07:00
## Methods
### evaluate
2021-04-16 17:10:15 +02:00
▸ **evaluate**(`manifold`: [Manifold](manifold.md), `xfA`: [Transform](transform.md), `xfB`: [Transform](transform.md)): *void*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:433](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L433)*
2021-04-16 17:10:15 +02:00
Called by Update method, and implemented by subclasses.
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-04-16 17:10:15 +02:00
`manifold` | [Manifold](manifold.md) |
2020-07-27 00:12:01 -07:00
`xfA` | [Transform](transform.md) |
`xfB` | [Transform](transform.md) |
**Returns:** *void*
___
### flagForFiltering
▸ **flagForFiltering**(): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:365](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L365)*
2021-04-16 17:10:15 +02:00
Flag this contact for filtering. Filtering will occur the next time step.
2020-07-27 00:12:01 -07:00
**Returns:** *void*
___
### getChildIndexA
▸ **getChildIndexA**(): *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:351](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L351)*
2021-04-16 17:10:15 +02:00
Get the child primitive index for fixture A.
2020-07-27 00:12:01 -07:00
**Returns:** *number*
___
### getChildIndexB
▸ **getChildIndexB**(): *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:358](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L358)*
2021-04-16 17:10:15 +02:00
Get the child primitive index for fixture B.
2020-07-27 00:12:01 -07:00
**Returns:** *number*
___
### getFixtureA
▸ **getFixtureA**(): *[Fixture](fixture.md)*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:337](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L337)*
2021-04-16 17:10:15 +02:00
Get fixture A in this contact.
2020-07-27 00:12:01 -07:00
**Returns:** *[Fixture](fixture.md)*
___
### getFixtureB
▸ **getFixtureB**(): *[Fixture](fixture.md)*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:344](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L344)*
2021-04-16 17:10:15 +02:00
Get fixture B in this contact.
2020-07-27 00:12:01 -07:00
**Returns:** *[Fixture](fixture.md)*
___
### getFriction
▸ **getFriction**(): *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:380](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L380)*
2021-04-16 17:10:15 +02:00
Get the friction.
2020-07-27 00:12:01 -07:00
**Returns:** *number*
___
### getManifold
2021-04-16 17:10:15 +02:00
▸ **getManifold**(): *[Manifold](manifold.md)*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:287](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L287)*
2020-07-27 00:12:01 -07:00
2021-04-16 17:10:15 +02:00
Get the contact manifold. Do not modify the manifold unless you understand
the internals of the library.
**Returns:** *[Manifold](manifold.md)*
2020-07-27 00:12:01 -07:00
___
### getNext
▸ **getNext**(): *[Contact](contact.md) | null*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:330](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L330)*
2021-04-16 17:10:15 +02:00
Get the next contact in the world's contact list.
2020-07-27 00:12:01 -07:00
**Returns:** *[Contact](contact.md) | null*
___
### getRestitution
▸ **getRestitution**(): *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:403](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L403)*
2021-04-16 17:10:15 +02:00
Get the restitution.
2020-07-27 00:12:01 -07:00
**Returns:** *number*
___
### getTangentSpeed
▸ **getTangentSpeed**(): *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:426](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L426)*
2021-04-16 17:10:15 +02:00
Get the desired tangent speed. In meters per second.
2020-07-27 00:12:01 -07:00
**Returns:** *number*
___
### getWorldManifold
2021-04-16 17:10:15 +02:00
▸ **getWorldManifold**(`worldManifold`: [WorldManifold](worldmanifold.md) | null | undefined): *[WorldManifold](worldmanifold.md) | undefined*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:294](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L294)*
2020-07-27 00:12:01 -07:00
2021-04-16 17:10:15 +02:00
Get the world manifold.
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-04-16 17:10:15 +02:00
`worldManifold` | [WorldManifold](worldmanifold.md) | null | undefined |
2020-07-27 00:12:01 -07:00
2021-04-16 17:10:15 +02:00
**Returns:** *[WorldManifold](worldmanifold.md) | undefined*
2020-07-27 00:12:01 -07:00
___
### initConstraint
2021-04-16 17:10:15 +02:00
▸ **initConstraint**(`step`: [TimeStep](timestep.md)): *void*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:215](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L215)*
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-04-16 17:10:15 +02:00
`step` | [TimeStep](timestep.md) |
2020-07-27 00:12:01 -07:00
**Returns:** *void*
___
### initVelocityConstraint
2021-04-16 17:10:15 +02:00
▸ **initVelocityConstraint**(`step`: [TimeStep](timestep.md)): *void*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:657](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L657)*
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-04-16 17:10:15 +02:00
`step` | [TimeStep](timestep.md) |
2020-07-27 00:12:01 -07:00
**Returns:** *void*
___
### isEnabled
▸ **isEnabled**(): *boolean*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:316](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L316)*
2021-04-16 17:10:15 +02:00
Has this contact been disabled?
2020-07-27 00:12:01 -07:00
**Returns:** *boolean*
___
### isTouching
▸ **isTouching**(): *boolean*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:323](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L323)*
2021-04-16 17:10:15 +02:00
Is this contact touching?
2020-07-27 00:12:01 -07:00
**Returns:** *boolean*
___
### resetFriction
▸ **resetFriction**(): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:387](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L387)*
2021-04-16 17:10:15 +02:00
Reset the friction mixture to the default value.
2020-07-27 00:12:01 -07:00
**Returns:** *void*
___
### resetRestitution
▸ **resetRestitution**(): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:410](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L410)*
2021-04-16 17:10:15 +02:00
Reset the restitution to the default value.
2020-07-27 00:12:01 -07:00
**Returns:** *void*
___
### setEnabled
▸ **setEnabled**(`flag`: boolean): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:309](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L309)*
2021-04-16 17:10:15 +02:00
Enable/disable this contact. This can be used inside the pre-solve contact
listener. The contact is only disabled for the current time step (or sub-step
in continuous collisions).
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
`flag` | boolean |
**Returns:** *void*
___
### setFriction
▸ **setFriction**(`friction`: number): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:373](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L373)*
2021-04-16 17:10:15 +02:00
Override the default friction mixture. You can call this in
ContactListener.preSolve. This value persists until set or reset.
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
`friction` | number |
**Returns:** *void*
___
### setRestitution
▸ **setRestitution**(`restitution`: number): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:396](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L396)*
2021-04-16 17:10:15 +02:00
Override the default restitution mixture. You can call this in
ContactListener.preSolve. The value persists until you set or reset.
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
`restitution` | number |
**Returns:** *void*
___
### setTangentSpeed
▸ **setTangentSpeed**(`speed`: number): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:419](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L419)*
2021-04-16 17:10:15 +02:00
Set the desired tangent speed for a conveyor belt behavior. In meters per
second.
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
`speed` | number |
**Returns:** *void*
___
### solvePositionConstraint
2021-04-16 17:10:15 +02:00
▸ **solvePositionConstraint**(`step`: [TimeStep](timestep.md)): *number*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:525](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L525)*
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-04-16 17:10:15 +02:00
`step` | [TimeStep](timestep.md) |
2020-07-27 00:12:01 -07:00
**Returns:** *number*
___
### solvePositionConstraintTOI
2021-04-16 17:10:15 +02:00
▸ **solvePositionConstraintTOI**(`step`: [TimeStep](timestep.md), `toiA`: [Body](body.md), `toiB`: [Body](body.md)): *number*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:529](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L529)*
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-04-16 17:10:15 +02:00
`step` | [TimeStep](timestep.md) |
`toiA` | [Body](body.md) |
`toiB` | [Body](body.md) |
2020-07-27 00:12:01 -07:00
**Returns:** *number*
___
### solveVelocityConstraint
2021-04-16 17:10:15 +02:00
▸ **solveVelocityConstraint**(`step`: [TimeStep](timestep.md)): *void*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:825](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L825)*
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-04-16 17:10:15 +02:00
`step` | [TimeStep](timestep.md) |
2020-07-27 00:12:01 -07:00
**Returns:** *void*
___
### storeConstraintImpulses
2021-04-16 17:10:15 +02:00
▸ **storeConstraintImpulses**(`step`: [TimeStep](timestep.md)): *void*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:817](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L817)*
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-04-16 17:10:15 +02:00
`step` | [TimeStep](timestep.md) |
2020-07-27 00:12:01 -07:00
**Returns:** *void*
___
### update
▸ **update**(`listener?`: object): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:447](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L447)*
2021-04-16 17:10:15 +02:00
Updates the contact manifold and touching status.
Note: do not assume the fixture AABBs are overlapping or are valid.
2020-07-27 00:12:01 -07:00
**Parameters:**
▪`Optional` **listener**: *object*
2021-04-16 17:10:15 +02:00
Name | Type | Description |
------ | ------ | ------ |
`beginContact` | | - |
`endContact` | | - |
`preSolve` | | |
2020-07-27 00:12:01 -07:00
**Returns:** *void*
___
### warmStartConstraint
2021-04-16 17:10:15 +02:00
▸ **warmStartConstraint**(`step`: [TimeStep](timestep.md)): *void*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Contact.ts:776](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Contact.ts#L776)*
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-04-16 17:10:15 +02:00
`step` | [TimeStep](timestep.md) |
2020-07-27 00:12:01 -07:00
**Returns:** *void*