diff options
Diffstat (limited to 'apps/recorder/cube.c')
-rw-r--r-- | apps/recorder/cube.c | 158 |
1 files changed, 87 insertions, 71 deletions
diff --git a/apps/recorder/cube.c b/apps/recorder/cube.c index fddd294773..4ad7ebb80b 100644 --- a/apps/recorder/cube.c +++ b/apps/recorder/cube.c | |||
@@ -31,25 +31,33 @@ | |||
31 | #include "button.h" | 31 | #include "button.h" |
32 | #include "sprintf.h" | 32 | #include "sprintf.h" |
33 | #include "screens.h" | 33 | #include "screens.h" |
34 | #include "font.h" | ||
34 | 35 | ||
35 | typedef struct | 36 | /* Loops that the values are displayed */ |
36 | {long x,y,z;} point3D; | 37 | #define DISP_TIME 30 |
38 | |||
39 | struct point_3D { | ||
40 | long x, y, z; | ||
41 | }; | ||
42 | |||
43 | struct point_2D { | ||
44 | long x, y; | ||
45 | }; | ||
37 | 46 | ||
38 | typedef struct | 47 | static struct point_3D sommet[8]; |
39 | {long x,y;} point2D; | 48 | static struct point_3D point3D[8]; |
49 | static struct point_2D point2D[8]; | ||
40 | 50 | ||
41 | static point3D Sommet[8]; | 51 | static long matrice[3][3]; |
42 | static point3D Point3D[8]; | ||
43 | static point2D Point2D[8]; | ||
44 | 52 | ||
45 | static int Nb_points = 8; | 53 | static int nb_points = 8; |
46 | 54 | ||
47 | static int Xoff = 56; | 55 | static int x_off = 56; |
48 | static int Yoff = 95; | 56 | static int y_off = 95; |
49 | static int Zoff = 600; | 57 | static int z_off = 600; |
50 | 58 | ||
51 | /* Precalculated sine and cosine * 10000 (four digit fixed point math) */ | 59 | /* Precalculated sine and cosine * 10000 (four digit fixed point math) */ |
52 | static int SinTable[91] = | 60 | static int sin_table[91] = |
53 | { | 61 | { |
54 | 0, 174, 348, 523, 697, | 62 | 0, 174, 348, 523, 697, |
55 | 871,1045,1218,1391,1564, | 63 | 871,1045,1218,1391,1564, |
@@ -72,76 +80,83 @@ static int SinTable[91] = | |||
72 | 10000 | 80 | 10000 |
73 | }; | 81 | }; |
74 | 82 | ||
75 | static long Sin(int val) | 83 | static long sin(int val) |
76 | { | 84 | { |
77 | /* Speed improvement through sukzessive lookup */ | 85 | /* Speed improvement through sukzessive lookup */ |
78 | if (val<181) | 86 | if (val<181) |
79 | { | 87 | { |
80 | if (val<91)/* phase 0-90 degree */ | 88 | if (val<91) |
81 | { | 89 | { |
82 | return (long)SinTable[val]; | 90 | /* phase 0-90 degree */ |
91 | return (long)sin_table[val]; | ||
83 | } | 92 | } |
84 | else/* phase 91-180 degree */ | 93 | else |
85 | { | 94 | { |
86 | return (long)SinTable[180-val]; | 95 | /* phase 91-180 degree */ |
96 | return (long)sin_table[180-val]; | ||
87 | } | 97 | } |
88 | } | 98 | } |
89 | else | 99 | else |
90 | { | 100 | { |
91 | if (val<271)/* phase 181-270 degree */ | 101 | if (val<271) |
92 | { | 102 | { |
93 | return (-1L)*(long)SinTable[val-180]; | 103 | /* phase 181-270 degree */ |
104 | return (-1L)*(long)sin_table[val-180]; | ||
94 | } | 105 | } |
95 | else/* phase 270-359 degree */ | 106 | else |
96 | { | 107 | { |
97 | return (-1L)*(long)SinTable[360-val]; | 108 | /* phase 270-359 degree */ |
109 | return (-1L)*(long)sin_table[360-val]; | ||
98 | } | 110 | } |
99 | } | 111 | } |
100 | return 0; | 112 | return 0; |
101 | } | 113 | } |
102 | 114 | ||
103 | static long Cos(int val) | 115 | static long cos(int val) |
104 | { | 116 | { |
105 | /* Speed improvement through sukzessive lookup */ | 117 | /* Speed improvement through sukzessive lookup */ |
106 | if (val<181) | 118 | if (val<181) |
107 | { | 119 | { |
108 | if (val<91)/* phase 0-90 degree */ | 120 | if (val<91) |
109 | { | 121 | { |
110 | return (long)SinTable[90-val]; | 122 | /* phase 0-90 degree */ |
123 | return (long)sin_table[90-val]; | ||
111 | } | 124 | } |
112 | else/* phase 91-180 degree */ | 125 | else |
113 | { | 126 | { |
114 | return (-1L)*(long)SinTable[val-90]; | 127 | /* phase 91-180 degree */ |
128 | return (-1L)*(long)sin_table[val-90]; | ||
115 | } | 129 | } |
116 | } | 130 | } |
117 | else | 131 | else |
118 | { | 132 | { |
119 | if (val<271)/* phase 181-270 degree */ | 133 | if (val<271) |
120 | { | 134 | { |
121 | return (-1L)*(long)SinTable[270-val]; | 135 | /* phase 181-270 degree */ |
136 | return (-1L)*(long)sin_table[270-val]; | ||
122 | } | 137 | } |
123 | else/* phase 270-359 degree */ | 138 | else |
124 | { | 139 | { |
125 | return (long)SinTable[val-270]; | 140 | /* phase 270-359 degree */ |
141 | return (long)sin_table[val-270]; | ||
126 | } | 142 | } |
127 | } | 143 | } |
128 | return 0; | 144 | return 0; |
129 | } | 145 | } |
130 | 146 | ||
131 | static long matrice[3][3]; | ||
132 | 147 | ||
133 | static void cube_rotate(int Xa, int Ya, int Za) | 148 | static void cube_rotate(int xa, int ya, int za) |
134 | { | 149 | { |
135 | int i; | 150 | int i; |
136 | 151 | ||
137 | /* Just to prevent unnecessary lookups */ | 152 | /* Just to prevent unnecessary lookups */ |
138 | long sxa,cxa,sya,cya,sza,cza; | 153 | long sxa,cxa,sya,cya,sza,cza; |
139 | sxa=Sin(Xa); | 154 | sxa=sin(xa); |
140 | cxa=Cos(Xa); | 155 | cxa=cos(xa); |
141 | sya=Sin(Ya); | 156 | sya=sin(ya); |
142 | cya=Cos(Ya); | 157 | cya=cos(ya); |
143 | sza=Sin(Za); | 158 | sza=sin(za); |
144 | cza=Cos(Za); | 159 | cza=cos(za); |
145 | 160 | ||
146 | /* calculate overall translation matrix */ | 161 | /* calculate overall translation matrix */ |
147 | matrice[0][0] = cza*cya/10000L; | 162 | matrice[0][0] = cza*cya/10000L; |
@@ -157,19 +172,16 @@ static void cube_rotate(int Xa, int Ya, int Za) | |||
157 | matrice[2][2] = cxa*cya/10000L; | 172 | matrice[2][2] = cxa*cya/10000L; |
158 | 173 | ||
159 | /* apply translation matrix to all points */ | 174 | /* apply translation matrix to all points */ |
160 | for(i=0;i<Nb_points;i++) | 175 | for(i=0;i<nb_points;i++) |
161 | { | 176 | { |
162 | Point3D[i].x = matrice[0][0]*Sommet[i].x | 177 | point3D[i].x = matrice[0][0]*sommet[i].x + matrice[1][0]*sommet[i].y |
163 | + matrice[1][0]*Sommet[i].y | 178 | + matrice[2][0]*sommet[i].z; |
164 | + matrice[2][0]*Sommet[i].z; | 179 | |
165 | 180 | point3D[i].y = matrice[0][1]*sommet[i].x + matrice[1][1]*sommet[i].y | |
166 | Point3D[i].y = matrice[0][1]*Sommet[i].x | 181 | + matrice[2][1]*sommet[i].z; |
167 | + matrice[1][1]*Sommet[i].y | 182 | |
168 | + matrice[2][1]*Sommet[i].z; | 183 | point3D[i].z = matrice[0][2]*sommet[i].x + matrice[1][2]*sommet[i].y |
169 | 184 | + matrice[2][2]*sommet[i].z; | |
170 | Point3D[i].z = matrice[0][2]*Sommet[i].x | ||
171 | + matrice[1][2]*Sommet[i].y | ||
172 | + matrice[2][2]*Sommet[i].z; | ||
173 | } | 185 | } |
174 | } | 186 | } |
175 | 187 | ||
@@ -178,31 +190,31 @@ static void cube_viewport(void) | |||
178 | int i; | 190 | int i; |
179 | 191 | ||
180 | /* Do viewport transformation for all points */ | 192 | /* Do viewport transformation for all points */ |
181 | for(i=0;i<Nb_points;i++) | 193 | for(i=0;i<nb_points;i++) |
182 | { | 194 | { |
183 | Point2D[i].x=(((Point3D[i].x)<<8)/10000L)/ | 195 | point2D[i].x=(((point3D[i].x)<<8)/10000L)/ |
184 | (Point3D[i].z/10000L+Zoff)+Xoff; | 196 | (point3D[i].z/10000L+z_off)+x_off; |
185 | Point2D[i].y=(((Point3D[i].y)<<8)/10000L)/ | 197 | point2D[i].y=(((point3D[i].y)<<8)/10000L)/ |
186 | (Point3D[i].z/10000L+Zoff)+Yoff; | 198 | (point3D[i].z/10000L+z_off)+y_off; |
187 | } | 199 | } |
188 | } | 200 | } |
189 | 201 | ||
190 | static void cube_init(void) | 202 | static void cube_init(void) |
191 | { | 203 | { |
192 | /* Original 3D-position of cube's corners */ | 204 | /* Original 3D-position of cube's corners */ |
193 | Sommet[0].x = -40; Sommet[0].y = -40; Sommet[0].z = -40; | 205 | sommet[0].x = -40; sommet[0].y = -40; sommet[0].z = -40; |
194 | Sommet[1].x = 40; Sommet[1].y = -40; Sommet[1].z = -40; | 206 | sommet[1].x = 40; sommet[1].y = -40; sommet[1].z = -40; |
195 | Sommet[2].x = 40; Sommet[2].y = 40; Sommet[2].z = -40; | 207 | sommet[2].x = 40; sommet[2].y = 40; sommet[2].z = -40; |
196 | Sommet[3].x = -40; Sommet[3].y = 40; Sommet[3].z = -40; | 208 | sommet[3].x = -40; sommet[3].y = 40; sommet[3].z = -40; |
197 | Sommet[4].x = 40; Sommet[4].y = -40; Sommet[4].z = 40; | 209 | sommet[4].x = 40; sommet[4].y = -40; sommet[4].z = 40; |
198 | Sommet[5].x = -40; Sommet[5].y = -40; Sommet[5].z = 40; | 210 | sommet[5].x = -40; sommet[5].y = -40; sommet[5].z = 40; |
199 | Sommet[6].x = -40; Sommet[6].y = 40; Sommet[6].z = 40; | 211 | sommet[6].x = -40; sommet[6].y = 40; sommet[6].z = 40; |
200 | Sommet[7].x = 40; Sommet[7].y = 40; Sommet[7].z = 40; | 212 | sommet[7].x = 40; sommet[7].y = 40; sommet[7].z = 40; |
201 | } | 213 | } |
202 | 214 | ||
203 | static void line(int a, int b) | 215 | static void line(int a, int b) |
204 | { | 216 | { |
205 | lcd_drawline(Point2D[a].x,Point2D[a].y,Point2D[b].x,Point2D[b].y); | 217 | lcd_drawline(point2D[a].x, point2D[a].y, point2D[b].x, point2D[b].y); |
206 | } | 218 | } |
207 | 219 | ||
208 | static void cube_draw(void) | 220 | static void cube_draw(void) |
@@ -222,10 +234,6 @@ static void cube_draw(void) | |||
222 | line(3,6); | 234 | line(3,6); |
223 | } | 235 | } |
224 | 236 | ||
225 | |||
226 | /* Loops that the values are displayed */ | ||
227 | #define DISP_TIME 30 | ||
228 | |||
229 | bool cube(void) | 237 | bool cube(void) |
230 | { | 238 | { |
231 | int t_disp=0; | 239 | int t_disp=0; |
@@ -240,11 +248,14 @@ bool cube(void) | |||
240 | bool highspeed=0; | 248 | bool highspeed=0; |
241 | bool exit=0; | 249 | bool exit=0; |
242 | 250 | ||
251 | lcd_setfont(FONT_SYSFIXED); | ||
252 | |||
243 | cube_init(); | 253 | cube_init(); |
244 | 254 | ||
245 | while(!exit) | 255 | while(!exit) |
246 | { | 256 | { |
247 | if (!highspeed) sleep(4); | 257 | if (!highspeed) |
258 | sleep(4); | ||
248 | 259 | ||
249 | lcd_clear_display(); | 260 | lcd_clear_display(); |
250 | cube_rotate(xa,ya,za); | 261 | cube_rotate(xa,ya,za); |
@@ -255,7 +266,7 @@ bool cube(void) | |||
255 | t_disp--; | 266 | t_disp--; |
256 | snprintf(buffer, 30, "x:%d y:%d z:%d h:%d",xs,ys,zs,highspeed); | 267 | snprintf(buffer, 30, "x:%d y:%d z:%d h:%d",xs,ys,zs,highspeed); |
257 | lcd_putsxy(0, 56, buffer); | 268 | lcd_putsxy(0, 56, buffer); |
258 | } | 269 | } |
259 | lcd_update(); | 270 | lcd_update(); |
260 | 271 | ||
261 | xa+=xs; | 272 | xa+=xs; |
@@ -322,10 +333,13 @@ bool cube(void) | |||
322 | 333 | ||
323 | case SYS_USB_CONNECTED: | 334 | case SYS_USB_CONNECTED: |
324 | usb_screen(); | 335 | usb_screen(); |
336 | lcd_setfont(FONT_UI); | ||
325 | return true; | 337 | return true; |
326 | |||
327 | } | 338 | } |
328 | } | 339 | } |
340 | |||
341 | lcd_setfont(FONT_UI); | ||
342 | |||
329 | return false; | 343 | return false; |
330 | } | 344 | } |
331 | 345 | ||
@@ -338,3 +352,5 @@ bool cube(void) | |||
338 | * vim: et sw=4 ts=8 sts=4 tw=78 | 352 | * vim: et sw=4 ts=8 sts=4 tw=78 |
339 | */ | 353 | */ |
340 | 354 | ||
355 | |||
356 | |||