476 lines
12 KiB
Markdown
Raw Permalink Normal View History

2020-07-28 20:21:55 -07:00
[Planck.js API Doc](../README.md) › [Globals](../globals.md) › [MouseJoint](mousejoint.md)
# Class: MouseJoint
2021-04-16 17:10:15 +02:00
A mouse joint is used to make a point on a body track a specified world
point. This a soft constraint with a maximum force. This allows the
constraint to stretch and without applying huge forces.
NOTE: this joint is not documented in the manual because it was developed to
be used in the testbed. If you want to learn how to use the mouse joint, look
at the testbed.
2020-07-28 20:21:55 -07:00
## Hierarchy
* [Joint](joint.md)
2021-04-16 17:10:15 +02:00
2020-07-28 20:21:55 -07:00
↳ **MouseJoint**
## Index
### Constructors
* [constructor](mousejoint.md#constructor)
### Properties
* [TYPE](mousejoint.md#static-type)
### Methods
2021-04-16 17:10:15 +02:00
* [getAnchorA](mousejoint.md#getanchora)
* [getAnchorB](mousejoint.md#getanchorb)
* [getBodyA](mousejoint.md#getbodya)
* [getBodyB](mousejoint.md#getbodyb)
* [getCollideConnected](mousejoint.md#getcollideconnected)
2020-07-28 20:21:55 -07:00
* [getDampingRatio](mousejoint.md#getdampingratio)
* [getFrequency](mousejoint.md#getfrequency)
* [getMaxForce](mousejoint.md#getmaxforce)
2021-04-16 17:10:15 +02:00
* [getNext](mousejoint.md#getnext)
* [getReactionForce](mousejoint.md#getreactionforce)
* [getReactionTorque](mousejoint.md#getreactiontorque)
2020-07-28 20:21:55 -07:00
* [getTarget](mousejoint.md#gettarget)
2021-04-16 17:10:15 +02:00
* [getType](mousejoint.md#gettype)
* [getUserData](mousejoint.md#getuserdata)
* [initVelocityConstraints](mousejoint.md#initvelocityconstraints)
* [isActive](mousejoint.md#isactive)
2020-07-28 20:21:55 -07:00
* [setDampingRatio](mousejoint.md#setdampingratio)
* [setFrequency](mousejoint.md#setfrequency)
* [setMaxForce](mousejoint.md#setmaxforce)
* [setTarget](mousejoint.md#settarget)
2021-04-16 17:10:15 +02:00
* [setUserData](mousejoint.md#setuserdata)
* [shiftOrigin](mousejoint.md#shiftorigin)
* [solvePositionConstraints](mousejoint.md#solvepositionconstraints)
* [solveVelocityConstraints](mousejoint.md#solvevelocityconstraints)
2020-07-28 20:21:55 -07:00
## Constructors
### constructor
\+ **new MouseJoint**(`def`: [MouseJointDef](../interfaces/mousejointdef.md)): *[MouseJoint](mousejoint.md)*
*Overrides [Joint](joint.md).[constructor](joint.md#constructor)*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:106](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L106)*
2020-07-28 20:21:55 -07:00
**Parameters:**
Name | Type |
------ | ------ |
`def` | [MouseJointDef](../interfaces/mousejointdef.md) |
**Returns:** *[MouseJoint](mousejoint.md)*
\+ **new MouseJoint**(`def`: [MouseJointOpt](../interfaces/mousejointopt.md), `bodyA`: [Body](body.md), `bodyB`: [Body](body.md), `target`: [Vec2](vec2.md)): *[MouseJoint](mousejoint.md)*
*Overrides [Joint](joint.md).[constructor](joint.md#constructor)*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:108](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L108)*
2020-07-28 20:21:55 -07:00
**Parameters:**
Name | Type |
------ | ------ |
`def` | [MouseJointOpt](../interfaces/mousejointopt.md) |
`bodyA` | [Body](body.md) |
`bodyB` | [Body](body.md) |
`target` | [Vec2](vec2.md) |
**Returns:** *[MouseJoint](mousejoint.md)*
## Properties
### `Static` TYPE
2021-04-16 17:10:15 +02:00
▪ **TYPE**: *"mouse-joint"* = 'mouse-joint' as 'mouse-joint'
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:89](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L89)*
2020-07-28 20:21:55 -07:00
## Methods
2021-04-16 17:10:15 +02:00
### getAnchorA
2021-05-11 18:30:36 -07:00
▸ **getAnchorA**(): *[Vec2](vec2.md)*
2021-04-16 17:10:15 +02:00
*Overrides [Joint](joint.md).[getAnchorA](joint.md#abstract-getanchora)*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:246](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L246)*
2021-04-16 17:10:15 +02:00
Get the anchor point on bodyA in world coordinates.
2021-05-11 18:30:36 -07:00
**Returns:** *[Vec2](vec2.md)*
2021-04-16 17:10:15 +02:00
___
### getAnchorB
2021-05-11 18:30:36 -07:00
▸ **getAnchorB**(): *[Vec2](vec2.md)*
2021-04-16 17:10:15 +02:00
*Overrides [Joint](joint.md).[getAnchorB](joint.md#abstract-getanchorb)*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:253](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L253)*
2021-04-16 17:10:15 +02:00
Get the anchor point on bodyB in world coordinates.
2021-05-11 18:30:36 -07:00
**Returns:** *[Vec2](vec2.md)*
2021-04-16 17:10:15 +02:00
___
### getBodyA
2021-05-11 18:30:36 -07:00
▸ **getBodyA**(): *[Body](body.md)*
2021-04-16 17:10:15 +02:00
*Inherited from [Joint](joint.md).[getBodyA](joint.md#getbodya)*
2021-04-16 17:10:15 +02: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.
2021-05-11 18:30:36 -07:00
**Returns:** *[Body](body.md)*
2021-04-16 17:10:15 +02:00
___
### getBodyB
2021-05-11 18:30:36 -07:00
▸ **getBodyB**(): *[Body](body.md)*
2021-04-16 17:10:15 +02:00
*Inherited from [Joint](joint.md).[getBodyB](joint.md#getbodyb)*
2021-04-16 17:10:15 +02: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.
2021-05-11 18:30:36 -07:00
**Returns:** *[Body](body.md)*
2021-04-16 17:10:15 +02:00
___
### getCollideConnected
▸ **getCollideConnected**(): *boolean*
*Inherited from [Joint](joint.md).[getCollideConnected](joint.md#getcollideconnected)*
2021-04-16 17:10:15 +02:00
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.
**Returns:** *boolean*
___
2020-07-28 20:21:55 -07:00
### getDampingRatio
▸ **getDampingRatio**(): *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:239](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L239)*
2021-04-16 17:10:15 +02:00
Get the damping ratio (dimensionless).
2020-07-28 20:21:55 -07:00
**Returns:** *number*
___
### getFrequency
▸ **getFrequency**(): *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:225](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L225)*
2021-04-16 17:10:15 +02:00
Get the frequency in Hertz.
2020-07-28 20:21:55 -07:00
**Returns:** *number*
___
### getMaxForce
▸ **getMaxForce**(): *number*
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:211](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L211)*
2021-04-16 17:10:15 +02:00
Get the maximum force in Newtons.
**Returns:** *number*
___
### getNext
2021-05-11 18:30:36 -07:00
▸ **getNext**(): *[Joint](joint.md)*
2021-04-16 17:10:15 +02:00
*Inherited from [Joint](joint.md).[getNext](joint.md#getnext)*
2021-04-16 17:10:15 +02: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)*
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)*
2021-04-16 17:10:15 +02:00
___
### getReactionForce
2021-05-11 18:30:36 -07:00
▸ **getReactionForce**(`inv_dt`: number): *[Vec2](vec2.md)*
2021-04-16 17:10:15 +02:00
*Overrides [Joint](joint.md).[getReactionForce](joint.md#abstract-getreactionforce)*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:260](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L260)*
2021-04-16 17:10:15 +02:00
Get the reaction force on bodyB at the joint anchor in Newtons.
**Parameters:**
Name | Type |
------ | ------ |
2021-05-11 18:30:36 -07:00
`inv_dt` | number |
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
**Returns:** *[Vec2](vec2.md)*
2021-04-16 17:10:15 +02:00
___
### getReactionTorque
2021-05-11 18:30:36 -07:00
▸ **getReactionTorque**(`inv_dt`: number): *number*
2021-04-16 17:10:15 +02:00
*Overrides [Joint](joint.md).[getReactionTorque](joint.md#abstract-getreactiontorque)*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:267](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L267)*
2021-04-16 17:10:15 +02:00
Get the reaction torque on bodyB in N*m.
**Parameters:**
Name | Type |
------ | ------ |
2021-05-11 18:30:36 -07:00
`inv_dt` | number |
2020-07-28 20:21:55 -07:00
**Returns:** *number*
___
### getTarget
2021-05-11 18:30:36 -07:00
▸ **getTarget**(): *[Vec2](vec2.md)*
2020-07-28 20:21:55 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:197](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L197)*
2020-07-28 20:21:55 -07:00
2021-05-11 18:30:36 -07:00
**Returns:** *[Vec2](vec2.md)*
2020-07-28 20:21:55 -07:00
___
2021-04-16 17:10:15 +02:00
### getType
▸ **getType**(): *string*
*Inherited from [Joint](joint.md).[getType](joint.md#gettype)*
2021-04-16 17:10:15 +02:00
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.
**Returns:** *string*
___
### getUserData
▸ **getUserData**(): *unknown*
*Inherited from [Joint](joint.md).[getUserData](joint.md#getuserdata)*
2021-04-16 17:10:15 +02:00
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)*
2021-04-16 17:10:15 +02:00
**Returns:** *unknown*
___
### initVelocityConstraints
2021-05-11 18:30:36 -07:00
▸ **initVelocityConstraints**(`step`: [TimeStep](timestep.md)): *void*
2021-04-16 17:10:15 +02:00
*Overrides [Joint](joint.md).[initVelocityConstraints](joint.md#abstract-initvelocityconstraints)*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:278](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L278)*
2021-04-16 17:10:15 +02:00
**Parameters:**
Name | Type |
------ | ------ |
2021-05-11 18:30:36 -07:00
`step` | [TimeStep](timestep.md) |
2021-04-16 17:10:15 +02:00
**Returns:** *void*
___
### isActive
▸ **isActive**(): *boolean*
*Inherited from [Joint](joint.md).[isActive](joint.md#isactive)*
2021-04-16 17:10:15 +02:00
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.
**Returns:** *boolean*
___
2020-07-28 20:21:55 -07:00
### setDampingRatio
2021-05-11 18:30:36 -07:00
▸ **setDampingRatio**(`ratio`: number): *void*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:232](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L232)*
2020-07-28 20:21:55 -07:00
2021-04-16 17:10:15 +02:00
Set the damping ratio (dimensionless).
2020-07-28 20:21:55 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-05-11 18:30:36 -07:00
`ratio` | number |
2020-07-28 20:21:55 -07:00
**Returns:** *void*
___
### setFrequency
2021-05-11 18:30:36 -07:00
▸ **setFrequency**(`hz`: number): *void*
2020-07-28 20:21:55 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:218](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L218)*
2021-04-16 17:10:15 +02:00
Set the frequency in Hertz.
2020-07-28 20:21:55 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-05-11 18:30:36 -07:00
`hz` | number |
2020-07-28 20:21:55 -07:00
**Returns:** *void*
___
### setMaxForce
2021-05-11 18:30:36 -07:00
▸ **setMaxForce**(`force`: number): *void*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:204](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L204)*
2020-07-28 20:21:55 -07:00
2021-04-16 17:10:15 +02:00
Set the maximum force in Newtons.
2020-07-28 20:21:55 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-05-11 18:30:36 -07:00
`force` | number |
2020-07-28 20:21:55 -07:00
**Returns:** *void*
___
### setTarget
2021-05-11 18:30:36 -07:00
▸ **setTarget**(`target`: [Vec2](vec2.md)): *void*
2020-07-28 20:21:55 -07:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:190](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L190)*
2021-04-16 17:10:15 +02:00
Use this to update the target point.
2020-07-28 20:21:55 -07:00
**Parameters:**
Name | Type |
------ | ------ |
2021-05-11 18:30:36 -07:00
`target` | [Vec2](vec2.md) |
2021-04-16 17:10:15 +02:00
**Returns:** *void*
___
### setUserData
▸ **setUserData**(`data`: unknown): *void*
*Inherited from [Joint](joint.md).[setUserData](joint.md#setuserdata)*
2021-04-16 17:10:15 +02: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)*
2021-04-16 17:10:15 +02:00
**Parameters:**
Name | Type |
------ | ------ |
`data` | unknown |
2020-07-28 20:21:55 -07:00
**Returns:** *void*
2021-04-16 17:10:15 +02:00
___
### shiftOrigin
2021-05-11 18:30:36 -07:00
▸ **shiftOrigin**(`newOrigin`: [Vec2](vec2.md)): *void*
2021-04-16 17:10:15 +02:00
*Overrides [Joint](joint.md).[shiftOrigin](joint.md#shiftorigin)*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:274](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L274)*
2021-04-16 17:10:15 +02:00
Shift the origin for any points stored in world coordinates.
**Parameters:**
Name | Type |
------ | ------ |
2021-05-11 18:30:36 -07:00
`newOrigin` | [Vec2](vec2.md) |
2021-04-16 17:10:15 +02:00
**Returns:** *void*
___
### solvePositionConstraints
2021-05-11 18:30:36 -07:00
▸ **solvePositionConstraints**(`step`: [TimeStep](timestep.md)): *boolean*
2021-04-16 17:10:15 +02:00
*Overrides [Joint](joint.md).[solvePositionConstraints](joint.md#abstract-solvepositionconstraints)*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:384](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L384)*
2021-04-16 17:10:15 +02:00
This returns true if the position errors are within tolerance.
**Parameters:**
Name | Type |
------ | ------ |
2021-05-11 18:30:36 -07:00
`step` | [TimeStep](timestep.md) |
2021-04-16 17:10:15 +02:00
**Returns:** *boolean*
___
### solveVelocityConstraints
2021-05-11 18:30:36 -07:00
▸ **solveVelocityConstraints**(`step`: [TimeStep](timestep.md)): *void*
2021-04-16 17:10:15 +02:00
*Overrides [Joint](joint.md).[solveVelocityConstraints](joint.md#abstract-solvevelocityconstraints)*
2021-04-16 17:10:15 +02:00
2021-05-11 18:30:36 -07:00
*Defined in [src/dynamics/joint/MouseJoint.ts:353](https://github.com/shakiba/planck.js/blob/acc3bd8/src/dynamics/joint/MouseJoint.ts#L353)*
2021-04-16 17:10:15 +02:00
**Parameters:**
Name | Type |
------ | ------ |
2021-05-11 18:30:36 -07:00
`step` | [TimeStep](timestep.md) |
2021-04-16 17:10:15 +02:00
**Returns:** *void*