summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-08-05 17:56:38 -0400
committerJules Laplace <jules@okfoc.us>2014-08-05 17:56:38 -0400
commitbac4d6a8c8566814e851452bedf5fa7ce596d54d (patch)
tree665ed0bb05c84a28cbae034d7dc3279577ab24e5
parent43af2bebd1de70f0e2f5627815812dbfd01a5c9a (diff)
very basic mobile uimobile
-rw-r--r--public/assets/javascripts/mx/extensions/mx.movementsMobile.js92
-rw-r--r--public/assets/javascripts/util.js2
2 files changed, 81 insertions, 13 deletions
diff --git a/public/assets/javascripts/mx/extensions/mx.movementsMobile.js b/public/assets/javascripts/mx/extensions/mx.movementsMobile.js
index 7e1cc92..994c8d7 100644
--- a/public/assets/javascripts/mx/extensions/mx.movementsMobile.js
+++ b/public/assets/javascripts/mx/extensions/mx.movementsMobile.js
@@ -3,43 +3,83 @@ MX.MobileMovements = function (cam) {
var touching = true,
moving = false,
+ startTime = null,
v = 12,
vr = Math.PI * 0.012,
- jumpV = 23,
- vx = vy = vz = 0,
- creepFactor = 0.3
+ vx = vy = vz = 0;
- var DEFAULT_SCALE = 1.0, scale = DEFAULT_SCALE
-
- var pos = { x: 0, y: 0, z: 0, rotationX: 0, rotationY: 0 }
+ var directionLocked = false,
+ directionLockThreshold = 5
- var mouse = new Rect( 0,0,0,0 )
+ var pos = { x: 0, y: viewHeight, z: 0, rotationX: 0, rotationY: 0 }
+ var pointX, pointY, deltaX, deltaY, distX = 0, distY = 0, absDistX = 0, absDistY = 0, startTime
+
return {
init: function () {
document.addEventListener("touchstart", function(e){
if (e.touches.length == 1) {
touching = true
- mouse.x.a = mouse.x.b = event.touches[ 0 ].pageX
- mouse.y.a = mouse.y.b = event.touches[ 0 ].pageY
+
+ startTime = Date.now()
+
+ var point = event.touches[0]
+ pointX = point.pageX
+ pointY = point.pageY
+ distX = distY = 0
+ pos.x = cam.x
+ pos.z = cam.z
+ pos.rotationY = cam.rotationY
}
})
document.addEventListener("touchmove", function(e){
+ e.preventDefault()
if (e.touches.length == 1) {
+
+ var timestamp = Date.now()
+ var point = event.touches[0]
+ deltaX = point.pageX - pointX
+ deltaY = point.pageY - pointY
+ pointX = point.pageX
+ pointY = point.pageY
+
+ distX += deltaX
+ distY += deltaY
+ absDistX = abs(distX)
+ absDistY = abs(distY)
}
})
document.addEventListener("touchend", function(e){
+ e.preventDefault()
if (e.touches.length == 0) {
- touching = false
- mouse.zero()
+ touching = directionLocked = false
+ var timestamp = Date.now()
+ var duration = startTime - timestamp
+ if (duration < 300) {
+ }
}
})
},
update: function () {
- if (moving) {
+ if (distX || distY) {
+ var oldDistY = absDistY, oldDistX = absDistX
+ absDistY = avg(absDistY, 0, 5)
+ var dy = (oldDistY - absDistY) * sign(distY) * 2
+
+ absDistX = avg(absDistX, 0, 5)
+ var dx = (oldDistX - absDistX) * sign(distX) * 2
+
+ distY = sign(distY) * absDistY
+ distX = sign(distX) * absDistX
+
+ pos.x -= dy * Math.cos(pos.rotationY + Math.PI / 2)
+ pos.z -= dy * Math.sin(pos.rotationY + Math.PI / 2)
+ pos.rotationY += dx / (window.innerWidth) * Math.PI / 2
+ cam.rotationY = pos.rotationY
+
app.tube("move", pos)
}
},
@@ -54,3 +94,31 @@ MX.MobileMovements = function (cam) {
}
}
+
+
+// function momentum (current, start, time, lowerMargin, wrapperSize, deceleration) {
+// var distance = current - start,
+// speed = Math.abs(distance) / time,
+// destination,
+// duration;
+//
+// deceleration = deceleration === undefined ? 0.0006 : deceleration;
+//
+// destination = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 );
+// duration = speed / deceleration;
+//
+// if ( destination < lowerMargin ) {
+// destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin;
+// distance = Math.abs(destination - current);
+// duration = distance / speed;
+// } else if ( destination > 0 ) {
+// destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0;
+// distance = Math.abs(current) + destination;
+// duration = distance / speed;
+// }
+//
+// return {
+// destination: Math.round(destination),
+// duration: duration
+// };
+// }
diff --git a/public/assets/javascripts/util.js b/public/assets/javascripts/util.js
index 58dcc3a..b92dcf3 100644
--- a/public/assets/javascripts/util.js
+++ b/public/assets/javascripts/util.js
@@ -31,7 +31,7 @@ function quantize(n,a){ return round(n / a) * a }
function max(a,b){ return Math.max(a,b) }
function min(a,b){ return Math.min(a,b) }
function abs(n){ return Math.abs(n) }
-function sign(n){ return Math.abs(n)/n }
+function sign(n){ return n ? Math.abs(n)/n : 0 }
function pow(n,b) { return Math.pow(n,b) }
function exp(n) { return Math.exp(n) }
function log(n){ return Math.log(n) }