Class: Camera

Camera

new Camera(wcCenter, wcWidth, viewportArray, bound) → {Camera}

Default Constructor

Height of the user defined WC is implicitly defined by the viewport aspect ratio

viewportRect: an array of 4 elements

[0] [1]: (x,y) position of lower left corner on the canvas (in pixel)

[2]: width of viewport

[3]: height of viewport

Parameters:
Name Type Description
wcCenter vec2 Center position of Camera
wcWidth Number Width of Camera
viewportArray Array.<Float> position and size of viewport [x, y, width, height]
bound Number viewport border
Source:
Returns:
New instance of Camera
Type
Camera

Members

(static) eViewport :enum|eViewport

Viewport enum
Type:
  • enum | eViewport
Source:

Methods

clampAtBoundary(aXform, zone) → {eboundCollideStatus}

prevents the xform from moving outside of the WC boundary

by clamping the aXfrom at the boundary of WC

Parameters:
Name Type Description
aXform Transform to check collision status
zone Float distance from the camera border to collide with
Source:
Returns:
Collision status of the parameter transform and Camera
Type
eboundCollideStatus

collideWCBound(aXform, zone) → {eboundCollideStatus}

Check if parameter transform collides with the camera border
Parameters:
Name Type Description
aXform Transform to check collision status
zone Float distance from the camera border to collide with
Source:
Returns:
Collision status of the parameter transform and Camera
Type
eboundCollideStatus

configInterpolation(stiffness, duration) → {void}

Confiqure interpolation of camera
Parameters:
Name Type Description
stiffness Number stiffness value of interpolate, stiffness of 1 switches off interpolation
duration Number duration value of interpolate
Source:
Returns:
Type
void

fakeZInPixelSpace(z) → {Number}

Returns Fake z position in Pixel Space
Parameters:
Name Type Description
z Number value to scale with pixel ratio
Source:
Returns:
fake z position in Pixel space
Type
Number

getBackgroundColor() → {Array.<Float>}

Return the background color of the Camera
Source:
Returns:
Type
Array.<Float>

getPosInPixelSpace() → {vec3}

Return Camera position in pixel space
Source:
Returns:
Camera position in pixel space
Type
vec3

getViewport() → {Array}

Return the Camera viewport
Source:
Returns:
camera Viewport [x, y, width, height]
Type
Array

getVPMatrix() → {mat4}

Return the View-Projection transform operator
Source:
Returns:
View-Projection transform
Type
mat4

getWCCenter() → {vec2}

Return the World Coordinate center position
Source:
Returns:
World Coordinate center position
Type
vec2

getWCHeight() → {Number}

Return the height of the World Coordinate
Source:
Returns:
height of the World Coordinate
Type
Number

getWCWidth() → {Number}

Return the width of the World Coordinate
Source:
Returns:
width of the World Coordinate
Type
Number

isMouseInViewport() → {Boolean}

Checks if the mouse position is inside the Camera viewport
Source:
Returns:
true if mouse position is inside viewport
Type
Boolean

mouseDCX() → {Number}

Returns mouse X position.
Source:
Returns:
Type
Number

mouseDCY() → {Number}

Returns mouse Y position.
Source:
Returns:
Type
Number

mouseWCX() → {Number}

Returns the mouse X World Coordinate position
Source:
Returns:
Type
Number

mouseWCY() → {Number}

Returns the mouse Y World Coordinate position
Source:
Returns:
Type
Number

panBy(dx, dy) → {void}

Pan the Camera by dx and dy
Parameters:
Name Type Description
dx Number X value to pan the camera
dy Number Y value to pan the camera
Source:
Returns:
Type
void

panTo(cx, cy) → {void}

Pan Camera to cx, cy position
Parameters:
Name Type Description
cx Number X position to pan the camera to
cy Number Y position to pan the camera to
Source:
Returns:
Type
void

panWith(aXform, zone) → {void}

pan the camera to ensure aXform is within camera bounds

this is complementary to the ClampAtBound: instead of clamping aXform, now, move the camera.

Parameters:
Name Type Description
aXform Transform Transform to clamp the Camera to
zone Number distance from the camera border to collide with
Source:
Returns:
Type
void

setBackgroundColor(newColor) → {void}

Set the background color of the Camera
Parameters:
Name Type Description
newColor Array.<Float> new color of the background
Source:
Returns:
Type
void

setupViewProjection() → {void}

Initializes the camera to begin drawing
Source:
Returns:
Type
void

setViewport(viewportArray, bound) → {void}

Set the Camera viewport
Parameters:
Name Type Description
viewportArray Array.<Float> viewportArray position and size of viewport [x, y, width, height]
bound Number viewport border
Source:
Returns:
Type
void

setWCCenter(xPos, yPos) → {void}

Set the World Coordinate center position
Parameters:
Name Type Description
xPos Number World Coordinate X position
yPos Number World Coordinate Y position
Source:
Returns:
Type
void

setWCWidth(width) → {void}

Set the World Coordinate width
Parameters:
Name Type Description
width Number of the World Coordinate
Source:
Returns:
Type
void

shake(xDelta, yDelta, shakeFrequency, duration) → {void}

Initiates a camera shake
Parameters:
Name Type Description
xDelta Number how large a shake
yDelta Number how large a shake
shakeFrequency Number how much movement
duration Number for how long in number of cycles
Source:
Returns:
Type
void

update() → {void}

update function to be called from EngineCore.GameLoop.
Source:
Returns:
Type
void

wcDirToPixel(d) → {vec3}

transform direction in wc space to pixel space
Parameters:
Name Type Description
d vec3 vec3 direction in WC
Source:
Returns:
Type
vec3

wcPosToPixel(p) → {vec3}

Returns World Coordinate position as a pixel position
Parameters:
Name Type Description
p vec3 vec3 position, fake Z
Source:
Returns:
Pixel space position
Type
vec3

wcSizeToPixel(s) → {vec2}

Returns Pixel size of World Coordinate size
Parameters:
Name Type Description
s vec2 world coordinate size to convert to pixel size
Source:
Returns:
Pixel size of World Coordinate size
Type
vec2

zoomBy(zoom) → {void}

zoom with respect to the center

zoom > 1 ==> zooming out, see more of the world

zoom < 1 ==> zooming in, see less of the world, more detailed

zoom < 0 is ignored

Parameters:
Name Type Description
zoom Number to scale the camera width
Source:
Returns:
Type
void

zoomTowards(pos, zoom) → {void}

zoom towards (pX, pY) by zoom:

zoom > 1 ==> zooming out, see more of the world

zoom < 1 ==> zooming in, see less of the world, more detailed

zoom < 0 is ignored

Parameters:
Name Type Description
pos vec2 Point to scale the camera with respect to
zoom Number to scale the camera width
Source:
Returns:
Type
void