Class: SimpleRotator

SimpleRotator(canvas, callback, viewDirectionVector, viewUpVector, viewDistance)

An object of type SimpleRotator can be used to implement a trackball-like mouse rotation of a WebGL scene about the origin.

Only the first parameter of the constructor is required.
When an object is created, mouse event handlers are set up on the canvas to respond to rotation.
It will also work with a touchscreen.

Constructor

new SimpleRotator(canvas, callback, viewDirectionVector, viewUpVector, viewDistance)

Constructor of SimpleRotator.

Parameters:
Name Type Description
canvas HTMLCanvasElement the HTML canvas element used for WebGL drawing.
The user will rotate the scene by dragging the mouse on this canvas.
This parameter is required.
callback function if present must be a function, which is called whenever the rotation changes.
It is typically the function that draws the scene
viewDirectionVector Array.<Number> if present must be an array of three numbers, not all zero.
The view is from the direction of this vector towards the origin (0,0,0).
If not present, the value [0,0,10] is used.
viewUpVector Array.<Number> if present must be an array of three numbers.
Gives a vector that will be seen as pointing upwards in the view.
If not present, the value is [0,1,0].
viewDistance Number if present must be a positive number.
Gives the distance of the viewer from the origin.
If not present, the length of viewDirectionVector is used.
Source:

Methods

getViewDistance() → {Number}

Returns the viewDistance.
Source:
Returns:
view distance.
Type
Number

getViewMatrix() → {Float32Array}

Returns an array representing the viewing transformation matrix for the current view,
suitable for using with gl.uniformMatrix4fv or, for further transformation, with the glmatrix library mat4 class.
Source:
Returns:
view matrix.
Type
Float32Array

getViewMatrixArray() → {Array.<Number>}

Returns the view transformation matrix as a regular JavaScript array,
but still represents as a 1D array of 16 elements, in column-major order.
Source:
Returns:
view matrix.
Type
Array.<Number>

setView(viewDirectionVector, viewUpVector, viewDistance)

Set up the view, where the parameters are optional, and are used in the same way,
as the corresponding parameters in the constructor.
Parameters:
Name Type Description
viewDirectionVector Array.<Number> if present must be an array of three numbers, not all zero.
The view is from the direction of this vector towards the origin (0,0,0).
If not present, the value [0,0,10] is used.
viewUpVector Array.<Number> if present must be an array of three numbers.
Gives a vector that will be seen as pointing upwards in the view.
If not present, the value is [0,1,0].
viewDistance Number if present must be a positive number.
Gives the distance of the viewer from the origin.
If not present, the length of viewDirectionVector is used.
Source:

setViewDistance(viewDistance)

Sets the distance of the viewer from the origin without changing the direction of view.
If not present, the length of viewDirectionVector is used.
Parameters:
Name Type Description
viewDistance Number view distance.
Source:

setViewMatrix(matrix)

Sets the view matrix.
Parameters:
Name Type Description
matrix Float32Array view matrix.
Source: