5.6 MouseModulator

  Download source    View color-coded source

Content of MouseModulator.js:
MouseModulator
This modulator returns a rotation matrix depending on mouse interactions. When a mouseUp event occurs the rotation will spin the object and slow down gradually.


function MouseModulator(name, mode)
Constructs a MouseModulator.

The mode parameter specifies the interaction mode of the modulator, use MouseModulator.MODE_xxx constants here.
You can rotate around x and y (MODE_ROTATE), just on of them (MODE_ROTATE_X and MODE_ROTATE_Y), or move the model (MODE_MOVE).

Parameters
    String name - the name of the variable storing this object, e.g.
        var myMouseModulator = new MouseModulator("myMouseModulator");
    int mode - see above
Returns
    MouseModulator - a new MouseModulator instance



function getMatrix()
Returns the (rotation) matrix to transform with.

Returns
    Matrix - The matrix to transform with.



function animate()
Updates the modulator's matrix according to mouse movements.


function render(dX, dY)
In the render method, the modulator's matrix is computed using the current control values.
The way the connected object can be rotated and/or moved depends on the interaction mode.

Paramters
    int dX - x distance amount
    int dY - y distance amount



function up(e)
The mouseUp eventhandler. Pass the event object e when calling this method in the page's event handler.

Parameters
    Event e - the event object, just pass this on from your original handler



function down(e)
The mouseDown eventhandler. Pass the event object e when calling this method in the page's event handler.

Parameters
    Event e - the event object, just pass this on from your original handler



function move(e)
The mouseMove eventhandler. Pass the event object e when calling this method in the page's event handler.

Parameters
    Event e - the event object, just pass this on from your original handler



MouseModulator constants
The MouseModulator class contains the following constants for setting the mouse interaction mode:

Constants specifying the possible interaction modes. Use these when setting the modulator's mode, e.g. myMouseModulator.setMode(MouseModulator.MODE_ROTATE);

MouseModulator.MODE_ROTATE
MouseModulator.MODE_MOVE
MouseModulator.MODE_ROTATE_X
MouseModulator.MODE_ROTATE_Y