2002-10-15 07:17:50 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Damien Teney
|
|
|
|
* modified to use int instead of float math by Andreas Zwirtes
|
2005-07-13 20:40:46 +00:00
|
|
|
* heavily extended by Jens Arnold
|
2002-10-15 07:17:50 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
2003-06-29 16:33:04 +00:00
|
|
|
***************************************************************************/
|
|
|
|
#include "plugin.h"
|
2005-02-10 21:28:21 +00:00
|
|
|
#include "playergfx.h"
|
2005-07-12 23:57:06 +00:00
|
|
|
#include "xlcd.h"
|
2002-10-15 07:17:50 +00:00
|
|
|
|
2002-10-29 10:45:29 +00:00
|
|
|
/* Loops that the values are displayed */
|
|
|
|
#define DISP_TIME 30
|
|
|
|
|
2004-10-17 00:54:09 +00:00
|
|
|
/* variable button definitions */
|
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
2005-07-13 20:40:46 +00:00
|
|
|
#define CUBE_QUIT BUTTON_OFF
|
|
|
|
#define CUBE_X_INC BUTTON_RIGHT
|
|
|
|
#define CUBE_X_DEC BUTTON_LEFT
|
|
|
|
#define CUBE_Y_INC BUTTON_UP
|
|
|
|
#define CUBE_Y_DEC BUTTON_DOWN
|
|
|
|
#define CUBE_Z_INC BUTTON_F2
|
|
|
|
#define CUBE_Z_DEC BUTTON_F1
|
|
|
|
#define CUBE_MODE BUTTON_F3
|
|
|
|
#define CUBE_PAUSE BUTTON_PLAY
|
|
|
|
#define CUBE_HIGHSPEED BUTTON_ON
|
2004-10-17 00:54:09 +00:00
|
|
|
|
2005-02-10 21:28:21 +00:00
|
|
|
#elif CONFIG_KEYPAD == PLAYER_PAD
|
2005-07-13 20:40:46 +00:00
|
|
|
#define CUBE_QUIT BUTTON_STOP
|
|
|
|
#define CUBE_X_INC BUTTON_RIGHT
|
|
|
|
#define CUBE_X_DEC BUTTON_LEFT
|
|
|
|
#define CUBE_Y_INC (BUTTON_ON | BUTTON_RIGHT)
|
|
|
|
#define CUBE_Y_DEC (BUTTON_ON | BUTTON_LEFT)
|
|
|
|
#define CUBE_Z_INC (BUTTON_MENU | BUTTON_RIGHT)
|
|
|
|
#define CUBE_Z_DEC (BUTTON_MENU | BUTTON_LEFT)
|
|
|
|
#define CUBE_MODE_PRE BUTTON_MENU
|
|
|
|
#define CUBE_MODE (BUTTON_MENU | BUTTON_REL)
|
|
|
|
#define CUBE_PAUSE BUTTON_PLAY
|
|
|
|
#define CUBE_HIGHSPEED_PRE BUTTON_ON
|
|
|
|
#define CUBE_HIGHSPEED (BUTTON_ON | BUTTON_REL)
|
2005-02-10 21:28:21 +00:00
|
|
|
|
2004-10-17 00:54:09 +00:00
|
|
|
#elif CONFIG_KEYPAD == ONDIO_PAD
|
2005-07-13 20:40:46 +00:00
|
|
|
#define CUBE_QUIT BUTTON_OFF
|
|
|
|
#define CUBE_X_INC BUTTON_RIGHT
|
|
|
|
#define CUBE_X_DEC BUTTON_LEFT
|
|
|
|
#define CUBE_Y_INC BUTTON_UP
|
|
|
|
#define CUBE_Y_DEC BUTTON_DOWN
|
|
|
|
#define CUBE_Z_INC (BUTTON_MENU | BUTTON_UP)
|
|
|
|
#define CUBE_Z_DEC (BUTTON_MENU | BUTTON_DOWN)
|
|
|
|
#define CUBE_MODE_PRE BUTTON_MENU
|
|
|
|
#define CUBE_MODE (BUTTON_MENU | BUTTON_REL)
|
|
|
|
#define CUBE_PAUSE (BUTTON_MENU | BUTTON_LEFT)
|
|
|
|
#define CUBE_HIGHSPEED (BUTTON_MENU | BUTTON_RIGHT)
|
2004-10-17 00:54:09 +00:00
|
|
|
|
2005-06-29 12:47:24 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IRIVER_H300_PAD)
|
2005-07-13 20:40:46 +00:00
|
|
|
#define CUBE_QUIT BUTTON_OFF
|
|
|
|
#define CUBE_X_INC BUTTON_RIGHT
|
|
|
|
#define CUBE_X_DEC BUTTON_LEFT
|
|
|
|
#define CUBE_Y_INC BUTTON_UP
|
|
|
|
#define CUBE_Y_DEC BUTTON_DOWN
|
|
|
|
#define CUBE_Z_INC (BUTTON_ON | BUTTON_UP)
|
|
|
|
#define CUBE_Z_DEC (BUTTON_ON | BUTTON_DOWN)
|
|
|
|
#define CUBE_MODE BUTTON_MODE
|
|
|
|
#define CUBE_PAUSE_PRE BUTTON_ON
|
|
|
|
#define CUBE_PAUSE (BUTTON_ON | BUTTON_REL)
|
|
|
|
#define CUBE_HIGHSPEED BUTTON_SELECT
|
2005-02-04 12:41:09 +00:00
|
|
|
|
2004-10-17 00:54:09 +00:00
|
|
|
#endif
|
|
|
|
|
2005-02-10 21:28:21 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2005-07-01 16:22:15 +00:00
|
|
|
#define MYLCD(fn) rb->lcd_ ## fn
|
|
|
|
#define DIST (10*LCD_HEIGHT/16)
|
2005-02-08 22:48:53 +00:00
|
|
|
static int x_off = LCD_WIDTH/2;
|
|
|
|
static int y_off = LCD_HEIGHT/2;
|
2005-07-12 21:15:37 +00:00
|
|
|
#if CONFIG_LCD == LCD_SSD1815
|
|
|
|
#define ASPECT 320 /* = 1.25 (fixed point 24.8) */
|
2005-02-10 21:28:21 +00:00
|
|
|
#else
|
2005-07-12 21:15:37 +00:00
|
|
|
#define ASPECT 256 /* = 1.00 */
|
|
|
|
#endif
|
|
|
|
#else /* !LCD_BITMAP */
|
2005-07-01 16:22:15 +00:00
|
|
|
#define MYLCD(fn) pgfx_ ## fn
|
|
|
|
#define DIST 9
|
2005-02-10 21:28:21 +00:00
|
|
|
static int x_off = 10;
|
|
|
|
static int y_off = 7;
|
2005-07-12 21:15:37 +00:00
|
|
|
#define ASPECT 300 /* = 1.175 */
|
|
|
|
#endif /* !LCD_BITMAP */
|
2005-07-01 16:22:15 +00:00
|
|
|
|
2005-07-12 23:57:06 +00:00
|
|
|
struct point_3D {
|
|
|
|
long x, y, z;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct point_2D {
|
|
|
|
long x, y;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct line {
|
|
|
|
int start, end;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct face {
|
2005-07-13 20:40:46 +00:00
|
|
|
int corner[4];
|
|
|
|
int line[4];
|
2005-07-12 23:57:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* initial, unrotated cube corners */
|
|
|
|
static const struct point_3D sommet[8] =
|
|
|
|
{
|
|
|
|
{-DIST, -DIST, -DIST},
|
|
|
|
{ DIST, -DIST, -DIST},
|
|
|
|
{ DIST, DIST, -DIST},
|
|
|
|
{-DIST, DIST, -DIST},
|
|
|
|
{-DIST, -DIST, DIST},
|
|
|
|
{ DIST, -DIST, DIST},
|
|
|
|
{ DIST, DIST, DIST},
|
|
|
|
{-DIST, DIST, DIST}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The 12 lines forming the edges */
|
|
|
|
static const struct line lines[12] =
|
|
|
|
{
|
|
|
|
{0, 1}, {1, 2}, {2, 3}, {3, 0},
|
2005-07-13 20:40:46 +00:00
|
|
|
{4, 7}, {7, 6}, {6, 5}, {5, 4},
|
2005-07-12 23:57:06 +00:00
|
|
|
{0, 4}, {1, 5}, {2, 6}, {3, 7}
|
|
|
|
};
|
|
|
|
|
2005-07-13 20:40:46 +00:00
|
|
|
static bool lines_drawn[12];
|
|
|
|
|
|
|
|
/* The 6 faces of the cube; points are in clockwise order when viewed
|
|
|
|
from the outside */
|
2005-07-12 23:57:06 +00:00
|
|
|
static const struct face faces[6] =
|
|
|
|
{
|
2005-07-13 20:40:46 +00:00
|
|
|
{{0, 1, 2, 3}, {0, 1, 2, 3}},
|
|
|
|
{{4, 7, 6, 5}, {4, 5, 6, 7}},
|
|
|
|
{{0, 4, 5, 1}, {8, 7, 9, 0}},
|
|
|
|
{{2, 6, 7, 3}, {10, 5, 11, 2}},
|
|
|
|
{{0, 3, 7, 4}, {3, 11, 4, 8}},
|
|
|
|
{{1, 5, 6, 2}, {9, 6, 10, 1}}
|
2005-07-12 23:57:06 +00:00
|
|
|
};
|
|
|
|
|
2005-07-13 20:40:46 +00:00
|
|
|
#if LCD_DEPTH > 1
|
2005-07-19 10:33:41 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
static const struct rgb face_colors[6] =
|
|
|
|
{
|
|
|
|
{LCD_MAX_RED, 0, 0}, {LCD_MAX_RED, 0, 0}, {0, LCD_MAX_GREEN, 0},
|
|
|
|
{0, LCD_MAX_GREEN, 0}, {0, 0, LCD_MAX_BLUE}, {0, 0, LCD_MAX_BLUE}
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
static const int face_colors[6] =
|
2005-07-13 20:40:46 +00:00
|
|
|
{
|
2005-07-19 09:24:29 +00:00
|
|
|
2*LCD_MAX_LEVEL/3, 2*LCD_MAX_LEVEL/3, LCD_MAX_LEVEL/3, LCD_MAX_LEVEL/3, 0, 0
|
2005-07-13 20:40:46 +00:00
|
|
|
};
|
2005-07-12 23:57:06 +00:00
|
|
|
#endif
|
2005-07-19 10:33:41 +00:00
|
|
|
#endif
|
2005-07-12 23:57:06 +00:00
|
|
|
|
2005-07-13 20:40:46 +00:00
|
|
|
enum {
|
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
SOLID,
|
|
|
|
#endif
|
|
|
|
HIDDEN_LINES,
|
|
|
|
WIREFRAME,
|
|
|
|
NUM_MODES
|
|
|
|
};
|
|
|
|
|
|
|
|
static int mode = 0;
|
|
|
|
|
2005-07-12 23:57:06 +00:00
|
|
|
static struct point_3D point3D[8];
|
|
|
|
static struct point_2D point2D[8];
|
|
|
|
static long matrice[3][3];
|
2002-10-15 07:17:50 +00:00
|
|
|
|
2005-07-13 20:40:46 +00:00
|
|
|
static const int nb_points = 8;
|
2005-07-12 21:15:37 +00:00
|
|
|
static long z_off = 600;
|
|
|
|
|
|
|
|
/* Precalculated sine and cosine * 16384 (fixed point 18.14) */
|
2005-07-12 23:57:06 +00:00
|
|
|
static const short sin_table[91] =
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
2005-07-12 21:15:37 +00:00
|
|
|
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
|
|
|
|
};
|
2002-10-15 07:17:50 +00:00
|
|
|
|
2003-06-29 16:33:04 +00:00
|
|
|
static struct plugin_api* rb;
|
|
|
|
|
2002-10-29 10:45:29 +00:00
|
|
|
static long sin(int val)
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
|
|
|
/* Speed improvement through sukzessive lookup */
|
2005-07-12 21:15:37 +00:00
|
|
|
if (val < 181)
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
2005-07-12 21:15:37 +00:00
|
|
|
if (val < 91)
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
2002-10-29 10:45:29 +00:00
|
|
|
/* phase 0-90 degree */
|
|
|
|
return (long)sin_table[val];
|
2002-10-15 07:17:50 +00:00
|
|
|
}
|
2002-10-29 10:45:29 +00:00
|
|
|
else
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
2002-10-29 10:45:29 +00:00
|
|
|
/* phase 91-180 degree */
|
|
|
|
return (long)sin_table[180-val];
|
2002-10-15 07:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-12 21:15:37 +00:00
|
|
|
if (val < 271)
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
2002-10-29 10:45:29 +00:00
|
|
|
/* phase 181-270 degree */
|
2005-07-12 21:15:37 +00:00
|
|
|
return -(long)sin_table[val-180];
|
2002-10-15 07:17:50 +00:00
|
|
|
}
|
2002-10-29 10:45:29 +00:00
|
|
|
else
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
2002-10-29 10:45:29 +00:00
|
|
|
/* phase 270-359 degree */
|
2005-07-12 21:15:37 +00:00
|
|
|
return -(long)sin_table[360-val];
|
2002-10-15 07:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-29 10:45:29 +00:00
|
|
|
static long cos(int val)
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
|
|
|
/* Speed improvement through sukzessive lookup */
|
2005-07-12 21:15:37 +00:00
|
|
|
if (val < 181)
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
2005-07-12 21:15:37 +00:00
|
|
|
if (val < 91)
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
2002-10-29 10:45:29 +00:00
|
|
|
/* phase 0-90 degree */
|
|
|
|
return (long)sin_table[90-val];
|
2002-10-15 07:17:50 +00:00
|
|
|
}
|
2002-10-29 10:45:29 +00:00
|
|
|
else
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
2002-10-29 10:45:29 +00:00
|
|
|
/* phase 91-180 degree */
|
2005-07-12 21:15:37 +00:00
|
|
|
return -(long)sin_table[val-90];
|
2002-10-15 07:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-07-12 21:15:37 +00:00
|
|
|
if (val < 271)
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
2002-10-29 10:45:29 +00:00
|
|
|
/* phase 181-270 degree */
|
2005-07-12 21:15:37 +00:00
|
|
|
return -(long)sin_table[270-val];
|
2002-10-15 07:17:50 +00:00
|
|
|
}
|
2002-10-29 10:45:29 +00:00
|
|
|
else
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
2002-10-29 10:45:29 +00:00
|
|
|
/* phase 270-359 degree */
|
|
|
|
return (long)sin_table[val-270];
|
2002-10-15 07:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-29 10:45:29 +00:00
|
|
|
static void cube_rotate(int xa, int ya, int za)
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
/* Just to prevent unnecessary lookups */
|
2005-07-12 21:15:37 +00:00
|
|
|
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);
|
2002-10-15 07:17:50 +00:00
|
|
|
|
|
|
|
/* calculate overall translation matrix */
|
2005-07-12 21:15:37 +00:00
|
|
|
matrice[0][0] = (cza * cya) >> 14;
|
|
|
|
matrice[1][0] = (sza * cya) >> 14;
|
2002-10-15 07:17:50 +00:00
|
|
|
matrice[2][0] = -sya;
|
|
|
|
|
2005-07-12 21:15:37 +00:00
|
|
|
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;
|
2002-10-15 07:17:50 +00:00
|
|
|
|
2005-07-12 21:15:37 +00:00
|
|
|
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;
|
2002-10-15 07:17:50 +00:00
|
|
|
|
|
|
|
/* apply translation matrix to all points */
|
2005-07-12 21:15:37 +00:00
|
|
|
for (i = 0; i < nb_points; i++)
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
2005-07-12 21:15:37 +00:00
|
|
|
point3D[i].x = matrice[0][0] * sommet[i].x + matrice[1][0] * sommet[i].y
|
|
|
|
+ matrice[2][0] * sommet[i].z;
|
2002-10-29 10:45:29 +00:00
|
|
|
|
2005-07-12 21:15:37 +00:00
|
|
|
point3D[i].y = matrice[0][1] * sommet[i].x + matrice[1][1] * sommet[i].y
|
|
|
|
+ matrice[2][1] * sommet[i].z;
|
2002-10-29 10:45:29 +00:00
|
|
|
|
2005-07-12 21:15:37 +00:00
|
|
|
point3D[i].z = matrice[0][2] * sommet[i].x + matrice[1][2] * sommet[i].y
|
|
|
|
+ matrice[2][2] * sommet[i].z;
|
2002-10-15 07:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cube_viewport(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Do viewport transformation for all points */
|
2005-07-12 21:15:37 +00:00
|
|
|
for (i = 0; i < nb_points; i++)
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
2005-07-12 21:15:37 +00:00
|
|
|
#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;
|
2002-10-15 07:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cube_draw(void)
|
|
|
|
{
|
2005-07-13 20:40:46 +00:00
|
|
|
int i, j, line;
|
2005-07-12 23:57:06 +00:00
|
|
|
|
2005-07-13 20:40:46 +00:00
|
|
|
switch (mode)
|
2005-07-12 23:57:06 +00:00
|
|
|
{
|
2005-07-13 20:40:46 +00:00
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
case SOLID:
|
|
|
|
|
2005-07-13 06:07:11 +00:00
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
{
|
2005-07-13 20:40:46 +00:00
|
|
|
/* backface culling; if the shape winds counter-clockwise, we are
|
|
|
|
* looking at the backface, and the (simplified) cross product
|
|
|
|
* is < 0. Do not draw it. */
|
|
|
|
if (0 >= (point2D[faces[i].corner[1]].x - point2D[faces[i].corner[0]].x)
|
|
|
|
* (point2D[faces[i].corner[2]].y - point2D[faces[i].corner[1]].y)
|
|
|
|
- (point2D[faces[i].corner[1]].y - point2D[faces[i].corner[0]].y)
|
|
|
|
* (point2D[faces[i].corner[2]].x - point2D[faces[i].corner[1]].x))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rb->lcd_set_foreground(face_colors[i]);
|
|
|
|
xlcd_filltriangle(point2D[faces[i].corner[0]].x,
|
|
|
|
point2D[faces[i].corner[0]].y,
|
|
|
|
point2D[faces[i].corner[1]].x,
|
|
|
|
point2D[faces[i].corner[1]].y,
|
|
|
|
point2D[faces[i].corner[2]].x,
|
|
|
|
point2D[faces[i].corner[2]].y);
|
|
|
|
xlcd_filltriangle(point2D[faces[i].corner[0]].x,
|
|
|
|
point2D[faces[i].corner[0]].y,
|
|
|
|
point2D[faces[i].corner[2]].x,
|
|
|
|
point2D[faces[i].corner[2]].y,
|
|
|
|
point2D[faces[i].corner[3]].x,
|
|
|
|
point2D[faces[i].corner[3]].y);
|
|
|
|
|
2005-07-12 23:57:06 +00:00
|
|
|
}
|
2005-07-19 10:33:41 +00:00
|
|
|
rb->lcd_set_foreground(LCD_BLACK);
|
2005-07-13 20:40:46 +00:00
|
|
|
break;
|
|
|
|
#endif /* LCD_DEPTH > 1 */
|
2005-07-12 23:57:06 +00:00
|
|
|
|
2005-07-13 20:40:46 +00:00
|
|
|
case HIDDEN_LINES:
|
2005-07-12 23:57:06 +00:00
|
|
|
|
2005-07-13 20:40:46 +00:00
|
|
|
rb->memset(lines_drawn, 0, sizeof(lines_drawn));
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
/* backface culling; if the shape winds counter-clockwise, we are
|
|
|
|
* looking at the backface, and the (simplified) cross product
|
|
|
|
* is < 0. Do not draw it. */
|
|
|
|
if (0 >= (point2D[faces[i].corner[1]].x - point2D[faces[i].corner[0]].x)
|
|
|
|
* (point2D[faces[i].corner[2]].y - point2D[faces[i].corner[1]].y)
|
|
|
|
- (point2D[faces[i].corner[1]].y - point2D[faces[i].corner[0]].y)
|
|
|
|
* (point2D[faces[i].corner[2]].x - point2D[faces[i].corner[1]].x))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (j = 0; j < 4; j++)
|
2005-07-12 23:57:06 +00:00
|
|
|
{
|
2005-07-13 20:40:46 +00:00
|
|
|
line = faces[i].line[j];
|
|
|
|
if (!lines_drawn[line])
|
|
|
|
{
|
|
|
|
lines_drawn[line] = true;
|
|
|
|
MYLCD(drawline)(point2D[lines[line].start].x,
|
|
|
|
point2D[lines[line].start].y,
|
|
|
|
point2D[lines[line].end].x,
|
|
|
|
point2D[lines[line].end].y);
|
|
|
|
}
|
2005-07-13 06:07:11 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-13 20:40:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WIREFRAME:
|
|
|
|
|
2005-07-12 23:57:06 +00:00
|
|
|
for (i = 0; i < 12; i++)
|
|
|
|
MYLCD(drawline)(point2D[lines[i].start].x,
|
|
|
|
point2D[lines[i].start].y,
|
|
|
|
point2D[lines[i].end].x,
|
|
|
|
point2D[lines[i].end].y);
|
2005-07-13 20:40:46 +00:00
|
|
|
break;
|
2005-07-12 23:57:06 +00:00
|
|
|
}
|
2002-10-15 07:17:50 +00:00
|
|
|
}
|
|
|
|
|
2003-06-29 16:33:04 +00:00
|
|
|
|
|
|
|
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
|
|
|
char buffer[30];
|
2005-07-13 20:40:46 +00:00
|
|
|
int t_disp = 0;
|
2002-10-15 07:17:50 +00:00
|
|
|
|
2004-10-17 00:54:09 +00:00
|
|
|
int button;
|
2005-07-13 20:40:46 +00:00
|
|
|
int lastbutton = BUTTON_NONE;
|
|
|
|
int xa = 0;
|
|
|
|
int ya = 0;
|
|
|
|
int za = 0;
|
|
|
|
int xs = 1;
|
|
|
|
int ys = 3;
|
|
|
|
int zs = 1;
|
|
|
|
bool highspeed = false;
|
|
|
|
bool paused = false;
|
|
|
|
bool redraw = true;
|
|
|
|
bool exit = false;
|
2003-06-29 16:33:04 +00:00
|
|
|
|
|
|
|
TEST_PLUGIN_API(api);
|
|
|
|
(void)(parameter);
|
|
|
|
rb = api;
|
|
|
|
|
2005-02-10 21:28:21 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2005-07-12 23:57:06 +00:00
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
xlcd_init(rb);
|
|
|
|
#endif
|
2003-06-29 16:33:04 +00:00
|
|
|
rb->lcd_setfont(FONT_SYSFIXED);
|
2005-02-10 21:28:21 +00:00
|
|
|
#else
|
|
|
|
if (!pgfx_init(rb, 4, 2))
|
|
|
|
{
|
|
|
|
rb->splash(HZ*2, true, "Old LCD :(");
|
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|
2005-02-11 19:38:14 +00:00
|
|
|
pgfx_display(3, 0);
|
2005-02-10 21:28:21 +00:00
|
|
|
#endif
|
2002-10-29 10:45:29 +00:00
|
|
|
|
2002-10-15 07:17:50 +00:00
|
|
|
while(!exit)
|
|
|
|
{
|
2005-07-12 23:57:06 +00:00
|
|
|
if (highspeed)
|
2003-12-23 22:24:48 +00:00
|
|
|
rb->yield();
|
|
|
|
else
|
2003-06-29 16:33:04 +00:00
|
|
|
rb->sleep(4);
|
2005-02-10 21:28:21 +00:00
|
|
|
|
2005-07-13 20:40:46 +00:00
|
|
|
if (redraw)
|
|
|
|
{
|
|
|
|
MYLCD(clear_display)();
|
|
|
|
cube_rotate(xa, ya, za);
|
|
|
|
cube_viewport();
|
|
|
|
cube_draw();
|
|
|
|
redraw = false;
|
|
|
|
}
|
|
|
|
|
2005-02-10 21:28:21 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2005-07-13 20:40:46 +00:00
|
|
|
if (t_disp > 0)
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
|
|
|
t_disp--;
|
2005-02-11 19:38:14 +00:00
|
|
|
rb->snprintf(buffer, sizeof(buffer), "x:%d y:%d z:%d h:%d",
|
|
|
|
xs, ys, zs, highspeed);
|
2005-02-09 00:36:55 +00:00
|
|
|
rb->lcd_putsxy(0, LCD_HEIGHT-8, buffer);
|
2005-07-13 20:40:46 +00:00
|
|
|
if (t_disp == 0)
|
|
|
|
redraw = true;
|
2002-10-29 10:45:29 +00:00
|
|
|
}
|
2005-02-10 21:28:21 +00:00
|
|
|
#else
|
2005-07-13 20:40:46 +00:00
|
|
|
if (t_disp > 0)
|
2005-02-10 21:28:21 +00:00
|
|
|
{
|
2005-02-10 21:45:21 +00:00
|
|
|
if (t_disp == DISP_TIME)
|
|
|
|
{
|
2005-02-11 19:38:14 +00:00
|
|
|
rb->snprintf(buffer, sizeof(buffer), "x%d", xs);
|
2005-02-10 21:45:21 +00:00
|
|
|
rb->lcd_puts(0, 0, buffer);
|
2005-02-11 19:38:14 +00:00
|
|
|
rb->snprintf(buffer, sizeof(buffer), "y%d", ys);
|
2005-02-10 21:45:21 +00:00
|
|
|
rb->lcd_puts(0, 1, buffer);
|
2005-02-11 19:38:14 +00:00
|
|
|
pgfx_display(3, 0);
|
|
|
|
rb->snprintf(buffer, sizeof(buffer), "z%d", zs);
|
|
|
|
rb->lcd_puts(8, 0, buffer);
|
|
|
|
rb->snprintf(buffer, sizeof(buffer), "h%d", highspeed);
|
2005-02-10 21:45:21 +00:00
|
|
|
rb->lcd_puts(8, 1, buffer);
|
|
|
|
}
|
2005-02-10 21:28:21 +00:00
|
|
|
t_disp--;
|
2005-02-10 21:45:21 +00:00
|
|
|
if (t_disp == 0)
|
|
|
|
{
|
2005-02-11 19:38:14 +00:00
|
|
|
rb->lcd_clear_display();
|
|
|
|
pgfx_display(3, 0);
|
2005-02-10 21:45:21 +00:00
|
|
|
}
|
2005-02-10 21:28:21 +00:00
|
|
|
}
|
|
|
|
#endif
|
2005-07-01 16:22:15 +00:00
|
|
|
MYLCD(update)();
|
2005-02-09 00:36:55 +00:00
|
|
|
|
2005-07-13 20:40:46 +00:00
|
|
|
if (!paused)
|
|
|
|
{
|
|
|
|
xa += xs;
|
|
|
|
if (xa > 359)
|
|
|
|
xa -= 360;
|
|
|
|
if (xa < 0)
|
|
|
|
xa += 360;
|
|
|
|
ya += ys;
|
|
|
|
if (ya > 359)
|
|
|
|
ya -= 360;
|
|
|
|
if (ya < 0)
|
|
|
|
ya += 360;
|
|
|
|
za += zs;
|
|
|
|
if (za > 359)
|
|
|
|
za -= 360;
|
|
|
|
if (za < 0)
|
|
|
|
za += 360;
|
|
|
|
redraw = true;
|
|
|
|
}
|
2002-10-15 07:17:50 +00:00
|
|
|
|
2004-10-17 00:54:09 +00:00
|
|
|
button = rb->button_get(false);
|
2005-07-13 20:40:46 +00:00
|
|
|
switch (button)
|
2002-10-15 07:17:50 +00:00
|
|
|
{
|
2004-10-17 00:54:09 +00:00
|
|
|
case CUBE_X_INC:
|
2005-07-13 20:40:46 +00:00
|
|
|
if (xs < 10)
|
|
|
|
xs++;
|
|
|
|
t_disp = DISP_TIME;
|
2002-10-15 07:17:50 +00:00
|
|
|
break;
|
2005-07-13 20:40:46 +00:00
|
|
|
|
2004-10-17 00:54:09 +00:00
|
|
|
case CUBE_X_DEC:
|
2005-07-13 20:40:46 +00:00
|
|
|
if (xs > -10)
|
|
|
|
xs--;
|
|
|
|
t_disp = DISP_TIME;
|
2002-10-15 07:17:50 +00:00
|
|
|
break;
|
2005-07-13 20:40:46 +00:00
|
|
|
|
2004-10-17 00:54:09 +00:00
|
|
|
case CUBE_Y_INC:
|
2005-07-13 20:40:46 +00:00
|
|
|
if (ys < 10)
|
|
|
|
ys++;
|
|
|
|
t_disp = DISP_TIME;
|
2002-10-15 07:17:50 +00:00
|
|
|
break;
|
2005-07-13 20:40:46 +00:00
|
|
|
|
2004-10-17 00:54:09 +00:00
|
|
|
case CUBE_Y_DEC:
|
2005-07-13 20:40:46 +00:00
|
|
|
if (ys > -10)
|
|
|
|
ys--;
|
|
|
|
t_disp = DISP_TIME;
|
2002-10-15 07:17:50 +00:00
|
|
|
break;
|
2005-07-13 20:40:46 +00:00
|
|
|
|
2004-10-17 00:54:09 +00:00
|
|
|
case CUBE_Z_INC:
|
2005-07-13 20:40:46 +00:00
|
|
|
if (zs < 10)
|
|
|
|
zs++;
|
|
|
|
t_disp = DISP_TIME;
|
2002-10-15 07:17:50 +00:00
|
|
|
break;
|
2005-07-13 20:40:46 +00:00
|
|
|
|
2004-10-17 00:54:09 +00:00
|
|
|
case CUBE_Z_DEC:
|
2005-07-13 20:40:46 +00:00
|
|
|
if (zs > -10)
|
|
|
|
zs--;
|
|
|
|
t_disp = DISP_TIME;
|
2002-10-15 07:17:50 +00:00
|
|
|
break;
|
2005-07-13 20:40:46 +00:00
|
|
|
|
2005-07-12 23:57:06 +00:00
|
|
|
case CUBE_MODE:
|
2005-07-13 20:40:46 +00:00
|
|
|
#ifdef CUBE_MODE_PRE
|
|
|
|
if (lastbutton != CUBE_MODE_PRE)
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
if (++mode >= NUM_MODES)
|
|
|
|
mode = 0;
|
|
|
|
redraw = true;
|
2005-07-12 23:57:06 +00:00
|
|
|
break;
|
2005-07-13 20:40:46 +00:00
|
|
|
|
|
|
|
case CUBE_PAUSE:
|
|
|
|
#ifdef CUBE_PAUSE_PRE
|
|
|
|
if (lastbutton != CUBE_PAUSE_PRE)
|
|
|
|
break;
|
2005-07-12 23:57:06 +00:00
|
|
|
#endif
|
2005-07-13 20:40:46 +00:00
|
|
|
paused = !paused;
|
|
|
|
break;
|
|
|
|
|
2004-10-17 00:54:09 +00:00
|
|
|
case CUBE_HIGHSPEED:
|
|
|
|
#ifdef CUBE_HIGHSPEED_PRE
|
2005-07-13 20:40:46 +00:00
|
|
|
if (lastbutton != CUBE_HIGHSPEED_PRE)
|
2004-10-17 00:54:09 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2005-07-13 20:40:46 +00:00
|
|
|
highspeed = !highspeed;
|
|
|
|
t_disp = DISP_TIME;
|
2002-10-15 07:17:50 +00:00
|
|
|
break;
|
2005-07-13 20:40:46 +00:00
|
|
|
|
2004-10-17 00:54:09 +00:00
|
|
|
case CUBE_QUIT:
|
2005-07-13 20:40:46 +00:00
|
|
|
exit = true;
|
2002-10-15 07:17:50 +00:00
|
|
|
break;
|
2002-10-22 20:13:40 +00:00
|
|
|
|
2004-10-17 00:54:09 +00:00
|
|
|
default:
|
2005-07-13 20:40:46 +00:00
|
|
|
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
2005-02-11 19:38:14 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
|
|
|
pgfx_release();
|
|
|
|
#endif
|
2004-10-17 00:54:09 +00:00
|
|
|
return PLUGIN_USB_CONNECTED;
|
2005-02-11 19:38:14 +00:00
|
|
|
}
|
2004-10-17 00:54:09 +00:00
|
|
|
break;
|
2002-10-15 07:17:50 +00:00
|
|
|
}
|
2005-07-13 20:40:46 +00:00
|
|
|
if (button != BUTTON_NONE)
|
|
|
|
lastbutton = button;
|
2002-10-15 07:17:50 +00:00
|
|
|
}
|
2005-02-10 21:28:21 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
|
|
|
pgfx_release();
|
|
|
|
#endif
|
2002-10-29 10:45:29 +00:00
|
|
|
|
2003-06-29 16:33:04 +00:00
|
|
|
return PLUGIN_OK;
|
2002-10-15 07:17:50 +00:00
|
|
|
}
|
|
|
|
|