1
0
Fork 0
forked from len0rd/rockbox

Cube.rock: converted to binary fixed-point arithmetic allowing for some more optimisation, and added proper aspect handling of LCDs with non-square pixels (all archos SH targets).

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7126 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jens Arnold 2005-07-12 21:15:37 +00:00
parent d191756286
commit 426df39c4c

View file

@ -9,6 +9,7 @@
* *
* Copyright (C) 2002 Damien Teney * Copyright (C) 2002 Damien Teney
* modified to use int instead of float math by Andreas Zwirtes * modified to use int instead of float math by Andreas Zwirtes
* binary fixed point format and LCD aspect handling by Jens Arnold
* *
* All files in this archive are subject to the GNU General Public License. * All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement. * See the file COPYING in the source tree root for full license agreement.
@ -90,47 +91,45 @@ static int nb_points = 8;
#define DIST (10*LCD_HEIGHT/16) #define DIST (10*LCD_HEIGHT/16)
static int x_off = LCD_WIDTH/2; static int x_off = LCD_WIDTH/2;
static int y_off = LCD_HEIGHT/2; static int y_off = LCD_HEIGHT/2;
#if CONFIG_LCD == LCD_SSD1815
#define ASPECT 320 /* = 1.25 (fixed point 24.8) */
#else #else
#define ASPECT 256 /* = 1.00 */
#endif
#else /* !LCD_BITMAP */
#define MYLCD(fn) pgfx_ ## fn #define MYLCD(fn) pgfx_ ## fn
#define DIST 9 #define DIST 9
static int x_off = 10; static int x_off = 10;
static int y_off = 7; static int y_off = 7;
#endif #define ASPECT 300 /* = 1.175 */
#endif /* !LCD_BITMAP */
static int z_off = 600;
/* Precalculated sine and cosine * 10000 (four digit fixed point math) */ static long z_off = 600;
static int sin_table[91] =
/* Precalculated sine and cosine * 16384 (fixed point 18.14) */
static short sin_table[91] =
{ {
0, 174, 348, 523, 697, 0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563,
871,1045,1218,1391,1564, 2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334,
1736,1908,2079,2249,2419, 5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943,
2588,2756,2923,3090,3255, 8191, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310,
3420,3583,3746,3907,4067, 10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365,
4226,4383,4539,4694,4848, 12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043,
5000,5150,5299,5446,5591, 14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295,
5735,5877,6018,6156,6293, 15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082,
6427,6560,6691,6819,6946, 16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381,
7071,7193,7313,7431,7547, 16384
7660,7771,7880,7986,8090, };
8191,8290,8386,8480,8571,
8660,8746,8829,8910,8987,
9063,9135,9205,9271,9335,
9396,9455,9510,9563,9612,
9659,9702,9743,9781,9816,
9848,9876,9902,9925,9945,
9961,9975,9986,9993,9998,
10000
};
static struct plugin_api* rb; static struct plugin_api* rb;
static long sin(int val) static long sin(int val)
{ {
/* Speed improvement through sukzessive lookup */ /* Speed improvement through sukzessive lookup */
if (val<181) if (val < 181)
{ {
if (val<91) if (val < 91)
{ {
/* phase 0-90 degree */ /* phase 0-90 degree */
return (long)sin_table[val]; return (long)sin_table[val];
@ -143,15 +142,15 @@ static long sin(int val)
} }
else else
{ {
if (val<271) if (val < 271)
{ {
/* phase 181-270 degree */ /* phase 181-270 degree */
return (-1L)*(long)sin_table[val-180]; return -(long)sin_table[val-180];
} }
else else
{ {
/* phase 270-359 degree */ /* phase 270-359 degree */
return (-1L)*(long)sin_table[360-val]; return -(long)sin_table[360-val];
} }
} }
return 0; return 0;
@ -160,9 +159,9 @@ static long sin(int val)
static long cos(int val) static long cos(int val)
{ {
/* Speed improvement through sukzessive lookup */ /* Speed improvement through sukzessive lookup */
if (val<181) if (val < 181)
{ {
if (val<91) if (val < 91)
{ {
/* phase 0-90 degree */ /* phase 0-90 degree */
return (long)sin_table[90-val]; return (long)sin_table[90-val];
@ -170,15 +169,15 @@ static long cos(int val)
else else
{ {
/* phase 91-180 degree */ /* phase 91-180 degree */
return (-1L)*(long)sin_table[val-90]; return -(long)sin_table[val-90];
} }
} }
else else
{ {
if (val<271) if (val < 271)
{ {
/* phase 181-270 degree */ /* phase 181-270 degree */
return (-1L)*(long)sin_table[270-val]; return -(long)sin_table[270-val];
} }
else else
{ {
@ -193,40 +192,40 @@ static long cos(int val)
static void cube_rotate(int xa, int ya, int za) static void cube_rotate(int xa, int ya, int za)
{ {
int i; int i;
/* Just to prevent unnecessary lookups */ /* Just to prevent unnecessary lookups */
long sxa,cxa,sya,cya,sza,cza; long sxa, cxa, sya, cya, sza, cza;
sxa=sin(xa);
cxa=cos(xa); sxa = sin(xa);
sya=sin(ya); cxa = cos(xa);
cya=cos(ya); sya = sin(ya);
sza=sin(za); cya = cos(ya);
cza=cos(za); sza = sin(za);
cza = cos(za);
/* calculate overall translation matrix */ /* calculate overall translation matrix */
matrice[0][0] = cza*cya/10000L; matrice[0][0] = (cza * cya) >> 14;
matrice[1][0] = sza*cya/10000L; matrice[1][0] = (sza * cya) >> 14;
matrice[2][0] = -sya; matrice[2][0] = -sya;
matrice[0][1] = cza*sya/10000L*sxa/10000L - sza*cxa/10000L; matrice[0][1] = (((cza * sya) >> 14) * sxa - sza * cxa) >> 14;
matrice[1][1] = sza*sya/10000L*sxa/10000L + cxa*cza/10000L; matrice[1][1] = (((sza * sya) >> 14) * sxa + cxa * cza) >> 14;
matrice[2][1] = sxa*cya/10000L; matrice[2][1] = (sxa * cya) >> 14;
matrice[0][2] = cza*sya/10000L*cxa/10000L + sza*sxa/10000L; matrice[0][2] = (((cza * sya) >> 14) * cxa + sza * sxa) >> 14;
matrice[1][2] = sza*sya/10000L*cxa/10000L - cza*sxa/10000L; matrice[1][2] = (((sza * sya) >> 14) * cxa - cza * sxa) >> 14;
matrice[2][2] = cxa*cya/10000L; matrice[2][2] = (cxa * cya) >> 14;
/* apply translation matrix to all points */ /* apply translation matrix to all points */
for(i=0;i<nb_points;i++) for (i = 0; i < nb_points; i++)
{ {
point3D[i].x = matrice[0][0]*sommet[i].x + matrice[1][0]*sommet[i].y point3D[i].x = matrice[0][0] * sommet[i].x + matrice[1][0] * sommet[i].y
+ matrice[2][0]*sommet[i].z; + matrice[2][0] * sommet[i].z;
point3D[i].y = matrice[0][1]*sommet[i].x + matrice[1][1]*sommet[i].y point3D[i].y = matrice[0][1] * sommet[i].x + matrice[1][1] * sommet[i].y
+ matrice[2][1]*sommet[i].z; + matrice[2][1] * sommet[i].z;
point3D[i].z = matrice[0][2]*sommet[i].x + matrice[1][2]*sommet[i].y point3D[i].z = matrice[0][2] * sommet[i].x + matrice[1][2] * sommet[i].y
+ matrice[2][2]*sommet[i].z; + matrice[2][2] * sommet[i].z;
} }
} }
@ -235,12 +234,17 @@ static void cube_viewport(void)
int i; int i;
/* Do viewport transformation for all points */ /* Do viewport transformation for all points */
for(i=0;i<nb_points;i++) for (i = 0; i < nb_points; i++)
{ {
point2D[i].x=(((point3D[i].x)<<8)/10000L)/ #if ASPECT != 256
(point3D[i].z/10000L+z_off)+x_off; point2D[i].x = (point3D[i].x * ASPECT) / (point3D[i].z + (z_off << 14))
point2D[i].y=(((point3D[i].y)<<8)/10000L)/ + x_off;
(point3D[i].z/10000L+z_off)+y_off; #else
point2D[i].x = (point3D[i].x << 8) / (point3D[i].z + (z_off << 14))
+ x_off;
#endif
point2D[i].y = (point3D[i].y << 8) / (point3D[i].z + (z_off << 14))
+ y_off;
} }
} }