C# Class LitDev.LDPhysics

Show file Open project: litdev1/LitDev

Public Methods

Method Description
AddChain ( Primitive shape1, Primitive shape2 ) : Primitive

Add a chain between two existing shapes.

AddExplosion ( Primitive posX, Primitive posY, Primitive power, Primitive damping, Primitive colour ) : void

Make an explosion, which consists of 50x20kg particles blast apart over 500ms.

AddFixedAnchor ( Primitive posX, Primitive posY ) : Primitive

Add a new small, transparent shape to be used as a fixed anchor point.

AddFixedShape ( Primitive shapeName, Primitive friction, Primitive restitution ) : void

Add an existing SmallBasic shape to the physics engine as a fixed (non-dynamic) shape with friction and restitution that affects shapes that hit it.

AddInactiveShape ( Primitive shapeName ) : void

Add an existing SmallBasic shape to the physics engine as an inactive (non-dynamic and non-interacting) shape which only moves with the PanView method.

AddMovingAnchor ( Primitive posX, Primitive posY ) : Primitive

Add a new small, transparent and high density shape to be used as a moving anchor point.

AddMovingShape ( Primitive shapeName, Primitive friction, Primitive restitution, Primitive density ) : void

Add an existing SmallBasic shape to the physics engine as a moving (dynamic) shape.

AddRope ( Primitive shape1, Primitive shape2 ) : Primitive

Add a rope between two existing shapes.

AttachShapes ( Primitive shape1, Primitive shape2 ) : void

Connect two shapes to move together as one. The shapes are connected with a distance joint and may wobble a bit if they are hit.

AttachShapesWithJoint ( Primitive shape1, Primitive shape2, Primitive type, Primitive collide, Primitive parameters ) : Primitive

Connect two shapes to move together as one with one of several joint types. These can be advanced and require reference to Box2D manual. In many cases it is best to prevent shape rotation for the joints to behave as desired. Multiple joints may also be applied to shapes. The methods use the initial shape positions, so set these first.

AttachShapesWithRotation ( Primitive shape1, Primitive shape2 ) : void

Connect two shapes to move together as one, but allow the shapes to rotate about each other.

BoxShape ( Primitive shapeName, Primitive x1, Primitive y1, Primitive x2, Primitive y2 ) : void

Set a shape to remain within a box within the view. This is similar to PanView, except that the view pans automatically to keep the specified shape within a box region of the GraphicsWindow. Only one shape can be boxed. To unset shape box, set the shapeName to "".

BrakeTire ( Primitive shapeName ) : void

Apply a brake to a tire shape.

DetachJoint ( Primitive jointName ) : void

Disconnect two shapes that were previously joined with a joint.

DetachShapes ( Primitive shape1, Primitive shape2 ) : void

Disconnect two shapes that were previously attached.

DisconnectShape ( Primitive shapeName ) : void

Disconnect shape from the physics engine without deleting the shape.

DoTimestep ( ) : void

Perform a time-step update.

FollowShapeX ( Primitive shapeName ) : void

Set a shape to remain stationary at X position in the view. This is similar to PanView, except that the view pans automatically to keep the specified shape at a constant visual X location. Only one shape can be followed in X direction. To unset shape following, set the shapeName to "".

FollowShapeY ( Primitive shapeName ) : void

Set a shape to remain stationary at Y position in the view. This is similar to PanView, except that the view pans automatically to keep the specified shape at a constant visual Y location. Only one shape can be followed in Y direction. To unset shape following, set the shapeName to "".

GetAllShapesAt ( Primitive posX, Primitive posY ) : Primitive

Get an array of all the physics engine shapes (if any) at the input coordinates. The coordinates for this method are the physics engine coordinates if panning is present.

GetAngle ( Primitive shapeName ) : Primitive

Get the angle of rotation for the shape.

GetCollisions ( Primitive shapeName ) : Primitive

Get an array of all the shapes that the specified shape collided with during the last DoTimestep().

GetContacts ( Primitive posX, Primitive posY, Primitive distance ) : Primitive

Get a list of shapes that collided within a distance of a specified contact point.

GetInertia ( Primitive shapeName ) : Primitive

Get the moment of inertia of a shape.

GetMass ( Primitive shapeName ) : Primitive

Get the mass of a shape.

GetPan ( ) : Primitive

Get the current pan offset, see PanView, FollowShapeX(Y) and BoxShape. World coordinates = screen coordinates + pan offset.

GetPosition ( Primitive shapeName ) : Primitive

