316 lines
7.0 KiB
Markdown
Raw Permalink Normal View History

2020-07-28 20:21:55 -07:00
[Planck.js API Doc](../README.md) › [Globals](../globals.md) › [Joint](joint.md)
2020-07-27 00:12:01 -07:00
2020-07-28 20:21:55 -07:00
# Class: Joint
2020-07-27 00:12:01 -07:00
2021-04-16 17:10:15 +02:00
The base joint class. Joints are used to constraint two bodies together in
various fashions. Some joints also feature limits and motors.
2020-07-27 00:12:01 -07:00
## Hierarchy
* **Joint**
↳ [DistanceJoint](distancejoint.md)
↳ [FrictionJoint](frictionjoint.md)
↳ [RevoluteJoint](revolutejoint.md)
↳ [PrismaticJoint](prismaticjoint.md)
↳ [GearJoint](gearjoint.md)
↳ [MotorJoint](motorjoint.md)
↳ [MouseJoint](mousejoint.md)
↳ [PulleyJoint](pulleyjoint.md)
↳ [RopeJoint](ropejoint.md)
↳ [WeldJoint](weldjoint.md)
↳ [WheelJoint](wheeljoint.md)
2020-07-27 00:12:01 -07:00
## Index
2021-04-16 17:10:15 +02:00
### Constructors
* [constructor](joint.md#constructor)
2020-07-27 00:12:01 -07:00
### Methods
2021-04-16 17:10:15 +02:00
* [getAnchorA](joint.md#abstract-getanchora)
* [getAnchorB](joint.md#abstract-getanchorb)
2020-07-27 00:12:01 -07:00
* [getBodyA](joint.md#getbodya)
* [getBodyB](joint.md#getbodyb)
* [getCollideConnected](joint.md#getcollideconnected)
* [getNext](joint.md#getnext)
2021-04-16 17:10:15 +02:00
* [getReactionForce](joint.md#abstract-getreactionforce)
* [getReactionTorque](joint.md#abstract-getreactiontorque)
2020-07-27 00:12:01 -07:00
* [getType](joint.md#gettype)
* [getUserData](joint.md#getuserdata)
2021-04-16 17:10:15 +02:00
* [initVelocityConstraints](joint.md#abstract-initvelocityconstraints)
2020-07-27 00:12:01 -07:00
* [isActive](joint.md#isactive)
* [setUserData](joint.md#setuserdata)
* [shiftOrigin](joint.md#shiftorigin)
2021-04-16 17:10:15 +02:00
* [solvePositionConstraints](joint.md#abstract-solvepositionconstraints)
* [solveVelocityConstraints](joint.md#abstract-solvevelocityconstraints)
## Constructors
### constructor
\+ **new Joint**(`def`: [JointDef](../interfaces/jointdef.md)): *[Joint](joint.md)*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:110](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L110)*
2021-04-16 17:10:15 +02:00
**Parameters:**
Name | Type |
------ | ------ |
`def` | [JointDef](../interfaces/jointdef.md) |
**Returns:** *[Joint](joint.md)*
\+ **new Joint**(`def`: [JointOpt](../interfaces/jointopt.md), `bodyA`: [Body](body.md), `bodyB`: [Body](body.md)): *[Joint](joint.md)*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:112](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L112)*
2021-04-16 17:10:15 +02:00
**Parameters:**
Name | Type |
------ | ------ |
`def` | [JointOpt](../interfaces/jointopt.md) |
`bodyA` | [Body](body.md) |
`bodyB` | [Body](body.md) |
**Returns:** *[Joint](joint.md)*
2020-07-27 00:12:01 -07:00
## Methods
2021-04-16 17:10:15 +02:00
### `Abstract` getAnchorA
2020-07-27 00:12:01 -07:00
▸ **getAnchorA**(): *[Vec2](vec2.md)*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:197](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L197)*
2021-04-16 17:10:15 +02:00
Get the anchor point on bodyA in world coordinates.
2020-07-27 00:12:01 -07:00
**Returns:** *[Vec2](vec2.md)*
___
2021-04-16 17:10:15 +02:00
### `Abstract` getAnchorB
2020-07-27 00:12:01 -07:00
▸ **getAnchorB**(): *[Vec2](vec2.md)*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:202](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L202)*
2021-04-16 17:10:15 +02:00
Get the anchor point on bodyB in world coordinates.
2020-07-27 00:12:01 -07:00
**Returns:** *[Vec2](vec2.md)*
___
### getBodyA
2021-05-11 18:30:36 -07:00
▸ **getBodyA**(): *[Body](body.md)*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:159](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L159)*
2021-04-16 17:10:15 +02:00
Get the first body attached to this joint.
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
**Returns:** *[Body](body.md)*
2020-07-27 00:12:01 -07:00
___
### getBodyB
2021-05-11 18:30:36 -07:00
▸ **getBodyB**(): *[Body](body.md)*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:166](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L166)*
2021-04-16 17:10:15 +02:00
Get the second body attached to this joint.
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
**Returns:** *[Body](body.md)*
2020-07-27 00:12:01 -07:00
___
### getCollideConnected
▸ **getCollideConnected**(): *boolean*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:190](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L190)*
2021-04-16 17:10:15 +02:00
Get collide connected. Note: modifying the collide connect flag won't work
correctly because the flag is only checked when fixture AABBs begin to
overlap.
2020-07-27 00:12:01 -07:00
**Returns:** *boolean*
___
### getNext
2021-05-11 18:30:36 -07:00
▸ **getNext**(): *[Joint](joint.md)*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:173](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L173)*
2020-07-27 00:12:01 -07:00
2021-04-16 17:10:15 +02:00
Get the next joint the world joint list.
2021-05-11 18:30:36 -07:00
**Returns:** *[Joint](joint.md)*
2020-07-27 00:12:01 -07:00
___
2021-04-16 17:10:15 +02:00
### `Abstract` getReactionForce
2020-07-27 00:12:01 -07:00
▸ **getReactionForce**(`inv_dt`: number): *[Vec2](vec2.md)*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:207](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L207)*
2021-04-16 17:10:15 +02:00
Get the reaction force on bodyB at the joint anchor in Newtons.
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
`inv_dt` | number |
**Returns:** *[Vec2](vec2.md)*
___
2021-04-16 17:10:15 +02:00
### `Abstract` getReactionTorque
▸ **getReactionTorque**(`inv_dt`: number): *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:212](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L212)*
2021-04-16 17:10:15 +02:00
Get the reaction torque on bodyB in N*m.
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
`inv_dt` | number |
**Returns:** *number*
___
### getType
▸ **getType**(): *string*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:152](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L152)*
2021-04-16 17:10:15 +02:00
Get the type of the concrete joint.
2020-07-27 00:12:01 -07:00
**Returns:** *string*
___
### getUserData
▸ **getUserData**(): *unknown*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:177](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L177)*
2020-07-27 00:12:01 -07:00
**Returns:** *unknown*
___
2021-04-16 17:10:15 +02:00
### `Abstract` initVelocityConstraints
2021-05-11 18:30:36 -07:00
▸ **initVelocityConstraints**(`step`: [TimeStep](timestep.md)): *void*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:219](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L219)*
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-05-11 18:30:36 -07:00
`step` | [TimeStep](timestep.md) |
2020-07-27 00:12:01 -07:00
**Returns:** *void*
___
### isActive
▸ **isActive**(): *boolean*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:145](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L145)*
2021-04-16 17:10:15 +02:00
Short-cut function to determine if either body is inactive.
2020-07-27 00:12:01 -07:00
**Returns:** *boolean*
___
### setUserData
2021-04-16 17:10:15 +02:00
▸ **setUserData**(`data`: unknown): *void*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:181](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L181)*
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-04-16 17:10:15 +02:00
`data` | unknown |
2020-07-27 00:12:01 -07:00
**Returns:** *void*
___
### shiftOrigin
▸ **shiftOrigin**(`newOrigin`: [Vec2](vec2.md)): *void*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:217](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L217)*
2021-04-16 17:10:15 +02:00
Shift the origin for any points stored in world coordinates.
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
`newOrigin` | [Vec2](vec2.md) |
**Returns:** *void*
___
2021-04-16 17:10:15 +02:00
### `Abstract` solvePositionConstraints
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
▸ **solvePositionConstraints**(`step`: [TimeStep](timestep.md)): *boolean*
2020-07-27 00:12:01 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:226](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L226)*
2021-04-16 17:10:15 +02:00
This returns true if the position errors are within tolerance.
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-05-11 18:30:36 -07:00
`step` | [TimeStep](timestep.md) |
2020-07-27 00:12:01 -07:00
**Returns:** *boolean*
___
2021-04-16 17:10:15 +02:00
### `Abstract` solveVelocityConstraints
2021-05-11 18:30:36 -07:00
▸ **solveVelocityConstraints**(`step`: [TimeStep](timestep.md)): *void*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/Joint.ts:221](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/Joint.ts#L221)*
2020-07-27 00:12:01 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-05-11 18:30:36 -07:00
`step` | [TimeStep](timestep.md) |
2020-07-27 00:12:01 -07:00
**Returns:** *void*