Class: Camera

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

Class that encapsulates the scaling and translation of the portions of the game world that are visible.

Found in Chapter 3, page 102 of the textbook

Examples: 3.5 Camera Objects, 7.4 Multiple Cameras

Constructor

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

Parameters:
Name Type Description
wcCenter vec2 center position of Camera in world coordinates
wcWidth float width of the world, implicitly defines the world height
viewportArray Array.<float> 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
bound float viewport border
Source:
Returns:
a new Camera instance
Type
Camera

Members

(static, constant) eViewport

Enum for viewport properties index
Source:

Methods

_mouseDCX() → {integer}

Return the mouse x position with respect to the viewport origin
Source:
Returns:
mouse x position
Type
integer

_mouseDCY() → {integer}

Return the mouse y position with respect to the viewport origin
Source:
Returns:
mouse y position
Type
integer

clampAtBoundary(aXform, zone) → {eBoundCollideStatus}

Moves the Transform parameter back inside of the WC boundary
Parameters:
Name Type Description
aXform Transform Transform to detect collision and clamp
zone float distance from the Camera border to collide with
Source:
Returns:
Collision status for aXform and this Camera
Type
eBoundCollideStatus

collideWCBound(aXform, zone) → {eBoundCollideStatus}

Detect if parameter Transform collides with the border of this Camera
Parameters:
Name Type Description
aXform Transform Transform to detect collision status
zone float distance from the Camera border to collide with
Source:
Returns:
Collision status for aXform and this Camera
Type
eBoundCollideStatus

configLerp(stiffness, duration)

Configure the linear interpolation of this Camera
Parameters:
Name Type Description
stiffness float the rate for the interpolations
duration integer the number of cycles for the interpolations
Source:

fakeZInPixelSpace(z) → {float}

Return a fake z world coordinate converted to pixel space
Parameters:
Name Type Description
z float value to scale with pixel ratio
Source:
Returns:
fake z position in pixel space
Type
float

getBackgroundColor() → {Array.<float>}

Return the background color of this Camera
Source:
Returns:
mBGColor - background color of this Camera
Type
Array.<float>

getCameraMatrix() → {mat4}

Return the transformed Camera matrix
Source:
Returns:
mCameraMatrix - scaled and translated Camera matrix
Type
mat4

getViewport() → {Array.<float>}

Returns the Camera viewport
Source:
Returns:
Camera viewport [x,y,width,height]
Type
Array.<float>

getWCCenter() → {vec2}

Returns the center world coordinates for this Camera
Source:
Returns:
The center world coordinates
Type
vec2

getWCCenterInPixelSpace() → {vec3}

Returns the world coordinate center in pixel coordinates
Source:
Returns:
The world coordinate center in pixel coordinates
Type
vec3

getWCHeight() → {float}

Returns the world coordinate height of this Camera
Source:
Returns:
The current height of this Camera
Type
float

getWCWidth() → {float}

Returns the world coordinate width of this Camera
Source:
Returns:
The current width of this Camera
Type
float

isMouseInViewport() → {boolean}

Return whether the mouse is within the viewport
Source:
Returns:
whether the mouse is within the viewport
Type
boolean

mouseWCX() → {float}

Return the mouse x world coordinate position
Source:
Returns:
mouse x world coordinate position
Type
float

mouseWCY() → {float}

Return the mouse y world coordinate position
Source:
Returns:
mouse y world coordinate position
Type
float

panBy(dx, dy)

Pan the Camera by dx,dy
Parameters:
Name Type Description
dx float change in x world coordinate
dy float change in y world coordinate
Source:

panTo(cx, cy)

Pan the Camera to be centered at cx,cy
Parameters:
Name Type Description
cx float x world coordinate
cy float y world coordinate
Source:

panWith(aXform, zone)

Pan this Camera to follow the Transform argument when it moves outside the zone
Parameters:
Name Type Description
aXform Transform Transform to follow
zone float percentage from the center of this Camera
Source:

reShake() → {boolean}

Restart the shaking of this Camera
Source:
Returns:
true if this Camera has a defined CameraShake
Type
boolean

setViewAndCameraMatrix()

Initializes the camera to begin drawing
Source:

setViewport(viewportArray, bound)

Sets the Camera viewport
Parameters:
Name Type Description
viewportArray Array.<float>
bound float
Source:

setWCCenter(xPos, yPos)

Sets the world coordinate center for this Camera
Parameters:
Name Type Description
xPos float the new center x value
yPos float the new center y value
Source:

setWCWidth(width)

Sets the world coordinate width of this Camera
Parameters:
Name Type Description
width integer The new width for this Camera
Source:

shake(deltas, freqs, shakeDuration)

Define a new CameraShake for this Camera
Parameters:
Name Type Description
deltas vec2 the [x,y] magnitudes of the shake
freqs float the frequency of the shaking in revolutions per cycle
shakeDuration float the number of cycles for the shaking
Source:

update()

Update function to be called from GameLoop
Source:

wcDirToPixel(d) → {vec3}

Return a direction in world coordinates converted to pixel space
Parameters:
Name Type Description
d vec3 world coordinate direction
Source:
Returns:
[x,y,z] direction in pixel space
Type
vec3

wcPosToPixel(p) → {vec3}

Return a point in world coordinates converted to pixel space
Parameters:
Name Type Description
p vec3 vec3 position, fake z
Source:
Returns:
[x,y,z] in pixel space
Type
vec3

wcSizeToPixel(s) → {float}

Convert a size in world coordinates to a number pixels
Parameters:
Name Type Description
s float size in world coordinates
Source:
Returns:
the number of pixels
Type
float

zoomBy(zoom)

Change the zoom level of this Camera with respect to the center
Parameters:
Name Type Description
zoom float scaling factor for the width of this Camera
Source:

zoomTowards(pos, zoom)

Change zoom level of this Camera with respect to pos agrument
Parameters:
Name Type Description
pos vec2 Point to scale this Camera with respect to
zoom float sacling factor for the width of this Camera
Source: