User interface controller for RigidBodySim, provides mouse dragging of nearest moveable RigidBody, and keyboard thrust controls for one or two selected RigidBodys.

Mouse Drag

When the Clock is running, mouse dragging is accomplished by connecting a spring between the RigidBody and the mouse position. The spring has zero rest length. The spring stiffness can be set via setDragStiffness.

When the Clock is not running, mouse dragging will move the RigidBody. Holding down the alt, meta, or control key will rotate the RigidBody when moving the mouse.

Thrusters

One or two RigidBodys can be specified to have keyboard activated thruster controls with setThrusters. You can specify a ThrusterSet of thrust forces for each RigidBody. The keyboard commands to fire thrusters are:

  • Right hand controls: keys J, K, L, I and arrow keys.
  • Left hand controls: keys S, D, F, E.

Some of the key commands will fire pairs of 'side ways' thrust controls. Holding shift key changes the pair of thrusters to give a rotation effect.

TO DO extract the stuff about thrusters into a subclass or decorating class, so that the mouse drag stuff could be reused separately.

Implements

Constructors

Properties

optionKey_: boolean = false

whether alt, meta or control key is down

shiftLeft_: boolean = false

Remember whether shift key was down when these keys (left, right, S, F) are first pressed, so that we use the same value for shift key when the key is released. (Fixes the 'stuck thruster' problem).

startBodyAngle_: number = 0

for rotating a body

startDragAngle_: number = 0

for rotating a body

Methods

  • Called at the end of a mouse drag operation, performs whatever action is appropriate. Only called if startDrag returned true.

    Parameters

    • _simObject: null | SimObject

      the SimObject being dragged, or null if no SimObject was found

    • _location: Vector

      the location of the mouse in simulation coordinates of the SimView where simObject was found, or in the focus view if simObject is null.

    • _offset: Vector

      distance from the initial object position to the mouse location at start of drag.

    Returns void

  • Called when a key is pressed or released, performs whatever action is appropriate for that event.

    Parameters

    • evt: KeyboardEvent

      the KeyboardEvent that happened

    • pressed: boolean

      true means this is a key-down event; false means a key-up event

    • modifiers: ModifierKeys

      the modifier keys down during event

    Returns void

  • Called at each movement during a mouse drag, performs whatever action is appropriate. Only called if startDrag returned true. The SimObject being moved is passed in, along with the current mouse position, in simulation coordinates, and an offset calculated at the start of the drag.

    Setting the SimObject position to (x - offsetX, y - offsetY) will move the SimObject smoothly along with the mouse movement.

    Parameters

    • _simObject: null | SimObject

      the SimObject being dragged, or null if no SimObject was found

    • location: Vector

      the location of the mouse in simulation coordinates of the SimView where simObject was found, or in the focus view if simObject is null.

    • offset: Vector

      distance from the initial object position (from DisplayObject.getPosition) to the mouse location at start of drag.

    Returns void

  • Set the given ThrusterSet to be activated by keyboard thrust controls. Right hand controls: keys J, K, L, I and arrow keys. Left hand controls: keys S, D, F, E.

    Parameters

    • thrusters: null | ThrusterSet

      the ThrusterSet to be activated by keyboard commands, or null to turn off this set of thruster controls

    • side: string

      'right' sets right hand controls, 'left' sets left hand controls

    Returns void

  • Called at the start of a mouse drag. The nearest dragable SimObject is passed in, along with mouse position in simulation coordinates. If no dragable SimObject was found, null is passed for the first argument. If the EventHandler does not recognize the SimObject then it should return false.

    Parameters

    • simObject: null | SimObject

      the SimObject that is nearest to the mouse drag coordinates, or null if no SimObject was found

    • location: Vector

      the location of the mouse in simulation coordinates of the SimView where simObject was found, or in the focus view if simObject is null.

    • offset: Vector

      distance from the initial object position (from DisplayObject.getPosition) to the mouse location at start of drag

    • dragBody: null | Vector

      location of 'drag point' on the SimObject in body coordinates of the SimObject; this is where for example a spring will be attached on the SimObject when dragging; or null when no SimObject was found

    • modifiers: ModifierKeys

      the modifier keys down during event

    Returns boolean

    true if the EventHandler will handle dragging the SimObject

  • 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