Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

camera-2d-simple

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

camera-2d-simple

2D camera for WebGL

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
896
increased by19.15%
Maintainers
1
Weekly downloads
 
Created
Source

2D Camera

npm version stability experimental build status gzipped size code style prettier demo

Simple camera built on top of gl-matrix for 2D scenes. Heavily inspired by Mikola's Orbit Camera.

Also see:

Install

npm install camera-2d-simple

API

import createCamera from "camera-2d-simple";
const camera = createCamera(target = [0,0], distance = 1, rotation = 0)

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.

Returns A new 2d camera object

camera.lookAt(target = [0,0], distance = 1, rotation = 0)

Move the camera to look at .

camera.pan([x,y]) or camera.translate([x,y])

Moves the center of the camera by x and y pixel.

camera.zoom(delta, scaleCenter) or 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.rotate(angle)

Rotate the camera by angle (in radians) around the z axis with respect to the viewport center.

camera.set(view)

Set the camera to the view matrix (mat4).

camera.reset()

Reset the camera to the initial target, distance, and rotation.

camera.view

The current view matrix (mat4) of the camera.

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.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.

Keywords

FAQs

Package last updated on 03 Feb 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc