Class myphysicslab.sims.engine2D.RigidBodyObserver

Provided By
All Implemented Interfaces

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.

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
var dispPoly1 = displayList.find(polygon1);

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 myphysicslab.sims.engine2D.Engine2DApp, the rbo property is an instance of RigidBodyObserver.

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

Displaying Contact Forces

Instances of myphysicslab.lab.model.Force are displayed with myphysicslab.lab.view.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 myphysicslab.lab.util.GenericObserver for example code that sets the color of the DisplayLine based on contact gap distance.

new RigidBodyObserver( simList, displayList )


SimList to observe, and will process all the objects currently on the SimList


the DisplayList to add DisplayObjects to

Instance Methods

Instance Properties

Static Properties

Type Definitions