summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/mx
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-02-04 14:04:48 -0500
committerJules Laplace <jules@okfoc.us>2015-02-04 14:04:48 -0500
commit24c2c9bd7b776c49e5e90caef00c99bc008ac72a (patch)
tree08d030facc66ecca1c5274a717abd2e49fa4954b /public/assets/javascripts/mx
parent4c7cad2ebfc44244ba845c1574271e48b9f2b740 (diff)
separate orbit test & add mousewheel zoom
Diffstat (limited to 'public/assets/javascripts/mx')
-rw-r--r--public/assets/javascripts/mx/extensions/mx.orbitCamera.js31
1 files changed, 23 insertions, 8 deletions
diff --git a/public/assets/javascripts/mx/extensions/mx.orbitCamera.js b/public/assets/javascripts/mx/extensions/mx.orbitCamera.js
index b3dcc43..b09512e 100644
--- a/public/assets/javascripts/mx/extensions/mx.orbitCamera.js
+++ b/public/assets/javascripts/mx/extensions/mx.orbitCamera.js
@@ -11,10 +11,17 @@ MX.OrbitCamera = function(opt){
sensitivity: 10, // moving 1 pixel is like moving N radians
ease: 10,
})
- var rx, ry, px, py, epsilon = 1e-10, dragging = false
+ var rx, ry, radius, px, py, epsilon = 1e-10, dragging = false
exports.init = function(){
ry = opt.rotationY
rx = opt.rotationX
+ radius = opt.radius
+ exports.wheel = new wheel({
+ el: opt.el,
+ update: function(e, delta){
+ opt.radius = clamp( opt.radius+delta, opt.radiusRange[0], opt.radiusRange[1] )
+ },
+ })
exports.bind()
}
exports.toggle = function(state){
@@ -25,15 +32,17 @@ MX.OrbitCamera = function(opt){
if (bound) return;
bound = true
opt.el.addEventListener("mousedown", down)
- opt.el.addEventListener("mousemove", move)
- opt.el.addEventListener("mouseup", up)
+ window.addEventListener("mousemove", move)
+ window.addEventListener("mouseup", up)
+ exports.wheel.unlock()
}
exports.unbind = function(){
if (! bound) return;
bound = false
opt.el.removeEventListener("mousedown", down)
- opt.el.removeEventListener("mousemove", move)
- opt.el.removeEventListener("mouseup", up)
+ window.removeEventListener("mousemove", move)
+ window.removeEventListener("mouseup", up)
+ exports.wheel.lock()
}
function down (e) {
px = e.pageX
@@ -70,9 +79,15 @@ MX.OrbitCamera = function(opt){
else {
rx = opt.rotationX
}
- opt.camera.x = opt.center.x + opt.radius * sin(rx) * cos(ry)
- opt.camera.z = opt.center.y + opt.radius * sin(rx) * sin(ry)
- opt.camera.y = opt.center.z + opt.radius * cos(rx)
+ if (abs(radius - opt.radius) > epsilon) {
+ radius = avg(radius, opt.radius, opt.ease)
+ }
+ else {
+ radius = opt.radius
+ }
+ opt.camera.x = opt.center.x + radius * sin(rx) * cos(ry)
+ opt.camera.z = opt.center.y + radius * sin(rx) * sin(ry)
+ opt.camera.y = opt.center.z + radius * cos(rx)
opt.camera.rotationX = PI/2 - rx
opt.camera.rotationY = ry + PI/2
}