Automatically creates a DisplayObject for most types of SimObject when they are added to a SimList. Observes the SimList of a Simulation, adding or removing DisplayObjects to/from a DisplayList to represent the Simulation.

The constructor processes all the objects currently on the SimList, creating DisplayObjects for them.

Setting the Style of a DisplayObject

To control the style (color, line thickness, etc) used for a particular DisplayObject there are two approaches.

1. Modify the style directly

Modify the DisplayObject's style directly after it has been created. Here is an example:

simList.add(polygon1); // RigidBodyObserver creates a DisplayShape here
const dispPoly1 = displayList.findShape(polygon1);
dispPoly1.setFillStyle('red');

2. Modify the prototype

Many DisplayObjects allow specifying a prototype DisplayObject. When a display property is undefined, then the property is fetched from the prototype. If it is also undefined on the prototype then a default value is used.

RigidBodyObserver sets up around a dozen prototype objects. The DisplayObjects that RigidBodyObserver creates all have their prototypes set to be these objects. Keep in mind that all objects with that prototype will be affected.

Here is an example where we cause Polygons to draw their names. For apps that extend Engine2DApp, the rbo property is an instance of RigidBodyObserver.

this.rbo.protoPolygon.setNameFont('10pt sans-serif');

Displaying Contact Forces

Instances of Force are displayed with DisplayLine objects.

The policy used here is to only show the first contact Force when there is a pair of opposing contact Forces. Forces named 'contact_force1' are shown. Forces named 'contact_force2' are assumed to be the second Force of pair and are not displayed.

See GenericObserver for example code that sets the color of the DisplayLine based on contact gap distance.

Implements

Constructors

Properties

protoCollision: DisplayShape

Prototype DisplayShape for showing collisions.

protoConcreteLine: DisplayLine

Prototype DisplayLine for showing ConcreteLines.

protoContactForce: DisplayLine

Prototype DisplayLine for showing contact forces.

protoDragSpring: DisplaySpring

Prototype DisplaySpring for the spring that appears when user clicks mouse near a RigidBody. See RigidBodyEventHandler.

protoFixedPolygon: DisplayShape

Prototype DisplayShape for showing fixed, infinite mass Polygons.

protoForce: DisplayLine

Prototype DisplayLine for showing forces other than contact and thrust forces.

protoJoint: DisplayConnector

Prototype DisplayConnector for showing joints.

protoPathEndPoint: DisplayConnector

Prototype DisplayConnector for showing PathEndPoint.

protoPointMass: DisplayShape

Prototype DisplayShape for showing PointMass objects.

protoPolygon: DisplayShape

Prototype DisplayShape for showing Polygon.

protoRope: DisplayRope

Prototype DisplayRope for showing Ropes.

protoSpring: DisplaySpring

Prototype DisplaySpring for showing Springs.

protoThrustForce: DisplayLine

Prototype DisplayLine for showing thrust forces.

ordering: string = 'over'

Whether to add the next object 'over' or 'under' other DisplayObjects with the same zIndex. See DisplayObject.getZIndex. 'over' means the next object will appear above other DisplayObjects with the same zIndex; 'under' means it will appear below.

Methods

  • Notifies this Observer that a change has occurred in the Subject.

    Parameters

    • event: SubjectEvent

      contains information about what has changed in the Subject: typically either a one-time GenericEvent, or a change to the value of a Parameter

    Returns void

  • Returns a minimal string representation of this object, usually giving just identity information like the class name and name of the object.

    For an object whose main purpose is to represent another Printable object, it is recommended to include the result of calling toStringShort on that other object. For example, calling toStringShort() on a DisplayShape might return something like this:

    DisplayShape{polygon:Polygon{'chain3'}}
    

    Returns string

    a minimal string representation of this object.

Generated using TypeDoc