Skip to content
thothbot edited this page Mar 4, 2016 · 15 revisions

Controls

Controls are used to handle user events, such as mouse move, keyboards events, and make needed operation with a controlled object.

Description

All controls are inherited from the abstract Controls class, which has the following constructor:

    public Controls(Object3D object, Widget widget);

Where:

  • object - Object3D which will be controlled, for example Cameras objects.
  • widget - Widget where control commands are listened. Basically here should be Canvas3d widget.

All controls has the common initialization. The following controls on an example of control from a first person:

class MyScene extends AnimatedScene 
{
    FirstPersonControls controls;
    
    @Override
    protected void onStart()
    {
        this.controls = new FirstPersonControls( camera, getCanvas() );
    }

    @Override
    protected void onUpdate(double duration)
    {
        this.controls.update();
    }
}

Available controls

Control from a first person

There are implemented the following:

  • Disabled context menu for the widget.
  • Mouse:
    • Mouse move - rotate the object.
    • Mouse down - translate the object forward.
    • Mouse up - translate the object backward.
  • Keyboard:
    • [W or up] - translate the object forward.
    • [S or down] - translate the object backward.
    • [A or left] - translate the object to the left.
    • [D or right] - translate the object to the right.
    • [R] - translate the object up.
    • [F] - translate the object down.
    • [Q] - freez the object

Methods:

  • setMovementSpeed()
  • setLookSpeed()

Fly controls

  • Disabled context menu for the widget.
  • Mouse:
    • Mouse up/down or [up/down] - pitch the object up or down.
    • Mouse left/right or [left/right] - yaw the object left or right.
  • Keyboard:
    • [W] - translate the object forward.
    • [S] - translate the object backward.
    • [A] - translate the object to the left.
    • [D] - translate the object to the right.
    • [R] - translate the object up.
    • [F] - translate the object down.
    • [Q] - rotate the object left.
    • [E] - rotate the object right.

Methods:

  • setMovementSpeed()
  • setRollSpeed()

Trackball Controls

There are implemented the following:

  • Disabled context menu for the widget.
  • Object rotation: [left mouse button] or [A] + mouse drag
  • Object zooming: [center mouse button] or [S] + mouse drag
  • Object moving or pan: [right mouse button] or [D] + mouse drag

Methods:

  • setEnabled()

    Disables/enables the controlls. By default it is true.

  • setRotate(), setZoom(), setPan()

    Enables/Disables rotation, zoom, pan respectively. By default they are true.

  • setRotateSpeed(), setZoomSpeed(), setPanSpeed()

    Sets the rotation, zoom, pan speed respectively.

  • setKeyRotate() , setKeyZoom(), setKeyPan

    Sets keys to handle keyboard events. By default they are A, S, D .

  • setStaticMoving()

    Enables/disables static moving. By default it is true. If it is false then enabled dynamic moving and can be configured setDynamicDampingFactor().

  • setMinDistance(), setMaxDistance()

    Sets min and max distances to the object. By default 0 and Inf.

Clone this wiki locally