diff options
Diffstat (limited to 'apps/plugins/cube.c')
-rw-r--r-- | apps/plugins/cube.c | 93 |
1 files changed, 7 insertions, 86 deletions
diff --git a/apps/plugins/cube.c b/apps/plugins/cube.c index 31e1613479..f5158e9b7a 100644 --- a/apps/plugins/cube.c +++ b/apps/plugins/cube.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include "gray.h" | 22 | #include "gray.h" |
23 | #include "playergfx.h" | 23 | #include "playergfx.h" |
24 | #include "xlcd.h" | 24 | #include "xlcd.h" |
25 | #include "fixedpoint.h" | ||
25 | 26 | ||
26 | PLUGIN_HEADER | 27 | PLUGIN_HEADER |
27 | 28 | ||
@@ -312,100 +313,20 @@ static long matrice[3][3]; | |||
312 | static const int nb_points = 8; | 313 | static const int nb_points = 8; |
313 | static long z_off = 600; | 314 | static long z_off = 600; |
314 | 315 | ||
315 | /* Precalculated sine and cosine * 16384 (fixed point 18.14) */ | ||
316 | static const short sin_table[91] = | ||
317 | { | ||
318 | 0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563, | ||
319 | 2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334, | ||
320 | 5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943, | ||
321 | 8191, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310, | ||
322 | 10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365, | ||
323 | 12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043, | ||
324 | 14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295, | ||
325 | 15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082, | ||
326 | 16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381, | ||
327 | 16384 | ||
328 | }; | ||
329 | |||
330 | static struct plugin_api* rb; | 316 | static struct plugin_api* rb; |
331 | 317 | ||
332 | static long sin(int val) | ||
333 | { | ||
334 | /* Speed improvement through sukzessive lookup */ | ||
335 | if (val < 181) | ||
336 | { | ||
337 | if (val < 91) | ||
338 | { | ||
339 | /* phase 0-90 degree */ | ||
340 | return (long)sin_table[val]; | ||
341 | } | ||
342 | else | ||
343 | { | ||
344 | /* phase 91-180 degree */ | ||
345 | return (long)sin_table[180-val]; | ||
346 | } | ||
347 | } | ||
348 | else | ||
349 | { | ||
350 | if (val < 271) | ||
351 | { | ||
352 | /* phase 181-270 degree */ | ||
353 | return -(long)sin_table[val-180]; | ||
354 | } | ||
355 | else | ||
356 | { | ||
357 | /* phase 270-359 degree */ | ||
358 | return -(long)sin_table[360-val]; | ||
359 | } | ||
360 | } | ||
361 | return 0; | ||
362 | } | ||
363 | |||
364 | static long cos(int val) | ||
365 | { | ||
366 | /* Speed improvement through sukzessive lookup */ | ||
367 | if (val < 181) | ||
368 | { | ||
369 | if (val < 91) | ||
370 | { | ||
371 | /* phase 0-90 degree */ | ||
372 | return (long)sin_table[90-val]; | ||
373 | } | ||
374 | else | ||
375 | { | ||
376 | /* phase 91-180 degree */ | ||
377 | return -(long)sin_table[val-90]; | ||
378 | } | ||
379 | } | ||
380 | else | ||
381 | { | ||
382 | if (val < 271) | ||
383 | { | ||
384 | /* phase 181-270 degree */ | ||
385 | return -(long)sin_table[270-val]; | ||
386 | } | ||
387 | else | ||
388 | { | ||
389 | /* phase 270-359 degree */ | ||
390 | return (long)sin_table[val-270]; | ||
391 | } | ||
392 | } | ||
393 | return 0; | ||
394 | } | ||
395 | |||
396 | |||
397 | static void cube_rotate(int xa, int ya, int za) | 318 | static void cube_rotate(int xa, int ya, int za) |
398 | { | 319 | { |
399 | int i; | 320 | int i; |
400 | /* Just to prevent unnecessary lookups */ | 321 | /* Just to prevent unnecessary lookups */ |
401 | long sxa, cxa, sya, cya, sza, cza; | 322 | long sxa, cxa, sya, cya, sza, cza; |
402 | 323 | ||
403 | sxa = sin(xa); | 324 | sxa = sin_int(xa); |
404 | cxa = cos(xa); | 325 | cxa = cos_int(xa); |
405 | sya = sin(ya); | 326 | sya = sin_int(ya); |
406 | cya = cos(ya); | 327 | cya = cos_int(ya); |
407 | sza = sin(za); | 328 | sza = sin_int(za); |
408 | cza = cos(za); | 329 | cza = cos_int(za); |
409 | 330 | ||
410 | /* calculate overall translation matrix */ | 331 | /* calculate overall translation matrix */ |
411 | matrice[0][0] = (cza * cya) >> 14; | 332 | matrice[0][0] = (cza * cya) >> 14; |