3.0.1 • Published 8 years ago

camera-spin v3.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

camera-spin

stable

Mouse/touch-draggable first-person camera. Useful for out-of-the-box Google Street View-style camera controls.

Usage

NPM

camera = Camera(element, origin, up)

Creates a new camera instance. All arguments are optional:

  • element is the DOM element to attach to and make interactive.
  • origin is a [x, y, z] array specifying the position of the camera. Defaults to [0, 0, 0].
  • up is a [x, y, z] array specifying the "up" vector to use. Defaults to [0, 1, 0].

view = camera.tick()

This function should be run once per frame in your requestAnimationFrame loop:

const raf = require('raf')

render()
function render () {
  camera.tick()
  raf(render)
}

It's responsible for updating the camera parameters in response to user input. Returns view, your 4x4 Float32Array view matrix to give your shaders.

view = camera.view()

Calculates and returns the 4x4 view matrix provided by camera.tick() without performing any of the user input handling.

camera.direction

A normalized [x, y, z] array specifying the direction the camera is currently looking as a vector. You can use this, for example, to move the camera forward in the direction it's looking:

camera.origin[0] += camera.direction[0] * distance
camera.origin[1] += camera.direction[1] * distance
camera.origin[2] += camera.direction[2] * distance

The value is read-only: it'll be updated each time you call camera.tick().

camera.rotation

An [x, y] array containing the horizontal and vertical rotation in radians. You can use this to manually point the camera in a specific direction.

camera.lookSpeed

Change this value to set the speed at which the camera moves around, i.e. its mouse sensitivity. Should be between 0 and 1. Defaults to 0.003.

camera.dragRate

Change this value to set the rate of interpolation between rotation values. Should be between 0 and 1 — lower values will result in smoother motion, higher values will increase responsiveness. Defaults to 0.2.

camera.dispose()

Tear everything down once you're no longer using the camera. Required if you need to clean up after yourself :)

License

MIT, see LICENSE.md for details.

3.0.1

8 years ago

3.0.0

8 years ago

2.1.0

8 years ago

2.0.0

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago