jit.phys.world
Jitter Reference
Open Help

jit.phys.world

Collision detection and rigid body dynamics

Description

The jit.phys.world object encapsulates a physics simulation context to perform collision detection and rigid body dynamics on its child objects. Other physics objects in the same patch as a jit.phys.world object are automatically added to the world. Multiple contexts can be managed by explicitly setting the name attribute of the jit.phys.world object and the worldname attribute of the child physics objects. Dynamics can be disabled, allowing the world to be used solely for collision detections. A 2D simulation is achieved with the remove_plane attribute.

Examples

Collision detection and rigid body dynamics

Discussion

The physics engine maintains an internal timer for simulation steps that decouples the physics step frequency from the rendering frame rate. The fixedtimestep attribute controls the physics engine frequency, and the maxsubsteps attribute clamps the number of steps allowed between updates. The default frequency of 60 and maxsubsteps of 1 requires a FPS of 60. If the FPS is 30, maxsubsteps should be increased (allowing for more than 1 simulation step each update). If the simulation is behaving incorrectly (rigid body penetration, erratic movement, etc), try increasing the simulation frequency and sub-steps.

Attributes

automatic [int]

Enables and disables automatic mode where update messages are received from that target jit.gl.render object (default = 1).

collision_mode [symbol]

Specifies the format of the collisions dictionary (default = simple)

Possible values:

'simple' ( Report contact point positions and normals average )
'complete' ( All contact point position and normals reported )

collisions [int]

Enables and disables collision reporting out the second (dumpout) outlet.

drawto [symbol]

Assign to the named drawing context, allowing for updates to be received automatically.

dynamics [int]

Enables and disables rigid-body dynamics.

enable [int]

Enable the physics simulation for all objects in this physics context (default = 1).

fixedtimestep [int]

Fixed time step value (Hz) of physics simulation (default = 60). Increasing this value increases the resolution of the simulation.

gravity [3 floats]

A 3D vector describes the force of gravity applied to all objects in the world (default = 0, -9.8, 0).

maxsubsteps [int]

Maximum number of internal simulation steps between updates (default = 1). Increase this number if FPS is low in order to prevent the simulation from losing time.

name [symbol]

Specifies the name of the instance (default = UID).

numcollisions [int]

g/s(get)

Specifies the number of collision points in the world.

raytest_mode [symbol]

Specifies how raytest messages return object hits for the raytest and screenraytest messages (default = closest)

Possible values:

'closest' ( Return only the object closest to the camera )
'all' ( Return all intersecting objects )

remove_plane [int]

Remove plane to enable 2D simulation (default = none).

Possible values:

0 = 'none'
1 = 'x' ( Constrain simulation to Y and Z planes )
2 = 'y' ( Constrain simulation to X and Z planes )
3 = 'z' ( Constrain simulation to X and Y planes )

split_impulse [int]

Enables and disables split impulse dynamics (default = 1). When enabled, split impulse will allow the dynamics solver to apply positional corrections when deep collision penetrations occur.

targetname [symbol]

Specifies the name of a jit.gl.render object to receive update messages from.

worldbox [int]

Enables and disables the world bounds. (default = 1)

worldbox_scale [3 floats]

Changes the size and shape of the world bounds (default = 5, 5, 5).

Common Box Attributes

annotation [symbol]

Sets the text that will be displayed in the Clue window when the user moves the mouse over the object.

background [int] (default: 0)

Adds or removes the object from the patcher's background layer. background 1 adds the object to the background layer, background 0 removes it. Objects in the background layer are shown behind all objects in the default foreground layer.

color [4 floats]

Sets the color for the object box outline.

fontface [int]

Sets the type style used by the object. The options are:

plain
bold
italic
bold italic

Possible values:

0 = 'regular'
1 = 'bold'
2 = 'italic'
3 = 'bold italic'

fontname [symbol]

Sets the object's font.

fontsize [float]

Sets the object's font size (in points).

Possible values:

'8'
'9'
'10'
'11'
'12'
'13'
'14'
'16'
'18'
'20'
'24'
'30'
'36'
'48'
'64'
'72'

hidden [int] (default: 0)

Toggles whether an object is hidden when the patcher is locked.

hint [symbol]

Sets the text that will be displayed in as a pop-up hint when the user moves the mouse over the object in a locked patcher.

ignoreclick [int] (default: 0)

Toggles whether an object ignores mouse clicks in a locked patcher.

patching_rect [4 floats] (default: 0. 0. 100. 0.)

Sets the position and size of the object in the patcher window.

position [2 floats]

g/s(set)

Sets the object's x and y position in both patching and presentation modes (if the object belongs to its patcher's presentation), leaving its size unchanged.

presentation [int] (default: 0)

Sets whether an object belongs to the patcher's presentation.

presentation_rect [4 floats] (default: 0. 0. 0. 0.)

Sets the x and y position and width and height of the object in the patcher's presentation, leaving its patching position unchanged.

rect [4 floats]

g/s(set)

Sets the x and y position and width and height of the object in both patching and presentation modes (if the object belongs to its patcher's presentation).

size [2 floats]

g/s(set)

Sets the object's width and height in both patching and presentation modes (if the object belongs to its patcher's presentation), leaving its position unchanged.

textcolor [float]

Sets the color for the object's text in RGBA format.

textjustification [int]

Text Justification

Possible values:

0 = 'left'
1 = 'center'
2 = 'right'

varname [symbol]

Sets the patcher's scripting name, which can be used to address the object by name in pattr, scripting messages to thispatcher, and the js object.

Messages

bang

Causes the world to perform a single step of the physics simulation, test and report collisions, and update all child objects.

raytest

Arguments

x-from [float]
y-from [float]
z-from [float]
x-to [float]
y-to [float]
z-to [float]
Perform ray-testing on the rigid bodies using the passed in ray endpoints, and report colliding objects out the right-hand (dumpout) outlet of the object, followed by the relative intersection position and world-space intersection. See raytest_mode for more info.

reset

Reset the simulation including dynamic and kinematic rigid bodies.

screenraytest

Arguments

screen-x [float]
screen-y [float]
Perform ray-testing on the rigid bodies using the passed in screen coords. The ray start point is taken by converting the screen coords to world-space, and the end point is generated by casting a ray from the camera position, through the start point to the camera far clip plane. The colliding objects name is reported out the right-hand (dumpout) outlet of the object, followed by the relative intersection position and world-space intersection. See raytest_mode for more info.

See Also

Name Description
jit.phys.body A rigid body and collision shape
jit.phys.multiple Uses matrices to simulate multiple rigid bodies
jit.phys.ghost A collision sensor and forcefield
jit.phys.picker Constraint picking in a physics world
jit.gl.physdraw A physics opengl debug drawer