Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
camera-2d-simple
Advanced tools
Simple camera built on top of gl-matrix for 2D scenes. Heavily inspired by Mikola's Orbit Camera.
Also see:
npm install camera-2d-simple
import createCamera from "camera-2d-simple";
# createCamera(target = [0,0], distance = 1, rotation = 0, viewCenter = [0,0], scaleBounds = [0,Infinity])
Creates a 2d camera looking at target
from a certain distance
.
target
is the 2d vector the camera is looking at.distance
is the distance between the target and the camera.rotation
is angle in radiance around the z axis with respect to the viewport center.viewCenter
is the center point of the canvas w.r.t the view coordinates. When operating in normalized-device coordinates this must be [0,0]
but the center can differ when operating in pixel coordinates.scaleBounds
are the min and max allowed scalings.Returns A new 2d camera object
# camera.view
The current view matrix (mat4
) of the camera.
# camera.viewCenter
The current view center.
# camera.translation
The camera translation needed to look at the target
.
# camera.target
The camera center in normalized device coordinates. This is a shorthand for inverseOf(camera.view
) * [0,0,0,1]
.
# camera.scaling
The camera scaling. Larger scaling means the camera is closer to the target. This is the inverse of distance
, i.e., 1 / distance
.
# camera.scaleBounds
The scale limits.
# camera.distance
Distance of the camera to the target. This is the inverse of scaling
, i.e., 1 / scaling
.
# camera.rotation
Rotation in radians around the z axis.
# camera.lookAt(target = [0,0], distance = 1, rotation = 0)
Move the camera center to target
given the distance
and rotation
.
# camera.translate([x,y])
Moves the center of the camera by x
and y
pixel.
# camera.pan([x,y])
Same as camera.translate()
# camera.scale(delta, scaleCenter)
Zooms in or out by delta
with respect to scaleCenter
in [x,y]
. The new distance will be distance * delta
.
# camera.zoom(delta, scaleCenter)
Same as camera.scale()
# camera.rotate(angle)
Rotate the camera by angle
(in radians) around the z axis with respect to the viewport center.
# camera.setScaleBounds(bounds)
Set the scaling limits. Expects a tuple of the min and max allowed scale factors.
# camera.setView(view)
Set the camera to the view
matrix (mat4
).
# camera.setViewCenter(viewCenter)
Set viewCenter
w.r.t. the canvas.
# camera.reset()
Reset the camera to the initial target
, distance
, and rotation
.
v2.2.1
camera.rotation
FAQs
2D camera for WebGL
The npm package camera-2d-simple receives a total of 705 weekly downloads. As such, camera-2d-simple popularity was classified as not popular.
We found that camera-2d-simple demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.