summaryrefslogtreecommitdiff
path: root/site/public/assets/javascripts/mx/extensions/mx.unclampedOrbitCamera.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-09-02 13:31:36 -0400
committerJules Laplace <jules@okfoc.us>2016-09-02 13:31:36 -0400
commitde8b6ffa3c686256030df04a6dd56025fe6de8ac (patch)
tree6e0f954f151060ccba3441e03409557f674e54c3 /site/public/assets/javascripts/mx/extensions/mx.unclampedOrbitCamera.js
parent98bb711e716b4e9770aa7299b43f630fb7262acc (diff)
remove 2h site and bump to 0.1.40v0.1.40
Diffstat (limited to 'site/public/assets/javascripts/mx/extensions/mx.unclampedOrbitCamera.js')
-rw-r--r--site/public/assets/javascripts/mx/extensions/mx.unclampedOrbitCamera.js130
1 files changed, 0 insertions, 130 deletions
diff --git a/site/public/assets/javascripts/mx/extensions/mx.unclampedOrbitCamera.js b/site/public/assets/javascripts/mx/extensions/mx.unclampedOrbitCamera.js
deleted file mode 100644
index 28b1aac..0000000
--- a/site/public/assets/javascripts/mx/extensions/mx.unclampedOrbitCamera.js
+++ /dev/null
@@ -1,130 +0,0 @@
-MX.OrbitCamera = function(opt){
- var exports = {}, bound = false
- exports.opt = opt = defaults(opt, {
- el: window, // object to bind events on
- camera: scene.camera, // camera object we'll be moving
- radius: 100,
- radiusRange: [ 10, 1000 ],
- rotationX: PI/2,
- rotationY: 0,
- center: { x: 0, y: 0, z: 0 },
- sensitivity: 10, // moving 1 pixel is like moving N radians
- wheelSensitivity: 10,
- ease: 10,
- wheelEase: 10,
- })
- var rx, ry, radius, px, py, epsilon = 1e-10
- exports.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.wheelSensitivity, opt.radiusRange[0], opt.radiusRange[1] )
- },
- })
- exports.bind()
- }
- exports.toggle = function(state){
- if (state) exports.bind()
- else exports.unbind()
- }
- exports.bind = function(){
- if (bound) return;
- bound = true
- opt.el.addEventListener("mousedown", down)
- window.addEventListener("mousemove", move)
- window.addEventListener("mouseup", up)
- opt.el.addEventListener("touchstart", touch(down))
- window.addEventListener("touchmove", touch(move))
- window.addEventListener("touchend", touch(up))
- exports.wheel.unlock()
- }
- exports.unbind = function(){
- if (! bound) return;
- bound = false
- opt.el.removeEventListener("mousedown", down)
- window.removeEventListener("mousemove", move)
- window.removeEventListener("mouseup", up)
- exports.wheel.lock()
- }
- function cancelable (fn) {
- return function(e){
- e.preventDefault()
- fn(e)
- }
- }
- function touch (fn){
- return function(e){
- fn(e.touches[0])
- }
- }
- function down (e) {
- px = e.pageX
- py = e.pageY
- exports.dragging = true
- }
- function move (e) {
- if (! exports.dragging) return
- exports.delta(px- e.pageX, py - e.pageY)
- px = e.pageX
- py = e.pageY
- }
- function up (e) {
- exports.dragging = false
- }
- exports.delta = function(x,y){
- opt.rotationY += x/window.innerWidth * opt.sensitivity
- opt.rotationX = opt.rotationX + y/window.innerHeight * opt.sensitivity
- }
- exports.move = function(y, x){
- opt.rotationY = y
- if (typeof x == "number") { opt.rotationX = x }
- }
- exports.zoom = function(r){
- opt.radius = r
- }
- exports.setZoom = function(r){
- radius = opt.radius = r
- }
- exports.zoomPercent = function(n){
- opt.radius = lerp(n, opt.radiusRange[0], opt.radiusRange[1])
- }
- exports.zoomDelta = function(r){
- opt.radius += r
- }
- exports.pause = function(){
- var sy = sign(opt.rotationY-ry)
- var sx = sign(opt.rotationX-rx)
- opt.rotationY = ry + sy * 0.1
- opt.rotationX = rx + sx * 0.1
- }
- exports.update = function(){
- if (abs(ry - opt.rotationY) > epsilon) {
- ry = avg(ry, opt.rotationY, opt.ease)
- }
- else {
- ry = opt.rotationY
- }
- if (abs(rx - opt.rotationX) > epsilon) {
- rx = avg(rx, opt.rotationX, opt.ease)
- }
- else {
- rx = opt.rotationX
- }
- if (abs(radius - opt.radius) > epsilon) {
- radius = avg(radius, opt.radius, opt.wheelEase)
- }
- 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
- }
- return exports
-}