Class: CanvasController

CanvasController

new CanvasController()

Class creates listeners for a range of user events on the canvas. This class is responsible for setting up and implimenting listeners for different sets of actions performed on the canvas area. Including zooming, rotating and moving around the scene.
Source:

Methods

getLatestMoveX() → {Integer}

Returns the last accumulated movement along X axis
Source:
Returns:
getLatestMoveX Amount of movement along x axis in pixels.
Type
Integer

getLatestMoveZ() → {Integer}

Returns the last accumulated movement along Z axis
Source:
Returns:
getLatestMoveZ Amount of movement along z axis in pixels.
Type
Integer

getLatestTargetRotationX() → {Integer}

Returns the last accumulated rotatoion on X axis
Source:
Returns:
targetRotationX Amount of rotation along x axis in degrees.
Type
Integer

getLatestTargetRotationY() → {Integer}

Returns the last accumulated rotation on Y axis
Source:
Returns:
targetRotationY Amount of rotation along y axis in degrees.
Type
Integer

init(r, c)

Initial function which is called on startup for creating event listeners in the canvas area. Including scroll, mouse drag, touch drag and keyboard events.
Parameters:
Name Type Description
r Renderer Renderer object to have listeners added to
c Camera Camera object to have zoom and aspect ratio modified by events
Source:

onDocumentMouseDown(event)

Event that calculates the rotation and movement performed by the user starting from the mouse down to mouse up events. Sets global variables holding these values for use in the get methods used by the Main class.
Parameters:
Name Type Description
event Event Event triggured
Source:

onDocumentMouseMove(event)

Multiplies the rotating by 0.02 each time the mouse is moved whilst held down on the canvas.
Parameters:
Name Type Description
event Event Event triggured
Source:

onDocumentMouseOut(event)

Removes the listeners for mouse events once a user moves the mouse out of the canvas.
Parameters:
Name Type Description
event Event Event triggured
Source:

onDocumentMouseUp(event)

Removes the listeners for mouse events once a user releases the mouse click button on the canvas.
Parameters:
Name Type Description
event Event Event triggured
Source:

onDocumentTouchMove(event)

Alternative event for calculating rotation, for touch devices. Will work on phones and rotate scene when user drags across the screen.
Parameters:
Name Type Description
event Event Event triggured
Source:

onDocumentTouchStart(event)

Adds the listener for different mouse actions once a user clicks onto the canvas, holding the mouse down/
Parameters:
Name Type Description
event Event Event triggured
Source:

onKeyDown(event)

A listener to run each time the up, down, left and right arrows are pressed. Sets the global variables which are acesses in get methods to navigate the camera about the canvas.
Parameters:
Name Type Description
event Event Event triggured
Source:

onMouseScroll(event)

Updates the camera zoom parameter based on the amount scrolled. Has a maximum and minimum value of scroll.
Parameters:
Name Type Description
event Event Event triggured
Source:

onWindowResize()

Resizes the canvas in relation to the window size. Resizes all the objects too, and changes the camera perspective to view from the correct range.
Source: