Camera
Camera
This code is for the camera object which is a representation of the screen while using OpenCircuits.
Constructor
public Camera
new Camera(width, height, pos, zoom)
This constructor creates new Camera object which is the field of view (the screen) and initializes all the variables. It sets dirty to true which means that.
Parameters
width: number
– The width of the camera (screen).height: number
– The height of the camera (screen).pos: Vector
– The starting position in the camera to 0,0 (vector).zoom: number
– This initialzed zoom to 1.
Properties
No publicly accessible properties on Camera
private width: number
Description needed
private height: number
Description needed
private dirty: false | true
Description needed
private margin: Margin
Description needed
Methods
private updateMatrix
updateMatrix() => void
If dirty is true then it updates and recalculates the matrix to the new position, height, and width.
dirty
represents whether the screen has been changed/moved or not.
public resize
resize(width, height) => void
This function resizes the height and width and sets dirty to true when the screen is moved.
Parameters
width: number
– The new width of screen.height: number
– The new height of screen.
public setProp
setProp(key, val) => void
Description needed
Parameters
key: string
– Description neededval: any
– Description needed
public setPos
setPos(pos) => void
This sets the position of the screen (vector coordinates) and sets dirty to true.
Parameters
-
pos: Vector
– The new position vector.
public setZoom
setZoom(zoom) => void
The sets the zoom variable to the new zoom number.
Parameters
-
zoom: number
– The new zoom number (how much it's being zoomed in).
public translate
translate(dv) => void
This moves the position of the screen by dv (Ex: pos=(10,10) dv=(5,0) then pos will = (15,10) after call).
Parameters
-
dv: Vector
– A vector that represents by how much the position will be moved.
public zoomTo
zoomTo(c, z) => void
Zooms to a certain position on the screen by a certain amount z.
Parameters
c: Vector
– The position it's zooming to.z: number
– The amount it is zooming.
public zoomBy
zoomBy(s) => void
Zooms in or out at the current position.
Parameters
-
s: number
– The amount to zoom by.
public cull
cull(transform) => false | true
This function returns true or false if this.transform contains the transform passed through.
Parameters
-
transform: Transform
– Comparing this with this.transform.
Returns
-
false | true
– True or false.
public getCenter
getCenter() => Vector
This returns the coordinates of the center of the screen wherever it is.
Returns
-
Vector
– Return vector with coordinates.
public getSize
getSize() => Vector
Returns the size of the screen. This is the bottom-right corner.
Returns
-
Vector
– Vector that contains the size of the screen.
public getZoom
getZoom() => number
Return how much the screen is zoomed in/out by.
Returns
-
number
– The zoom, which is data type Number.
public getTransform
getTransform() => Transform
This returns a copy of the transform of camera and updates the matrix.
Returns
-
Transform
– Copy of this.transform.
public getMatrix
getMatrix() => Matrix2x3
Returns copy of current matrix and updates the matrix as needed.
Returns
-
Matrix2x3
– Returns copy of mat.
public getInverseMatrix
getInverseMatrix() => Matrix2x3
Returns a copy of the inverse of the matrix and updates the matrix.
Returns
-
Matrix2x3
– Returned copy of inv.
public getScreenPos
getScreenPos(v) => Vector
Returns the current screen position with formula using the vector v and getCenter.
Parameters
-
v: Vector
– The vector multiplied to inv.
Returns
-
Vector
– A vector of the screen position.
public getWorldPos
getWorldPos(v) => Vector
Returns the global position not the local screens position.
Parameters
-
v: Vector
– The current position.
Returns
-
Vector
– The global position.
public getMargin
getMargin() => Margin
Returns a set of margins that adjusts the view of the camera.
Returns
-
Margin
– Margin values for the camera.
public setMargin
setMargin(newMargin) => void
This sets the margin for the camera.
Parameters
-
newMargin: Partial
– The new margins for the camera.
Static Methods
No static methods for Camera