-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
70 lines (55 loc) · 1.46 KB
/
index.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict'
/**
* Module dependencies.
*/
var createBaseCamera = require('perspective-camera/lib/camera-base')
var coalesce = require('defined')
var lookAt = require('gl-mat4/lookAt')
var ortho = require('gl-mat4/ortho')
var add = require('gl-vec3/add')
var kDefaultNearValue = 100
var kDefaultFarValue = 1
/**
* Creates an orthographic camera interface.
*
* @public opts
* @param {?Object}
*/
module.exports = createOrthographicCamera
function createOrthographicCamera(opts) {
if (!opts || 'object' != typeof opts) {
opts = {}
}
var center = [0, 0, 0]
var camera = createBaseCamera(opts)
var updateBase = camera.update
camera.near = coalesce(opts.near, kDefaultNearValue)
camera.far = coalesce(opts.far, kDefaultFarValue)
// intial update
update()
camera.update = update
return camera
function update() {
var projection = camera.projection
var direction = camera.direction
var position = camera.position
var viewport = camera.viewport
var view = camera.view
var near = camera.near
var far = camera.far
var up = camera.up
var left = viewport[0]
var bottom = viewport[1]
var right = viewport[2]
var top = viewport[3]
// update projection
ortho(projection, left, right, bottom, top, near, far)
// update camera center position
add(center, position, direction)
// update view
lookAt(view, position, center, up)
// update base
updateBase()
return camera
}
}