Get the centre of the shape coordinates.

GetRotation ( Primitive shapeName ) : Primitive

Get the shape rotation speed.

GetShapeAt ( Primitive posX, Primitive posY ) : Primitive

Get the shape (if any) at the input coordinates. The coordinates for this method are the screen coordinates if panning is present.

GetTireInformation ( Primitive shapeName ) : Primitive

Get tire information, it includes: Skid (if this value exceeds the property AntiSkid, then the tire is skidding) Crash (the value is the speed of the impact)

GetTireProperties ( Primitive shapeName ) : Primitive

Get tire properties, they include: AntiSkid (higher value reduces skid) Drag (higher value increases forward/backward drag) Brake (higher value increases braking power) Straighten (higher value restores steering more quickly) BrakeStraighten (higher value restores steering more quickly while braking)

GetVelocity ( Primitive shapeName ) : Primitive

Get the velocity of the shape.

GroupShapes ( Primitive shape1, Primitive shape2 ) : void

Solidly group two shapes to move together as one. Shape1 is added to shape2 to act as one shape.

Help ( ) : void

This function is just to display this help. The extension uses Box2D (http://box2d.org) as an engine and provides an interface between it and the graphics capabilities of SmallBasic. Only shapes that are connected to the physics engine take part in the motion physics, for example you may add normal shapes (e.g. a gun and not connect it to the physics engine). Once a shape is connected to the engine, it is best to only interact with it through the methods provided by the extension. All positions are in the SmallBasic GraphicsWindow pixels and refer to shape centres. Image and text shapes are treated as rectangles, and ellipses as circles; there is also triangle and convex polygon support, but not lines. Images may be treated as circles by setting the property LoadImagesAsCircles to "True". One issue that Box2D has difficulty with is small fast moving objects that can 'tunnel' through other shapes without being deflected (see the SetBullet option). Another problem is shapes of very different size and hence mass, especially large shapes when they are connected together. It may be necessary to modify the density for these (the Anchor options are an attempt to automate this a bit), otherwise the default density of 1 is good. Resist the temptation to connect too many shapes together. It may be possible to improve the stability of some 'difficult' models using the TimestepControl settings, but the defaults look good for most cases. Do not call the physics methods inside SmallBasic event subroutines directly, rather set flags that can be processed in a main game loop. There are sample SmallBasic programs and a Getting Started Guide that comes with the extension dll - this is the best place to start. Report bugs and problems to the SmallBasic forum (http://social.msdn.microsoft.com/Forums/en-US/smallbasic/threads), but first simplify your SmallBasic code to isolate the issue before providing a short 'runnable' code sample.

MoveTire ( Primitive shapeName, Primitive force ) : void

Move a tire shape, apply a forward or backward force.

PanView ( Primitive panHorizontal, Primitive panVertical ) : void

Pan the camera view, including window boundaries.

RayCast ( Primitive shapeName, Primitive angle, Primitive distance ) : Primitive

Cast an invisible ray to detect the proximity of shapes.

ReadJson ( Primitive fileName, Primitive scale, Primitive reverseY, Primitive stationary, Primitive offsetX, Primitive offsetY ) : Primitive

Read in a json script compatible with R.U.B.E. and create a LDPhysics model. See https://www.iforce2d.net/rube for more details.

RemoveChain ( Primitive shapeName ) : void

Remove a chain.

RemoveFrozen ( ) : void

Removes all frozen shapes - outside the AABB for the engine.

RemoveRope ( Primitive shapeName ) : void

Remove a rope.

RemoveShape ( Primitive shapeName ) : void

Remove a shape.

Reset ( ) : void

Reset (delete all physics engine attached shapes).

SetAABB ( Primitive minX, Primitive maxX, Primitive minY, Primitive maxY ) : void

The physics engine AABB (axis-aligned bounding box). The units are the engine units of m. A Reset is required after setting. It is not recommended to change this.

SetAngle ( Primitive shapeName, Primitive angle ) : void

Reset the angle of rotation for a shape.

SetBoundaries ( Primitive left, Primitive right, Primitive top, Primitive bottom ) : void

Set solid boundaries (positioning a boundary outside the GraphicsWindow removes it).

SetBullet ( Primitive shapeName ) : void

Set a shape as a bullet. This prevents 'tunnelling' of fast moving small objects at the expense of performance.

SetDamping ( Primitive shapeName, Primitive linear, Primitive angular ) : void

Set a damping factor for a shape (default 0).

SetForce ( Primitive shapeName, Primitive forceX, Primitive forceY ) : void

Set a force to apply to a shape (Remember F = ma).

SetGravity ( Primitive gravX, Primitive gravY ) : void

Set the gravity direction and magnitude (default 0,100).

SetGroup ( Primitive shapeName, Primitive group, Primitive mask ) : void

Control which sprites interact (collide) with other shapes.

SetImpulse ( Primitive shapeName, Primitive impulseX, Primitive impulseY ) : void

Set an impulse to a shape (a kick).

SetJointMotor ( Primitive jointName, Primitive speed, Primitive maxForce ) : void

Set a motor for selected joints (Line, Prismatic_H, Prismatic_V and Revolute).

SetPosition ( Primitive shapeName, Primitive posX, Primitive posY, Primitive angle ) : void

Reset shape position.

SetRotation ( Primitive shapeName, Primitive rotation ) : void

Set shape rotation speed.

SetShapeGravity ( Primitive shapeName, Primitive gravX, Primitive gravY ) : void

Set the gravity direction and magnitude for an individual shape (default 0,100).

SetTire ( Primitive shapeName ) : void

Set an object to act as a drivable tire for a top down game. Usually gravity will be 0 and the shape should already be added to the engine. The object should be initially positioned facing forward up on the display.

SetTireProperties ( Primitive shapeName, Primitive properties ) : void

Set tire properties, they include: AntiSkid (higher value reduces skid) Drag (higher value increases forward/backward drag) Brake (higher value increases braking power) Straighten (higher value restores stearing more quickly) BrakeStraighten (higher value restores stearing more quickly while braking)

SetTorque ( Primitive shapeName, Primitive torque ) : void

Set a torque to a shape (a rotational kick).

SetVelocity ( Primitive shapeName, Primitive velX, Primitive velY ) : void

Set the velocity of a shape.

TimestepControl ( Primitive timestep, Primitive velocityIterations, Primitive positionIterations ) : void

Modify default timestep control parameters - also can be set using individual parameters.

ToggleMoving ( Primitive shapeName ) : void

Toggle a moving shape to be fixed and vice-versa. This method also sets the rotation to be on or off to match if it is moving or fixed.

ToggleRotation ( Primitive shapeName ) : void

Toggle a shape to not rotate and vice-versa. This method toggles the rotation property for fixed and moving shapes.

ToggleSensor ( Primitive shapeName ) : void

Toggle a shape to act as a sensor and vice-versa. A sensor shape does not interact with other shapes, but still provides collision data.

TurnTire ( Primitive shapeName, Primitive torque ) : void

Turn a tire shape, steer left or right.

UngroupShapes ( Primitive shape1, Primitive shape2 ) : void

Remove shape group pairing.

UnsetBullet ( Primitive shapeName ) : void

Unset a shape as a bullet. This reverts the shape to normal collision detection.

WakeAll ( ) : void

Wake all sleeping shapes - shapes sleep due to no applied forces or contacts. They wake automatically on any contact or applied force, so this action is rarely required.

WriteJson ( Primitive fileName ) : void

Write out a json script compatible with R.U.B.E. from current LDPhysics model. See https://www.iforce2d.net/rube for more details.

Private Methods

Method Description
Cast ( double value, bool reverseY ) : Primitive
GetJointName ( JsonJoint joint ) : string

Method Details

AddChain() public static method

Add a chain between two existing shapes.
public static AddChain ( Primitive shape1, Primitive shape2 ) : Primitive
shape1 Primitive /// First shape. ///
shape2 Primitive /// Second shape. ///
return Primitive

AddExplosion() public static method

Make an explosion, which consists of 50x20kg particles blast apart over 500ms.
public static AddExplosion ( Primitive posX, Primitive posY, Primitive power, Primitive damping, Primitive colour ) : void
posX Primitive The X coordinate of the explosion.
posY Primitive The Y coordinate of the explosion.
power Primitive The explosion force, this is the initial velocity of the blast particles.
damping Primitive A damping for the blast, the smaller this value the larger the blast range (default 10).
colour Primitive An optional colour of the explosion particles ("" for none).
return void

AddFixedAnchor() public static method

Add a new small, transparent shape to be used as a fixed anchor point.
public static AddFixedAnchor ( Primitive posX, Primitive posY ) : Primitive
posX Primitive /// The X coordinate of the anchor. ///
posY Primitive /// The Y coordinate of the anchor. ///
return Primitive

AddFixedShape() public static method

Add an existing SmallBasic shape to the physics engine as a fixed (non-dynamic) shape with friction and restitution that affects shapes that hit it.
public static AddFixedShape ( Primitive shapeName, Primitive friction, Primitive restitution ) : void
shapeName Primitive /// The name of the shape. ///
friction Primitive /// The shape friction (usually 0 to 1). ///
restitution Primitive /// The shape restitution or bounciness (usually 0 to 1). ///
return void

AddInactiveShape() public static method

Add an existing SmallBasic shape to the physics engine as an inactive (non-dynamic and non-interacting) shape which only moves with the PanView method.
public static AddInactiveShape ( Primitive shapeName ) : void
shapeName Primitive /// The name of the shape. ///
return void

AddMovingAnchor() public static method

Add a new small, transparent and high density shape to be used as a moving anchor point.
public static AddMovingAnchor ( Primitive posX, Primitive posY ) : Primitive
posX Primitive /// The X coordinate of the anchor. ///
posY Primitive /// The Y coordinate of the anchor. ///
return Primitive

AddMovingShape() public static method

Add an existing SmallBasic shape to the physics engine as a moving (dynamic) shape.
public static AddMovingShape ( Primitive shapeName, Primitive friction, Primitive restitution, Primitive density ) : void
shapeName Primitive /// The name of the shape. ///
friction Primitive /// The shape friction (usually 0 to 1). ///
restitution Primitive /// The shape restitution or bounciness (usually 0 to 1). /// If a negative value is set for restitution, then the shape will be added with a very small size which may be used to add an inactive image that can be grouped within an irregular compound shape that matches the image boundary. ///
density Primitive /// The shape density (default 1). ///
return void

AddRope() public static method

Add a rope between two existing shapes.
public static AddRope ( Primitive shape1, Primitive shape2 ) : Primitive
shape1 Primitive /// First shape. ///
shape2 Primitive /// Second shape. ///
return Primitive

AttachShapes() public static method

Connect two shapes to move together as one. The shapes are connected with a distance joint and may wobble a bit if they are hit.
public static AttachShapes ( Primitive shape1, Primitive shape2 ) : void
shape1 Primitive /// The first shape name. ///
shape2 Primitive /// The second shape name. ///
return void

AttachShapesWithJoint() public static method

Connect two shapes to move together as one with one of several joint types. These can be advanced and require reference to Box2D manual. In many cases it is best to prevent shape rotation for the joints to behave as desired. Multiple joints may also be applied to shapes. The methods use the initial shape positions, so set these first.
public static AttachShapesWithJoint ( Primitive shape1, Primitive shape2, Primitive type, Primitive collide, Primitive parameters ) : Primitive
shape1 Primitive The first shape name.
shape2 Primitive The second shape name.
type Primitive One of the following joint types. /// /// "Distance" - maintain a fixed distance between the shapes. /// "Gear" - link Prismatic or Revolute joints (previously created) of 2 shapes. /// "Line" - move the shapes along a line initially connecting the shapes. /// "Mouse" - move the shape to follow the mouse (both shape names should be the same). /// "Prismatic_H" - move shapes vertically along a line between the two shapes. /// "Prismatic_V" - move shapes horizontally along a line between the two shapes. /// "Pulley" - a pulley system, one shape moves up as the other moves down - position the shapes initially at the extreme points of the pulley motion. /// "Revolute" - the shapes can rotate about each other. ///
collide Primitive The connected shapes can interact with each other "True" or "False" (default). ///
parameters Primitive Optional parameters (default ""), multiple parameters are in an array. /// /// "Distance" - damping ratio (default 0) /// "Gear" - gear ratio, first joint, second joint (default 1, auto detect joints) /// "Line" - X direction, Y direction, lower translation, upper translation (default line connecting shapes, no limits) /// "Mouse" - max acceleration, damping ratio (default 10000, 0.7) /// "Prismatic_H" - X direction, Y direction, lower translation, upper translation (default 1,0, no limits) /// "Prismatic_V" - X direction, Y direction, lower translation, upper translation (default 0,1, no limits) /// "Pulley" - pulley ratio (block and tackle) (default 1) /// "Revolute" - lower angle, upper angle (default no limits) ///
return Primitive

AttachShapesWithRotation() public static method

Connect two shapes to move together as one, but allow the shapes to rotate about each other.
public static AttachShapesWithRotation ( Primitive shape1, Primitive shape2 ) : void
shape1 Primitive /// The first shape name. ///
shape2 Primitive /// The second shape name. ///
return void

BoxShape() public static method

Set a shape to remain within a box within the view. This is similar to PanView, except that the view pans automatically to keep the specified shape within a box region of the GraphicsWindow. Only one shape can be boxed. To unset shape box, set the shapeName to "".
public static BoxShape ( Primitive shapeName, Primitive x1, Primitive y1, Primitive x2, Primitive y2 ) : void
shapeName Primitive The shape to box or "".
x1 Primitive The left x coordinate of the box.
y1 Primitive The top y coordinate of the box.
x2 Primitive The right x coordinate of the box.
y2 Primitive The bottom y coordinate of the box.
return void

BrakeTire() public static method

Apply a brake to a tire shape.
public static BrakeTire ( Primitive shapeName ) : void
shapeName Primitive The tire shape to brake.
return void

DetachJoint() public static method

Disconnect two shapes that were previously joined with a joint.
public static DetachJoint ( Primitive jointName ) : void
jointName Primitive /// The joint name. ///
return void

DetachShapes() public static method

Disconnect two shapes that were previously attached.
public static DetachShapes ( Primitive shape1, Primitive shape2 ) : void
shape1 Primitive /// The first shape name. ///
shape2 Primitive /// The second shape name. ///
return void

DisconnectShape() public static method

Disconnect shape from the physics engine without deleting the shape.
public static DisconnectShape ( Primitive shapeName ) : void
shapeName Primitive /// The shape name. ///
return void

DoTimestep() public static method

Perform a time-step update.
public static DoTimestep ( ) : void
return void

FollowShapeX() public static method

Set a shape to remain stationary at X position in the view. This is similar to PanView, except that the view pans automatically to keep the specified shape at a constant visual X location. Only one shape can be followed in X direction. To unset shape following, set the shapeName to "".
public static FollowShapeX ( Primitive shapeName ) : void
shapeName Primitive /// The shape to follow or "". ///
return void

FollowShapeY() public static method

Set a shape to remain stationary at Y position in the view. This is similar to PanView, except that the view pans automatically to keep the specified shape at a constant visual Y location. Only one shape can be followed in Y direction. To unset shape following, set the shapeName to "".
public static FollowShapeY ( Primitive shapeName ) : void
shapeName Primitive /// The shape to follow or "". ///
return void

GetAllShapesAt() public static method

Get an array of all the physics engine shapes (if any) at the input coordinates. The coordinates for this method are the physics engine coordinates if panning is present.
public static GetAllShapesAt ( Primitive posX, Primitive posY ) : Primitive
posX Primitive /// The X coordinate. ///
posY Primitive /// The Y coordinate. ///
return Primitive

GetAngle() public static method

Get the angle of rotation for the shape.
public static GetAngle ( Primitive shapeName ) : Primitive
shapeName Primitive /// The shape name. ///
return Primitive

GetCollisions() public static method

Get an array of all the shapes that the specified shape collided with during the last DoTimestep().
public static GetCollisions ( Primitive shapeName ) : Primitive
shapeName Primitive /// The shape to check for collisions. ///
return Primitive

GetContacts() public static method

Get a list of shapes that collided within a distance of a specified contact point.
public static GetContacts ( Primitive posX, Primitive posY, Primitive distance ) : Primitive
posX Primitive /// The X coordinate of a contact position to check. ///
posY Primitive /// The Y coordinate of a contact position to check. ///
distance Primitive /// A maximum distance from the contact point for the contact. ///
return Primitive

GetInertia() public static method

Get the moment of inertia of a shape.
public static GetInertia ( Primitive shapeName ) : Primitive
shapeName Primitive /// The shape name. ///
return Primitive

GetMass() public static method

Get the mass of a shape.
public static GetMass ( Primitive shapeName ) : Primitive
shapeName Primitive /// The shape name. ///
return Primitive

GetPan() public static method

Get the current pan offset, see PanView, FollowShapeX(Y) and BoxShape. World coordinates = screen coordinates + pan offset.
public static GetPan ( ) : Primitive
return Primitive

GetPosition() public static method

Get the centre of the shape coordinates.
public static GetPosition ( Primitive shapeName ) : Primitive
shapeName Primitive /// The shape name. ///
return Primitive

GetRotation() public static method

Get the shape rotation speed.
public static GetRotation ( Primitive shapeName ) : Primitive
shapeName Primitive /// The shape name. ///
return Primitive

GetShapeAt() public static method

Get the shape (if any) at the input coordinates. The coordinates for this method are the screen coordinates if panning is present.
public static GetShapeAt ( Primitive posX, Primitive posY ) : Primitive
posX Primitive /// The X coordinate. ///
posY Primitive /// The Y coordinate. ///
return Primitive

GetTireInformation() public static method

Get tire information, it includes: Skid (if this value exceeds the property AntiSkid, then the tire is skidding) Crash (the value is the speed of the impact)
public static GetTireInformation ( Primitive shapeName ) : Primitive
shapeName Primitive The tire shape.
return Primitive

GetTireProperties() public static method

Get tire properties, they include: AntiSkid (higher value reduces skid) Drag (higher value increases forward/backward drag) Brake (higher value increases braking power) Straighten (higher value restores steering more quickly) BrakeStraighten (higher value restores steering more quickly while braking)
public static GetTireProperties ( Primitive shapeName ) : Primitive
shapeName Primitive The tire shape.
return Primitive

GetVelocity() public static method

Get the velocity of the shape.
public static GetVelocity ( Primitive shapeName ) : Primitive
shapeName Primitive /// The shape name. ///
return Primitive

GroupShapes() public static method

Solidly group two shapes to move together as one. Shape1 is added to shape2 to act as one shape.
public static GroupShapes ( Primitive shape1, Primitive shape2 ) : void
shape1 Primitive /// The first shape name. ///
shape2 Primitive /// The second shape name. ///
return void

Help() public static method

This function is just to display this help. The extension uses Box2D (http://box2d.org) as an engine and provides an interface between it and the graphics capabilities of SmallBasic. Only shapes that are connected to the physics engine take part in the motion physics, for example you may add normal shapes (e.g. a gun and not connect it to the physics engine). Once a shape is connected to the engine, it is best to only interact with it through the methods provided by the extension. All positions are in the SmallBasic GraphicsWindow pixels and refer to shape centres. Image and text shapes are treated as rectangles, and ellipses as circles; there is also triangle and convex polygon support, but not lines. Images may be treated as circles by setting the property LoadImagesAsCircles to "True". One issue that Box2D has difficulty with is small fast moving objects that can 'tunnel' through other shapes without being deflected (see the SetBullet option). Another problem is shapes of very different size and hence mass, especially large shapes when they are connected together. It may be necessary to modify the density for these (the Anchor options are an attempt to automate this a bit), otherwise the default density of 1 is good. Resist the temptation to connect too many shapes together. It may be possible to improve the stability of some 'difficult' models using the TimestepControl settings, but the defaults look good for most cases. Do not call the physics methods inside SmallBasic event subroutines directly, rather set flags that can be processed in a main game loop. There are sample SmallBasic programs and a Getting Started Guide that comes with the extension dll - this is the best place to start. Report bugs and problems to the SmallBasic forum (http://social.msdn.microsoft.com/Forums/en-US/smallbasic/threads), but first simplify your SmallBasic code to isolate the issue before providing a short 'runnable' code sample.
public static Help ( ) : void
return void

MoveTire() public static method

Move a tire shape, apply a forward or backward force.
public static MoveTire ( Primitive shapeName, Primitive force ) : void
shapeName Primitive The tire shape to move.
force Primitive The force to apply, positive is forward, negative is backward.
return void

PanView() public static method

Pan the camera view, including window boundaries.
public static PanView ( Primitive panHorizontal, Primitive panVertical ) : void
panHorizontal Primitive /// Pan in the horizontal direction (negative is left). ///
panVertical Primitive /// Pan in the vertical direction (negative is up). ///
return void

RayCast() public static method

Cast an invisible ray to detect the proximity of shapes.
public static RayCast ( Primitive shapeName, Primitive angle, Primitive distance ) : Primitive
shapeName Primitive The shape to cast the ray from.
angle Primitive The angle in degrees to check, this can also be an array of angles.
distance Primitive A maximum distance to check.
return Primitive

ReadJson() public static method

Read in a json script compatible with R.U.B.E. and create a LDPhysics model. See https://www.iforce2d.net/rube for more details.
public static ReadJson ( Primitive fileName, Primitive scale, Primitive reverseY, Primitive stationary, Primitive offsetX, Primitive offsetY ) : Primitive
fileName Primitive The full path to the json file to read.
scale Primitive Scale all shapes, default 1 (no scaling).
reverseY Primitive Reverse the Y direction up to down ("True" or "False").
stationary Primitive Set all shapes to be initially at rest, joint motors are still enabled ("True" or "False").
offsetX Primitive Add an x coordinate offset to all shapes.
offsetY Primitive Add a y coordinate offset to all shapes, especially useful when reverseY is set.
return Primitive

RemoveChain() public static method

Remove a chain.
public static RemoveChain ( Primitive shapeName ) : void
shapeName Primitive /// The chain name. ///
return void

RemoveFrozen() public static method

Removes all frozen shapes - outside the AABB for the engine.
public static RemoveFrozen ( ) : void
return void

RemoveRope() public static method

Remove a rope.
public static RemoveRope ( Primitive shapeName ) : void
shapeName Primitive /// The rope name. ///
return void

RemoveShape() public static method

Remove a shape.
public static RemoveShape ( Primitive shapeName ) : void
shapeName Primitive /// The name of the shape. ///
return void

Reset() public static method

Reset (delete all physics engine attached shapes).
public static Reset ( ) : void
return void

SetAABB() public static method

The physics engine AABB (axis-aligned bounding box). The units are the engine units of m. A Reset is required after setting. It is not recommended to change this.
public static SetAABB ( Primitive minX, Primitive maxX, Primitive minY, Primitive maxY ) : void
minX Primitive /// The left coordinate of the universe (default -100). ///
maxX Primitive /// The right coordinate of the universe (default 200). ///
minY Primitive /// The top coordinate of the universe (default -100). ///
maxY Primitive /// The bottom coordinate of the universe (default 200). ///
return void

SetAngle() public static method

Reset the angle of rotation for a shape.
public static SetAngle ( Primitive shapeName, Primitive angle ) : void
shapeName Primitive /// The shape name. ///
angle Primitive /// The angle of rotation in degrees. ///
return void

SetBoundaries() public static method

Set solid boundaries (positioning a boundary outside the GraphicsWindow removes it).
public static SetBoundaries ( Primitive left, Primitive right, Primitive top, Primitive bottom ) : void
left Primitive /// The left boundary X value. ///
right Primitive /// The right boundary X value. ///
top Primitive /// The top boundary Y value. ///
bottom Primitive /// The bottom (ground) boundary Y value. ///
return void

SetBullet() public static method

Set a shape as a bullet. This prevents 'tunnelling' of fast moving small objects at the expense of performance.
public static SetBullet ( Primitive shapeName ) : void
shapeName Primitive /// The shape name. ///
return void

SetDamping() public static method

Set a damping factor for a shape (default 0).
public static SetDamping ( Primitive shapeName, Primitive linear, Primitive angular ) : void
shapeName Primitive /// The shape to modify. ///
linear Primitive /// Linear damping factor. ///
angular Primitive /// Angular damping factor. ///
return void

SetForce() public static method

Set a force to apply to a shape (Remember F = ma).
public static SetForce ( Primitive shapeName, Primitive forceX, Primitive forceY ) : void
shapeName Primitive /// The shape to modify. ///
forceX Primitive /// X component of the force. ///
forceY Primitive /// Y component of the force. ///
return void

SetGravity() public static method

Set the gravity direction and magnitude (default 0,100).
public static SetGravity ( Primitive gravX, Primitive gravY ) : void
gravX Primitive /// The X component of gravity. ///
gravY Primitive /// The Y component of gravity. ///
return void

SetGroup() public static method

Control which sprites interact (collide) with other shapes.
public static SetGroup ( Primitive shapeName, Primitive group, Primitive mask ) : void
shapeName Primitive /// The shape to modify. ///
group Primitive /// The group that the current shape belongs to (default 0). This should be an integer between 0 and 15. ///
mask Primitive /// An array of groups that this shape will collide with (default all groups 0,1,2,..,14,15). /// To allow the shape to only interact with groups 0, 1 and 4 would be "1=0;2=1;3=4;". ///
return void

SetImpulse() public static method

Set an impulse to a shape (a kick).
public static SetImpulse ( Primitive shapeName, Primitive impulseX, Primitive impulseY ) : void
shapeName Primitive /// The shape to modify. ///
impulseX Primitive /// X component of the impulse. ///
impulseY Primitive /// Y component of the impulse. ///
return void

SetJointMotor() public static method

Set a motor for selected joints (Line, Prismatic_H, Prismatic_V and Revolute).
public static SetJointMotor ( Primitive jointName, Primitive speed, Primitive maxForce ) : void
jointName Primitive /// The joint name. ///
speed Primitive The desired motor speed.
maxForce Primitive The maximum motor force (torque for Revolute). /// A zero value turns motor off.
return void

SetPosition() public static method

Reset shape position.
public static SetPosition ( Primitive shapeName, Primitive posX, Primitive posY, Primitive angle ) : void
shapeName Primitive /// The shape to modify. ///
posX Primitive /// X component shape centre. ///
posY Primitive /// Y component shape centre. ///
angle Primitive /// The angle of rotation in degrees. ///
return void

SetRotation() public static method

Set shape rotation speed.
public static SetRotation ( Primitive shapeName, Primitive rotation ) : void
shapeName Primitive /// The shape to modify. ///
rotation Primitive /// The angular rotation speed degrees/s. ///
return void

SetShapeGravity() public static method

Set the gravity direction and magnitude for an individual shape (default 0,100).
public static SetShapeGravity ( Primitive shapeName, Primitive gravX, Primitive gravY ) : void
shapeName Primitive /// The shape to modify. ///
gravX Primitive /// The X component of gravity. ///
gravY Primitive /// The Y component of gravity. ///
return void

SetTire() public static method

Set an object to act as a drivable tire for a top down game. Usually gravity will be 0 and the shape should already be added to the engine. The object should be initially positioned facing forward up on the display.
public static SetTire ( Primitive shapeName ) : void
shapeName Primitive The shape to make a tire.
return void

SetTireProperties() public static method

Set tire properties, they include: AntiSkid (higher value reduces skid) Drag (higher value increases forward/backward drag) Brake (higher value increases braking power) Straighten (higher value restores stearing more quickly) BrakeStraighten (higher value restores stearing more quickly while braking)
public static SetTireProperties ( Primitive shapeName, Primitive properties ) : void
shapeName Primitive The tire shape.
properties Primitive An array of one or more properties to set. /// The index is one of the properties (case sensitive) and the value is the property value.
return void

SetTorque() public static method

Set a torque to a shape (a rotational kick).
public static SetTorque ( Primitive shapeName, Primitive torque ) : void
shapeName Primitive /// The shape to modify. ///
torque Primitive /// The torque to apply. ///
return void

SetVelocity() public static method

Set the velocity of a shape.
public static SetVelocity ( Primitive shapeName, Primitive velX, Primitive velY ) : void
shapeName Primitive /// The shape to modify. ///
velX Primitive /// X component of the velocity. ///
velY Primitive /// Y component of the velocity. ///
return void

TimestepControl() public static method

Modify default timestep control parameters - also can be set using individual parameters.
public static TimestepControl ( Primitive timestep, Primitive velocityIterations, Primitive positionIterations ) : void
timestep Primitive /// Time-step (default 0.025). ///
velocityIterations Primitive /// Velocity iterations (default 6). ///
positionIterations Primitive /// Position iterations (default 2). ///
return void

ToggleMoving() public static method

Toggle a moving shape to be fixed and vice-versa. This method also sets the rotation to be on or off to match if it is moving or fixed.
public static ToggleMoving ( Primitive shapeName ) : void
shapeName Primitive The shape name.
return void

ToggleRotation() public static method

Toggle a shape to not rotate and vice-versa. This method toggles the rotation property for fixed and moving shapes.
public static ToggleRotation ( Primitive shapeName ) : void
shapeName Primitive The shape name.
return void

ToggleSensor() public static method

Toggle a shape to act as a sensor and vice-versa. A sensor shape does not interact with other shapes, but still provides collision data.
public static ToggleSensor ( Primitive shapeName ) : void
shapeName Primitive The shape name.
return void

TurnTire() public static method

Turn a tire shape, steer left or right.
public static TurnTire ( Primitive shapeName, Primitive torque ) : void
shapeName Primitive The tire shape to turn.
torque Primitive The torque, rotation force to apply, positive is turn right, negative is turn left.
return void

UngroupShapes() public static method

Remove shape group pairing.
public static UngroupShapes ( Primitive shape1, Primitive shape2 ) : void
shape1 Primitive /// The first shape name. ///
shape2 Primitive /// The second shape name. ///
return void

UnsetBullet() public static method

Unset a shape as a bullet. This reverts the shape to normal collision detection.
public static UnsetBullet ( Primitive shapeName ) : void
shapeName Primitive /// The shape name. ///
return void

WakeAll() public static method

Wake all sleeping shapes - shapes sleep due to no applied forces or contacts. They wake automatically on any contact or applied force, so this action is rarely required.
public static WakeAll ( ) : void
return void

WriteJson() public static method

Write out a json script compatible with R.U.B.E. from current LDPhysics model. See https://www.iforce2d.net/rube for more details.
public static WriteJson ( Primitive fileName ) : void
fileName Primitive The full path to the json file to create.
return void