1.0.4 • Published 9 years ago

hexr-camera v1.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

Hexr Camera

An incomplete but handy Camera Operator module for games using Hexr or THREE.JS.

// The cameraman has her own 
var camerawoman = require('hexr-camera')(fov, aspect, near, far);

// rendering with it..
var camera = camerawoman.camera;
renderer.render(scene, camera);

## Updating the Camera

// every tick...
camerawoman.update(worldTime.now, worldTime.delta);

The trick with Hexr Camera is that you don't move the camera yourself. You get the camera operator to do it instead.

Resetting the Camera / Setting Position

To reset the camera and move it directly to a particular position

~~js // setting the position manually automatically kills any previous instructions // to the camerawoman. camerawoman.setPosition(new THREE.Vector3(0,0,50)); camerawoman.lookAt(new THREE.Vector3(0,0,0));

## Following a character: Truck and Pedestal

In a 2D game you can get the camerawoman to 'truck' and 'pedestal' the camera so that it keeps a track of a particular vector. In effect, the camera scrolls left and right and up and down, but not in and out. 

~~~js
// target 2 units above the player's position and close 10% of the distance each frame.
camerawoman.follow( player.mesh.position, new THREE.Vector3(0,2,0), 0.1);

Trucking

You can truck the camera to the left and right (keeping facing straight forward) over a duration

camerawoman.truckTo( x, duration );

## Pedestal

You can pedestal the camera up and down (again keeping facing straight forward) over a duration

camerawoman.pedestalTo (y, duration);

Dolly

You can get the camera to dolly in and out of the screen over a duration

camerawoman.dollyTo(z, duration);

Shake

You can get the camera to shake

camerawoman.shake(distance, duration);

Pivot

The camera pivots around a radius around the lookAt point

camerawoman.pivot(speed, radius, lookAtVector)

setExtents

Clamps the camera's possible x and y movement.

var extents = {
	left : -4,
	right : 4,
	top: 2,
	bottom : -2
}
var minZoom = 40;
var maxZoom = 4;
camerawoman.setExtents(extents, zoomOut, zoomIn);
1.0.4

9 years ago

1.0.2

9 years ago

1.0.0

9 years ago