author | Eugene Ostroukhov <eugeneo@symbian.org> |
Tue, 29 Jun 2010 13:44:16 -0700 | |
changeset 402 | f943a50b6689 |
child 403 | ba20dd5983c7 |
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) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
6 |
var width = 50, height = 100, depth = 10; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
7 |
var margin = 5, bottomMargin = 15; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
8 |
var angleX = 180; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
9 |
var angleY = 180; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
10 |
var angleZ = 180; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
11 |
var accelerationCallback = accelCallback; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
12 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
13 |
$("#sliderX").slider( { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
14 |
slide : updateAngleX, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
15 |
animate : true, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
16 |
max : 360, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
17 |
min : 0, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
18 |
value : angleX |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
19 |
}); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
20 |
$("#sliderY").slider( { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
21 |
slide : updateAngleY, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
22 |
animate : true, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
23 |
max : 360, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
24 |
min : 0, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
25 |
value : angleY |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
26 |
}); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
27 |
$("#sliderZ").slider( { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
28 |
slide : updateAngleZ, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
29 |
animate : true, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
30 |
max : 360, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
31 |
min : 0, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
32 |
value : angleZ |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
33 |
}); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
34 |
renderUI(); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
35 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
36 |
function translateFace(xy, xz, yz) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
37 |
var px = width / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
38 |
var py = height / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
39 |
var pz = depth/2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
40 |
var points = [ { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
41 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
42 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
43 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
44 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
45 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
46 |
y : -py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
47 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
48 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
49 |
x : -px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
50 |
y : -py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
51 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
52 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
53 |
x : -px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
54 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
55 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
56 |
} ]; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
57 |
return rotate(points, xy, xz, yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
58 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
59 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
60 |
function translateScreen(xy, xz, yz) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
61 |
var px = width / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
62 |
var py = height / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
63 |
var pz = depth/2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
64 |
var points = [ { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
65 |
x : px - margin, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
66 |
y : py - bottomMargin, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
67 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
68 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
69 |
x : px - margin, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
70 |
y : -py + bottomMargin, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
71 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
72 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
73 |
x : -px + margin, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
74 |
y : -py + margin, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
75 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
76 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
77 |
x : -px + margin, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
78 |
y : py - margin, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
79 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
80 |
} ]; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
81 |
return rotate(points, xy, xz, yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
82 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
83 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
84 |
function translateBack(xy, xz, yz) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
85 |
var px = width / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
86 |
var py = height / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
87 |
var pz = -depth/2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
88 |
var points = [ { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
89 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
90 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
91 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
92 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
93 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
94 |
y : -py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
95 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
96 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
97 |
x : -px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
98 |
y : -py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
99 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
100 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
101 |
x : -px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
102 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
103 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
104 |
} ]; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
105 |
return rotate(points, xy, xz, yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
106 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
107 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
108 |
function translateTop(xy, xz, yz) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
109 |
var px = width / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
110 |
var py = height / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
111 |
var pz = depth/2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
112 |
var points = [ { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
113 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
114 |
y : -py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
115 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
116 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
117 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
118 |
y : -py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
119 |
z : -pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
120 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
121 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
122 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
123 |
z : -pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
124 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
125 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
126 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
127 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
128 |
} ]; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
129 |
return rotate(points, xy, xz, yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
130 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
131 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
132 |
function translateBottom(xy, xz, yz) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
133 |
var px = -width / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
134 |
var py = height / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
135 |
var pz = depth/2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
136 |
var points = [ { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
137 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
138 |
y : -py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
139 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
140 |
}, { |
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 |
return rotate(points, xy, xz, yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
154 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
155 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
156 |
function translateLeft(xy, xz, yz) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
157 |
var px = width / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
158 |
var py = height / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
159 |
var pz = depth/2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
160 |
var points = [ { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
161 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
162 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
163 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
164 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
165 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
166 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
167 |
z : -pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
168 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
169 |
x : -px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
170 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
171 |
z : -pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
172 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
173 |
x : -px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
174 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
175 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
176 |
} ]; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
177 |
return rotate(points, xy, xz, yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
178 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
179 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
180 |
function translateRight(xy, xz, yz) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
181 |
var px = width / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
182 |
var py = -height / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
183 |
var pz = depth/2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
184 |
var points = [ { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
185 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
186 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
187 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
188 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
189 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
190 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
191 |
z : -pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
192 |
}, { |
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 |
}, { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
197 |
x : -px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
198 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
199 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
200 |
} ]; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
201 |
return rotate(points, xy, xz, yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
202 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
203 |
|
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 |
function renderUI() { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
206 |
var canvas = document.getElementById("phoneposition"); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
207 |
var ctx = canvas.getContext("2d"); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
208 |
ctx.clearRect(0, 0, canvas.width, canvas.height); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
209 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
210 |
var r = 62; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
211 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
212 |
var xy = (180 - angleX) * Math.PI / 180; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
213 |
var yz = (angleY - 180) * Math.PI / 180; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
214 |
var xz = (180 - angleZ) * Math.PI / 180 + Math.PI / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
215 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
216 |
var back = translateBack(xy, xz, yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
217 |
if ((back[0].z + back[2].z)/2 < 0) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
218 |
paint(canvas, ctx, back); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
219 |
} else { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
220 |
paint(canvas, ctx, translateFace(xy, xz, yz)); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
221 |
paintScreen(canvas, ctx, translateScreen(xy, xz, yz)); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
222 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
223 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
224 |
var dz = 0; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
225 |
if (back[0].z > back[3].z) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
226 |
var bottom = translateBottom(xy, xz, yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
227 |
paint(canvas, ctx, bottom); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
228 |
dz = bottom[1].y - bottom[0].y; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
229 |
} else if (back[0].z != back[3].z) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
230 |
var top = translateTop(xy, xz, yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
231 |
paint(canvas, ctx, top); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
232 |
dz = top[1].y - top[0].y; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
233 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
234 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
235 |
if (back[1].z > back[0].z) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
236 |
paint(canvas, ctx, translateLeft(xy, xz, yz)); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
237 |
} else if (back[1].z != back[0].z) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
238 |
paint(canvas, ctx, translateRight(xy, xz, yz)); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
239 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
240 |
var accelX = (back[1].y - back[0].y) / width; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
241 |
var accelY = (back[0].y - back[3].y) / height; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
242 |
var accelZ = dz / depth; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
243 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
244 |
notifyAcceleration(accelX, accelY, accelZ); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
245 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
246 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
247 |
function rotate(points, xy, xz, yz) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
248 |
var res = new Array(); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
249 |
for ( var p in points) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
250 |
var px = points[p].x; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
251 |
var py = points[p].y; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
252 |
var pz = points[p].z; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
253 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
254 |
var rx = Math.sqrt(px * px + py * py); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
255 |
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
|
256 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
257 |
px = rx * Math.sin(angXY + xy); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
258 |
py = rx * Math.cos(angXY + xy); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
259 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
260 |
var rz = Math.sqrt(px * px + pz * pz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
261 |
var angXZ = (px == 0 ? 0 : Math.atan(pz / px)) |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
262 |
+ (px < 0 ? Math.PI : 0); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
263 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
264 |
px = rz * Math.sin(angXZ + xz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
265 |
pz = rz * Math.cos(angXZ + xz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
266 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
267 |
var ry = Math.sqrt(py * py + pz * pz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
268 |
var angYZ = (pz == 0 ? 0 : Math.atan(py / pz)) |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
269 |
+ (pz < 0 ? Math.PI : 0); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
270 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
271 |
py = ry * Math.sin(angYZ + yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
272 |
pz = ry * Math.cos(angYZ + yz); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
273 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
274 |
res.push( { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
275 |
x : px, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
276 |
y : py, |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
277 |
z : pz |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
278 |
}); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
279 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
280 |
return res; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
281 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
282 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
283 |
function updateAngleX(event, ui) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
284 |
angleX = ui.value; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
285 |
renderUI(); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
286 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
287 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
288 |
function updateAngleY(event, ui) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
289 |
angleY = ui.value; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
290 |
renderUI(); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
291 |
} |
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 |
function updateAngleZ(event, ui) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
294 |
angleZ = ui.value; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
295 |
renderUI(); |
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 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
298 |
function paint(canvas, ctx, points) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
299 |
var xcoord = canvas.width / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
300 |
var ycoord = canvas.height / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
301 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
302 |
ctx.fillStyle = "yellow"; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
303 |
ctx.strokeStyle = "black"; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
304 |
ctx.beginPath(); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
305 |
ctx.moveTo(xcoord + points[3].x, ycoord + points[3].y); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
306 |
for (point in points) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
307 |
ctx.lineTo(xcoord + points[point].x, ycoord + points[point].y); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
308 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
309 |
ctx.fill(); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
310 |
ctx.beginPath(); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
311 |
ctx.moveTo(xcoord + points[3].x, ycoord + points[3].y); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
312 |
for (point in points) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
313 |
ctx.lineTo(xcoord + points[point].x, ycoord + points[point].y); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
314 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
315 |
ctx.stroke(); |
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 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
318 |
function paintScreen(canvas, ctx, screen) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
319 |
var xcoord = canvas.width / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
320 |
var ycoord = canvas.height / 2; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
321 |
|
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
322 |
ctx.fillStyle = "grey"; |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
323 |
ctx.beginPath(); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
324 |
ctx.moveTo(xcoord + screen[3].x, ycoord + screen[3].y); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
325 |
for (point in screen) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
326 |
ctx.lineTo(xcoord + screen[point].x, ycoord + screen[point].y); |
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 |
ctx.fill(); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
329 |
} |
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 |
function notifyAcceleration(x, y, z) { |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
332 |
accelerationCallback(x, y, z); |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
333 |
} |
f943a50b6689
Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
334 |
} |