author | Eugene Ostroukhov <eugeneo@symbian.org> |
Wed, 30 Jun 2010 17:10:46 -0700 | |
changeset 408 | 9985028ffc2c |
parent 407 | c7c8bde493b1 |
child 410 | 084ae6de03b5 |
permissions | -rw-r--r-- |
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
1 |
function RotationSupport(accelerationCallback) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
2 |
this.controls = new RotationControls(accelerationCallback); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
3 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
4 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
5 |
function RotationControls(accelCallback) { |
407
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
6 |
this.angleX = 0; |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
7 |
this.angleY = 0; |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
8 |
this.angleZ = 0; |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
9 |
var control = this; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
10 |
this.accelerationCallback = accelCallback; |
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
11 |
|
407
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
12 |
setupListeners("xaxis", "xleft", "xright", updateAngleX, this.angleX); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
13 |
setupListeners("yaxis", "yleft", "yright", updateAngleY, this.angleY); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
14 |
setupListeners("zaxis", "zleft", "zright", updateAngleZ, this.angleZ); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
15 |
|
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
16 |
window.setTimeout(function() { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
17 |
this.paint(); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
18 |
}, 50); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
19 |
|
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
20 |
function setupListeners(inputId, leftArrow, rightArrow, fn, initial) { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
21 |
var input = $("#" + inputId); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
22 |
input.numeric(); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
23 |
input.val(initial); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
24 |
input.change(function() { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
25 |
adjust(input, fn, 0); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
26 |
}); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
27 |
handleButton(leftArrow, input, fn, -1); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
28 |
handleButton(rightArrow, input, fn, 1); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
29 |
} |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
30 |
|
407
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
31 |
function handleButton(buttonId, input, fn, increment) { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
32 |
var id = false; |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
33 |
var timeout = false; |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
34 |
var stop = function() { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
35 |
if (timeout) { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
36 |
window.clearTimeout(timeout); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
37 |
timeout = false; |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
38 |
adjust(input, fn, increment); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
39 |
} |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
40 |
if (id) { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
41 |
window.clearInterval(id); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
42 |
id = false; |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
43 |
} |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
44 |
}; |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
45 |
|
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
46 |
$("#" + buttonId).mousedown(function() { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
47 |
timeout = window.setTimeout(function() { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
48 |
id = window.setInterval(function() { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
49 |
timeout = false; |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
50 |
adjust(input, fn, increment); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
51 |
}, 10); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
52 |
}, 250); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
53 |
}).mouseup(stop).focusout(stop).blur(stop).mouseleave(stop); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
54 |
} |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
55 |
|
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
56 |
function adjust(input, callback, increment) { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
57 |
var n = parseInt(input.val()); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
58 |
if (isNaN(n)) { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
59 |
n = 0; |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
60 |
} |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
61 |
var val = fix(n + increment); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
62 |
input.val(val); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
63 |
callback(val); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
64 |
} |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
65 |
|
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
66 |
function fix(n) { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
67 |
while (n < -180) { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
68 |
n = n + 360; |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
69 |
} |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
70 |
while (n >= 180) { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
71 |
n = n - 360; |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
72 |
} |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
73 |
return n; |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
74 |
} |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
75 |
|
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
76 |
function updateAngleX(angle) { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
77 |
control.angleX = angle; |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
78 |
control.paint(); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
79 |
} |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
80 |
|
407
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
81 |
function updateAngleY(angle) { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
82 |
control.angleY = angle; |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
83 |
control.paint(); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
84 |
} |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
85 |
|
407
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
86 |
function updateAngleZ(angle) { |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
87 |
control.angleZ = angle; |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
88 |
control.paint(); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
89 |
} |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
90 |
} |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
91 |
|
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
92 |
RotationControls.prototype.paint = function(ignoreListeners) { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
93 |
var width = 50, height = 100, depth = 10; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
94 |
var margin = 5, bottomMargin = 15; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
95 |
|
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
96 |
var canvas = document.getElementById("phoneposition"); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
97 |
var ctx = canvas.getContext("2d"); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
98 |
ctx.clearRect(0, 0, canvas.width, canvas.height); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
99 |
|
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
100 |
var r = 62; |
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
101 |
|
407
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
102 |
var xy = (this.angleX - 180) * Math.PI / 180; |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
103 |
var yz = (this.angleY - 180) * Math.PI / 180; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
104 |
var xz = (180 - this.angleZ) * Math.PI / 180 + Math.PI / 2; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
105 |
|
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
106 |
var back = translateBack(xy, xz, yz); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
107 |
if ((back[0].z + back[2].z) / 2 < 0) { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
108 |
paint(canvas, ctx, back); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
109 |
} else { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
110 |
paint(canvas, ctx, translateFace(xy, xz, yz)); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
111 |
paintScreen(canvas, ctx, translateScreen(xy, xz, yz)); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
112 |
} |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
113 |
|
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
114 |
var dz = 0; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
115 |
if (back[0].z > back[3].z) { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
116 |
var bottom = translateBottom(xy, xz, yz); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
117 |
paint(canvas, ctx, bottom); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
118 |
dz = bottom[1].y - bottom[0].y; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
119 |
} else if (back[0].z != back[3].z) { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
120 |
var top = translateTop(xy, xz, yz); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
121 |
paint(canvas, ctx, top); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
122 |
dz = top[1].y - top[0].y; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
123 |
} |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
124 |
|
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
125 |
if (back[1].z > back[0].z) { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
126 |
paint(canvas, ctx, translateLeft(xy, xz, yz)); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
127 |
} else if (back[1].z != back[0].z) { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
128 |
paint(canvas, ctx, translateRight(xy, xz, yz)); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
129 |
} |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
130 |
if (!ignoreListeners) { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
131 |
var accelX = (back[1].y - back[0].y) / width; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
132 |
var accelY = (back[0].y - back[3].y) / height; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
133 |
var accelZ = dz / depth; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
134 |
notifyAcceleration(accelX, accelY, accelZ); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
135 |
} |
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
136 |
function translateFace(xy, xz, yz) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
137 |
var px = width / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
138 |
var py = height / 2; |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
139 |
var pz = depth / 2; |
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
140 |
var points = [ { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
141 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
142 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
143 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
144 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
145 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
146 |
y : -py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
147 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
148 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
149 |
x : -px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
150 |
y : -py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
151 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
152 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
153 |
x : -px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
154 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
155 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
156 |
} ]; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
157 |
return rotate(points, xy, xz, yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
158 |
} |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
159 |
|
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
160 |
function translateScreen(xy, xz, yz) { |
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
161 |
var px = width / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
162 |
var py = height / 2; |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
163 |
var pz = depth / 2; |
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
164 |
var points = [ { |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
165 |
x : px - margin, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
166 |
y : py - bottomMargin, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
167 |
z : pz |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
168 |
}, { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
169 |
x : px - margin, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
170 |
y : -py + bottomMargin, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
171 |
z : pz |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
172 |
}, { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
173 |
x : -px + margin, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
174 |
y : -py + margin, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
175 |
z : pz |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
176 |
}, { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
177 |
x : -px + margin, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
178 |
y : py - margin, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
179 |
z : pz |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
180 |
} ]; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
181 |
return rotate(points, xy, xz, yz); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
182 |
} |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
183 |
|
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
184 |
function translateBack(xy, xz, yz) { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
185 |
var px = width / 2; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
186 |
var py = height / 2; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
187 |
var pz = -depth / 2; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
188 |
var points = [ { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
189 |
x : px, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
190 |
y : py, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
191 |
z : pz |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
192 |
}, { |
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
193 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
194 |
y : -py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
195 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
196 |
}, { |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
197 |
x : -px, |
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
198 |
y : -py, |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
199 |
z : pz |
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
200 |
}, { |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
201 |
x : -px, |
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
202 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
203 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
204 |
} ]; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
205 |
return rotate(points, xy, xz, yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
206 |
} |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
207 |
|
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
208 |
function translateTop(xy, xz, yz) { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
209 |
var px = width / 2; |
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
210 |
var py = height / 2; |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
211 |
var pz = depth / 2; |
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
212 |
var points = [ { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
213 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
214 |
y : -py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
215 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
216 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
217 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
218 |
y : -py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
219 |
z : -pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
220 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
221 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
222 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
223 |
z : -pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
224 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
225 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
226 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
227 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
228 |
} ]; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
229 |
return rotate(points, xy, xz, yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
230 |
} |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
231 |
|
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
232 |
function translateBottom(xy, xz, yz) { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
233 |
var px = -width / 2; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
234 |
var py = height / 2; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
235 |
var pz = depth / 2; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
236 |
var points = [ { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
237 |
x : px, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
238 |
y : -py, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
239 |
z : pz |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
240 |
}, { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
241 |
x : px, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
242 |
y : -py, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
243 |
z : -pz |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
244 |
}, { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
245 |
x : px, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
246 |
y : py, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
247 |
z : -pz |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
248 |
}, { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
249 |
x : px, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
250 |
y : py, |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
251 |
z : pz |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
252 |
} ]; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
253 |
return rotate(points, xy, xz, yz); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
254 |
} |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
255 |
|
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
256 |
function translateLeft(xy, xz, yz) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
257 |
var px = width / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
258 |
var py = height / 2; |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
259 |
var pz = depth / 2; |
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
260 |
var points = [ { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
261 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
262 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
263 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
264 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
265 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
266 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
267 |
z : -pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
268 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
269 |
x : -px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
270 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
271 |
z : -pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
272 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
273 |
x : -px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
274 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
275 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
276 |
} ]; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
277 |
return rotate(points, xy, xz, yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
278 |
} |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
279 |
|
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
280 |
function translateRight(xy, xz, yz) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
281 |
var px = width / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
282 |
var py = -height / 2; |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
283 |
var pz = depth / 2; |
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
284 |
var points = [ { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
285 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
286 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
287 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
288 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
289 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
290 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
291 |
z : -pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
292 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
293 |
x : -px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
294 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
295 |
z : -pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
296 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
297 |
x : -px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
298 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
299 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
300 |
} ]; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
301 |
return rotate(points, xy, xz, yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
302 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
303 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
304 |
function rotate(points, xy, xz, yz) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
305 |
var res = new Array(); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
306 |
for ( var p in points) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
307 |
var px = points[p].x; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
308 |
var py = points[p].y; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
309 |
var pz = points[p].z; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
310 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
311 |
var rx = Math.sqrt(px * px + py * py); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
312 |
var angXY = Math.atan(px / py) + (px < 0 ? Math.PI : 0); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
313 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
314 |
px = rx * Math.sin(angXY + xy); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
315 |
py = rx * Math.cos(angXY + xy); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
316 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
317 |
var rz = Math.sqrt(px * px + pz * pz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
318 |
var angXZ = (px == 0 ? 0 : Math.atan(pz / px)) |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
319 |
+ (px < 0 ? Math.PI : 0); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
320 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
321 |
px = rz * Math.sin(angXZ + xz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
322 |
pz = rz * Math.cos(angXZ + xz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
323 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
324 |
var ry = Math.sqrt(py * py + pz * pz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
325 |
var angYZ = (pz == 0 ? 0 : Math.atan(py / pz)) |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
326 |
+ (pz < 0 ? Math.PI : 0); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
327 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
328 |
py = ry * Math.sin(angYZ + yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
329 |
pz = ry * Math.cos(angYZ + yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
330 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
331 |
res.push( { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
332 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
333 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
334 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
335 |
}); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
336 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
337 |
return res; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
338 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
339 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
340 |
function paint(canvas, ctx, points) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
341 |
var xcoord = canvas.width / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
342 |
var ycoord = canvas.height / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
343 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
344 |
ctx.fillStyle = "yellow"; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
345 |
ctx.strokeStyle = "black"; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
346 |
ctx.beginPath(); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
347 |
ctx.moveTo(xcoord + points[3].x, ycoord + points[3].y); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
348 |
for (point in points) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
349 |
ctx.lineTo(xcoord + points[point].x, ycoord + points[point].y); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
350 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
351 |
ctx.fill(); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
352 |
ctx.beginPath(); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
353 |
ctx.moveTo(xcoord + points[3].x, ycoord + points[3].y); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
354 |
for (point in points) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
355 |
ctx.lineTo(xcoord + points[point].x, ycoord + points[point].y); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
356 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
357 |
ctx.stroke(); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
358 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
359 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
360 |
function paintScreen(canvas, ctx, screen) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
361 |
var xcoord = canvas.width / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
362 |
var ycoord = canvas.height / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
363 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
364 |
ctx.fillStyle = "grey"; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
365 |
ctx.beginPath(); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
366 |
ctx.moveTo(xcoord + screen[3].x, ycoord + screen[3].y); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
367 |
for (point in screen) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
368 |
ctx.lineTo(xcoord + screen[point].x, ycoord + screen[point].y); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
369 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
370 |
ctx.fill(); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
371 |
} |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
372 |
|
402
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
373 |
function notifyAcceleration(x, y, z) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
374 |
accelerationCallback(x, y, z); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
375 |
} |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
376 |
}; |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
377 |
|
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
378 |
RotationSupport.prototype.setAngles = function(x, y, z) { |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
379 |
this.controls.angleX = x; |
407
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
380 |
this.controls.angleY = z; // It is extremly messy - this UI was developed |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
381 |
// separately from the rest and follows |
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
382 |
this.controls.angleZ = y; // different conventions |
407
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
383 |
|
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
384 |
$("#xaxis").val(this.controls.angleX); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
385 |
$("#yaxis").val(this.controls.angleY); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
386 |
$("#zaxis").val(this.controls.angleZ); |
c7c8bde493b1
Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
403
diff
changeset
|
387 |
|
403
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
388 |
this.controls.paint(true); |
ba20dd5983c7
Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
402
diff
changeset
|
389 |
}; |