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:
parent
d191756286
commit
426df39c4c
1 changed files with 66 additions and 62 deletions
|
@ -9,6 +9,7 @@
|
|||
*
|
||||
* Copyright (C) 2002 Damien Teney
|
||||
* 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.
|
||||
* 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)
|
||||
static int x_off = LCD_WIDTH/2;
|
||||
static int y_off = LCD_HEIGHT/2;
|
||||
#if CONFIG_LCD == LCD_SSD1815
|
||||
#define ASPECT 320 /* = 1.25 (fixed point 24.8) */
|
||||
#else
|
||||
#define ASPECT 256 /* = 1.00 */
|
||||
#endif
|
||||
#else /* !LCD_BITMAP */
|
||||
#define MYLCD(fn) pgfx_ ## fn
|
||||
#define DIST 9
|
||||
static int x_off = 10;
|
||||
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 int sin_table[91] =
|
||||
static long z_off = 600;
|
||||
|
||||
/* Precalculated sine and cosine * 16384 (fixed point 18.14) */
|
||||
static short sin_table[91] =
|
||||
{
|
||||
0, 174, 348, 523, 697,
|
||||
871,1045,1218,1391,1564,
|
||||
1736,1908,2079,2249,2419,
|
||||
2588,2756,2923,3090,3255,
|
||||
3420,3583,3746,3907,4067,
|
||||
4226,4383,4539,4694,4848,
|
||||
5000,5150,5299,5446,5591,
|
||||
5735,5877,6018,6156,6293,
|
||||
6427,6560,6691,6819,6946,
|
||||
7071,7193,7313,7431,7547,
|
||||
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
|
||||
};
|
||||
0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563,
|
||||
2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334,
|
||||
5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943,
|
||||
8191, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310,
|
||||
10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365,
|
||||
12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043,
|
||||
14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295,
|
||||
15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082,
|
||||
16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381,
|
||||
16384
|
||||
};
|
||||
|
||||
static struct plugin_api* rb;
|
||||
|
||||
static long sin(int val)
|
||||
{
|
||||
/* Speed improvement through sukzessive lookup */
|
||||
if (val<181)
|
||||
if (val < 181)
|
||||
{
|
||||
if (val<91)
|
||||
if (val < 91)
|
||||
{
|
||||
/* phase 0-90 degree */
|
||||
return (long)sin_table[val];
|
||||
|
@ -143,15 +142,15 @@ static long sin(int val)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (val<271)
|
||||
if (val < 271)
|
||||
{
|
||||
/* phase 181-270 degree */
|
||||
return (-1L)*(long)sin_table[val-180];
|
||||
return -(long)sin_table[val-180];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* phase 270-359 degree */
|
||||
return (-1L)*(long)sin_table[360-val];
|
||||
return -(long)sin_table[360-val];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -160,9 +159,9 @@ static long sin(int val)
|
|||
static long cos(int val)
|
||||
{
|
||||
/* Speed improvement through sukzessive lookup */
|
||||
if (val<181)
|
||||
if (val < 181)
|
||||
{
|
||||
if (val<91)
|
||||
if (val < 91)
|
||||
{
|
||||
/* phase 0-90 degree */
|
||||
return (long)sin_table[90-val];
|
||||
|
@ -170,15 +169,15 @@ static long cos(int val)
|
|||
else
|
||||
{
|
||||
/* phase 91-180 degree */
|
||||
return (-1L)*(long)sin_table[val-90];
|
||||
return -(long)sin_table[val-90];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (val<271)
|
||||
if (val < 271)
|
||||
{
|
||||
/* phase 181-270 degree */
|
||||
return (-1L)*(long)sin_table[270-val];
|
||||
return -(long)sin_table[270-val];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -193,40 +192,40 @@ static long cos(int val)
|
|||
static void cube_rotate(int xa, int ya, int za)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Just to prevent unnecessary lookups */
|
||||
long sxa,cxa,sya,cya,sza,cza;
|
||||
sxa=sin(xa);
|
||||
cxa=cos(xa);
|
||||
sya=sin(ya);
|
||||
cya=cos(ya);
|
||||
sza=sin(za);
|
||||
cza=cos(za);
|
||||
long sxa, cxa, sya, cya, sza, cza;
|
||||
|
||||
sxa = sin(xa);
|
||||
cxa = cos(xa);
|
||||
sya = sin(ya);
|
||||
cya = cos(ya);
|
||||
sza = sin(za);
|
||||
cza = cos(za);
|
||||
|
||||
/* calculate overall translation matrix */
|
||||
matrice[0][0] = cza*cya/10000L;
|
||||
matrice[1][0] = sza*cya/10000L;
|
||||
matrice[0][0] = (cza * cya) >> 14;
|
||||
matrice[1][0] = (sza * cya) >> 14;
|
||||
matrice[2][0] = -sya;
|
||||
|
||||
matrice[0][1] = cza*sya/10000L*sxa/10000L - sza*cxa/10000L;
|
||||
matrice[1][1] = sza*sya/10000L*sxa/10000L + cxa*cza/10000L;
|
||||
matrice[2][1] = sxa*cya/10000L;
|
||||
matrice[0][1] = (((cza * sya) >> 14) * sxa - sza * cxa) >> 14;
|
||||
matrice[1][1] = (((sza * sya) >> 14) * sxa + cxa * cza) >> 14;
|
||||
matrice[2][1] = (sxa * cya) >> 14;
|
||||
|
||||
matrice[0][2] = cza*sya/10000L*cxa/10000L + sza*sxa/10000L;
|
||||
matrice[1][2] = sza*sya/10000L*cxa/10000L - cza*sxa/10000L;
|
||||
matrice[2][2] = cxa*cya/10000L;
|
||||
matrice[0][2] = (((cza * sya) >> 14) * cxa + sza * sxa) >> 14;
|
||||
matrice[1][2] = (((sza * sya) >> 14) * cxa - cza * sxa) >> 14;
|
||||
matrice[2][2] = (cxa * cya) >> 14;
|
||||
|
||||
/* 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
|
||||
+ matrice[2][0]*sommet[i].z;
|
||||
point3D[i].x = matrice[0][0] * sommet[i].x + matrice[1][0] * sommet[i].y
|
||||
+ matrice[2][0] * sommet[i].z;
|
||||
|
||||
point3D[i].y = matrice[0][1]*sommet[i].x + matrice[1][1]*sommet[i].y
|
||||
+ matrice[2][1]*sommet[i].z;
|
||||
point3D[i].y = matrice[0][1] * sommet[i].x + matrice[1][1] * sommet[i].y
|
||||
+ matrice[2][1] * sommet[i].z;
|
||||
|
||||
point3D[i].z = matrice[0][2]*sommet[i].x + matrice[1][2]*sommet[i].y
|
||||
+ matrice[2][2]*sommet[i].z;
|
||||
point3D[i].z = matrice[0][2] * sommet[i].x + matrice[1][2] * sommet[i].y
|
||||
+ matrice[2][2] * sommet[i].z;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,12 +234,17 @@ static void cube_viewport(void)
|
|||
int i;
|
||||
|
||||
/* 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)/
|
||||
(point3D[i].z/10000L+z_off)+x_off;
|
||||
point2D[i].y=(((point3D[i].y)<<8)/10000L)/
|
||||
(point3D[i].z/10000L+z_off)+y_off;
|
||||
#if ASPECT != 256
|
||||
point2D[i].x = (point3D[i].x * ASPECT) / (point3D[i].z + (z_off << 14))
|
||||
+ x_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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue