-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.js
35 lines (31 loc) · 1.06 KB
/
camera.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
"use strict"
var createOrbitCamera = require("orbit-camera")
function attachCamera(shell) {
var camera = createOrbitCamera()
shell.on("tick", function() {
var ctrl = shell.down("control")
var alt = shell.down("shift")
var left = shell.down("mouse-left")
var right = shell.down("mouse-right")
var middle = shell.down("mouse-middle")
if(left && !ctrl && !alt) {
camera.rotate([shell.mouseX/shell.width-0.5, shell.mouseY/shell.height-0.5],
[shell.prevMouseX/shell.width-0.5, shell.prevMouseY/shell.height-0.5])
}
if(right || (left && ctrl && !alt)) {
camera.pan([(shell.mouseX - shell.prevMouseX)/shell.width,
(shell.mouseY - shell.prevMouseY)/shell.height])
}
if(shell.scroll[1]) {
camera.distance *= Math.exp(shell.scroll[1] / shell.height)
}
if(middle || (left && !ctrl && alt)) {
var d = shell.mouseY - shell.prevMouseY
if(d) {
camera.distance *= Math.exp(d / shell.height)
}
}
})
return camera
}
module.exports = attachCamera