summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/mx/extensions/mx.movementsMobile.js
blob: 7e1cc924837d1fcdc769b6cf676b9487ef673454 (plain)
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
MX.MobileMovements = function (cam) {

	var touching = true,
			moving = false,
	    v = 12,
			vr = Math.PI * 0.012,
			jumpV = 23,
			vx = vy = vz = 0,
			creepFactor = 0.3

	var DEFAULT_SCALE = 1.0, scale = DEFAULT_SCALE
	
	var pos = { x: 0, y: 0, z: 0, rotationX: 0, rotationY: 0 }

	var mouse = new Rect( 0,0,0,0 )

	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
				}
			})
			document.addEventListener("touchmove", function(e){
				if (e.touches.length == 1) {
					
				}
			})
			document.addEventListener("touchend", function(e){
				if (e.touches.length == 0) {
					touching = false
					mouse.zero()
				}
			})
		},
		
		update: function () {
			if (moving) {
				app.tube("move", pos)
			}
		},
		
		lock: function(){ locked = true },
		unlock: function(){ locked = false },
		scale: function(n){ if (n) scale = n; return scale },
		resetScale: function(n){ scale = DEFAULT_SCALE },
		gravity: function(g){ return typeof g == "boolean" ? gravity = g : gravity },
		velocity: function(n){ v = clamp(n, 1, 50) },
		jumpVelocity: function(n){ jumpV = clamp(n, 1, 50) },
	}

}