forked from littlstar/axis360
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.js
More file actions
39 lines (34 loc) · 1.06 KB
/
camera.js
File metadata and controls
39 lines (34 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Module dependencies
*/
var three = require('three.js')
// default field of view
var DEFAULT_FOV = require('./constants').DEFAULT_FOV;
/**
* Creates an instance of THREE.PerspectiveCamera
* and assigns it to a scope object if not null.
*
* @public
* @name createCamera
* @param {Object} scope - Scope object to assign camera to.
* @param {Boolean} force - Force creation and assignment.
* @return {THREE.PerspectiveCamera}
*/
module.exports = function createCamera (scope, force) {
var height = scope.height();
var width = scope.width();
var ratio = width / height;
var camera = scope.camera;
var state = scope.state;
var vector = null;
var target = null;
var fov = state.opts ? state.opts.fov || DEFAULT_FOV : DEFAULT_FOV;
if (null == scope.camera || true == force) {
vector = new three.Vector3(0, 0, 0);
target = camera && camera.target ? camera.target : vector;
scope.camera = new three.PerspectiveCamera(fov, ratio, 0.01, 1000);
scope.camera.target = target;
scope.camera.rotation.reorder('YXZ');
}
return scope.camera;
};