409 lines
9.6 KiB
Markdown
Raw Permalink Normal View History

2020-07-28 20:21:55 -07:00
[Planck.js API Doc](../README.md) › [Globals](../globals.md) › [BroadPhase](broadphase.md)
# Class: BroadPhase
2021-04-16 17:10:15 +02:00
The broad-phase wraps and extends a dynamic-tree to keep track of moved
objects and query them on update.
2020-07-28 20:21:55 -07:00
## Hierarchy
* **BroadPhase**
2021-04-16 17:10:15 +02:00
## Index
### Properties
* [m_callback](broadphase.md#m_callback)
* [m_moveBuffer](broadphase.md#m_movebuffer)
* [m_proxyCount](broadphase.md#m_proxycount)
* [m_queryProxyId](broadphase.md#m_queryproxyid)
* [m_tree](broadphase.md#m_tree)
### Methods
* [bufferMove](broadphase.md#buffermove)
* [createProxy](broadphase.md#createproxy)
* [destroyProxy](broadphase.md#destroyproxy)
* [getFatAABB](broadphase.md#getfataabb)
* [getProxyCount](broadphase.md#getproxycount)
* [getTreeBalance](broadphase.md#gettreebalance)
* [getTreeHeight](broadphase.md#gettreeheight)
* [getTreeQuality](broadphase.md#gettreequality)
* [getUserData](broadphase.md#getuserdata)
* [moveProxy](broadphase.md#moveproxy)
* [query](broadphase.md#query)
* [queryCallback](broadphase.md#querycallback)
* [rayCast](broadphase.md#raycast)
* [shiftOrigin](broadphase.md#shiftorigin)
* [testOverlap](broadphase.md#testoverlap)
* [touchProxy](broadphase.md#touchproxy)
* [unbufferMove](broadphase.md#unbuffermove)
* [updatePairs](broadphase.md#updatepairs)
## Properties
### m_callback
• **m_callback**: *function*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:45](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L45)*
2021-04-16 17:10:15 +02:00
#### Type declaration:
▸ (`userDataA`: any, `userDataB`: any): *void*
**Parameters:**
Name | Type |
------ | ------ |
`userDataA` | any |
`userDataB` | any |
___
### m_moveBuffer
• **m_moveBuffer**: *any[]* = []
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:43](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L43)*
2021-04-16 17:10:15 +02:00
___
### m_proxyCount
• **m_proxyCount**: *number* = 0
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:42](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L42)*
2021-04-16 17:10:15 +02:00
___
### m_queryProxyId
• **m_queryProxyId**: *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:46](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L46)*
2021-04-16 17:10:15 +02:00
___
### m_tree
• **m_tree**: *[DynamicTree](dynamictree.md)‹[FixtureProxy](fixtureproxy.md)‹››* = new DynamicTree<FixtureProxy>()
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:41](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L41)*
2021-04-16 17:10:15 +02:00
## Methods
### bufferMove
▸ **bufferMove**(`proxyId`: number): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:172](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L172)*
2021-04-16 17:10:15 +02:00
**Parameters:**
Name | Type |
------ | ------ |
`proxyId` | number |
**Returns:** *void*
___
### createProxy
▸ **createProxy**(`aabb`: [AABB](aabb.md), `userData`: [FixtureProxy](fixtureproxy.md)): *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:135](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L135)*
2021-04-16 17:10:15 +02:00
Create a proxy with an initial AABB. Pairs are not reported until UpdatePairs
is called.
**Parameters:**
Name | Type |
------ | ------ |
`aabb` | [AABB](aabb.md) |
`userData` | [FixtureProxy](fixtureproxy.md) |
**Returns:** *number*
___
### destroyProxy
▸ **destroyProxy**(`proxyId`: number): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:146](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L146)*
2021-04-16 17:10:15 +02:00
Destroy a proxy. It is up to the client to remove any pairs.
**Parameters:**
Name | Type |
------ | ------ |
`proxyId` | number |
**Returns:** *void*
___
### getFatAABB
2021-05-11 18:30:36 -07:00
▸ **getFatAABB**(`proxyId`: number): *[AABB](aabb.md)*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:67](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L67)*
2021-04-16 17:10:15 +02:00
Get the fat AABB for a proxy.
**Parameters:**
Name | Type |
------ | ------ |
2021-05-11 18:30:36 -07:00
`proxyId` | number |
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
**Returns:** *[AABB](aabb.md)*
2021-04-16 17:10:15 +02:00
___
### getProxyCount
▸ **getProxyCount**(): *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:74](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L74)*
2021-04-16 17:10:15 +02:00
Get the number of proxies.
**Returns:** *number*
___
### getTreeBalance
▸ **getTreeBalance**(): *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:88](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L88)*
2021-04-16 17:10:15 +02:00
Get the balance (integer) of the embedded tree.
**Returns:** *number*
___
### getTreeHeight
▸ **getTreeHeight**(): *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:81](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L81)*
2021-04-16 17:10:15 +02:00
Get the height of the embedded tree.
**Returns:** *number*
___
### getTreeQuality
▸ **getTreeQuality**(): *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:95](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L95)*
2021-04-16 17:10:15 +02:00
Get the quality metric of the embedded tree.
**Returns:** *number*
___
### getUserData
2021-05-11 18:30:36 -07:00
▸ **getUserData**(`proxyId`: number): *[FixtureProxy](fixtureproxy.md)*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:51](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L51)*
2021-04-16 17:10:15 +02:00
Get user data from a proxy. Returns null if the id is invalid.
**Parameters:**
Name | Type |
------ | ------ |
2021-05-11 18:30:36 -07:00
`proxyId` | number |
2021-04-16 17:10:15 +02:00
**Returns:** *[FixtureProxy](fixtureproxy.md)*
___
### moveProxy
▸ **moveProxy**(`proxyId`: number, `aabb`: [AABB](aabb.md), `displacement`: [Vec2](vec2.md)): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:156](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L156)*
2021-04-16 17:10:15 +02:00
Call moveProxy as many times as you like, then when you are done call
UpdatePairs to finalized the proxy pairs (for your time step).
**Parameters:**
Name | Type |
------ | ------ |
`proxyId` | number |
`aabb` | [AABB](aabb.md) |
`displacement` | [Vec2](vec2.md) |
**Returns:** *void*
___
### query
▸ **query**(`aabb`: any, `queryCallback`: any): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:103](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L103)*
2021-04-16 17:10:15 +02:00
Query an AABB for overlapping proxies. The callback class is called for each
proxy that overlaps the supplied AABB.
**Parameters:**
Name | Type |
------ | ------ |
`aabb` | any |
`queryCallback` | any |
**Returns:** *void*
___
### queryCallback
▸ **queryCallback**(`proxyId`: number): *boolean*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:210](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L210)*
2021-04-16 17:10:15 +02:00
**Parameters:**
Name | Type |
------ | ------ |
`proxyId` | number |
**Returns:** *boolean*
___
### rayCast
2021-05-08 11:13:58 -07:00
▸ **rayCast**(`input`: [RayCastInput](../interfaces/raycastinput.md), `rayCastCallback`: [RayCastCallback](../globals.md#raycastcallback)): *void*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:117](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L117)*
2021-04-16 17:10:15 +02:00
Ray-cast against the proxies in the tree. This relies on the callback to
perform a exact ray-cast in the case were the proxy contains a shape. The
callback also performs the any collision filtering. This has performance
roughly equal to k * log(n), where k is the number of collisions and n is the
number of proxies in the tree.
**Parameters:**
Name | Type | Description |
------ | ------ | ------ |
2021-05-08 11:13:58 -07:00
`input` | [RayCastInput](../interfaces/raycastinput.md) | The ray-cast input data. The ray extends from `p1` to `p1 + maxFraction * (p2 - p1)`. |
`rayCastCallback` | [RayCastCallback](../globals.md#raycastcallback) | A function that is called for each proxy that is hit by the ray. |
2021-04-16 17:10:15 +02:00
**Returns:** *void*
___
### shiftOrigin
▸ **shiftOrigin**(`newOrigin`: [Vec2](vec2.md)): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:127](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L127)*
2021-04-16 17:10:15 +02:00
Shift the world origin. Useful for large worlds. The shift formula is:
position -= newOrigin
**Parameters:**
Name | Type | Description |
------ | ------ | ------ |
`newOrigin` | [Vec2](vec2.md) | The new origin with respect to the old origin |
**Returns:** *void*
___
### testOverlap
2021-05-11 18:30:36 -07:00
▸ **testOverlap**(`proxyIdA`: number, `proxyIdB`: number): *boolean*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:58](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L58)*
2021-04-16 17:10:15 +02:00
Test overlap of fat AABBs.
**Parameters:**
Name | Type |
------ | ------ |
2021-05-11 18:30:36 -07:00
`proxyIdA` | number |
`proxyIdB` | number |
2021-04-16 17:10:15 +02:00
**Returns:** *boolean*
___
### touchProxy
▸ **touchProxy**(`proxyId`: number): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:168](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L168)*
2021-04-16 17:10:15 +02:00
Call to trigger a re-processing of it's pairs on the next call to
UpdatePairs.
**Parameters:**
Name | Type |
------ | ------ |
`proxyId` | number |
**Returns:** *void*
___
### unbufferMove
▸ **unbufferMove**(`proxyId`: number): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:176](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L176)*
2021-04-16 17:10:15 +02:00
**Parameters:**
Name | Type |
------ | ------ |
`proxyId` | number |
**Returns:** *void*
___
### updatePairs
▸ **updatePairs**(`addPairCallback`: function): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/collision/BroadPhase.ts:187](https://github.com/shakiba/planck.js/blob/acc3bd8/src/collision/BroadPhase.ts#L187)*
2021-04-16 17:10:15 +02:00
Update the pairs. This results in pair callbacks. This can only add pairs.
**Parameters:**
▪ **addPairCallback**: *function*
▸ (`userDataA`: [FixtureProxy](fixtureproxy.md), `userDataB`: [FixtureProxy](fixtureproxy.md)): *void*
**Parameters:**
Name | Type |
------ | ------ |
`userDataA` | [FixtureProxy](fixtureproxy.md) |
`userDataB` | [FixtureProxy](fixtureproxy.md) |
**Returns:** *void*