/* * Copyright (C) 2002 Clemens Fuchslocher * * TiCube3D - 01.07.2002 - v0.1 - first public release * * zero:~$ tigcc -Wall TiCube3D.c * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * */ #define SAVE_SCREEN #define USE_TI89 #define USE_TI92PLUS #include #define PERIOD 197 /* T=2*pi/w, w=1/10*pi */ float sin_table[PERIOD]; float cos_table[PERIOD]; void _main (void) { int cube[] = { -20, -20, -20, 20, -20, -20, 20, 20, -20, -20, 20, -20, -20, -20, 20, 20, -20, 20, 20, 20, 20, -20, 20, 20 }; int dots[16]; int x1, y1, z1; int x_t, y_t, z_t; int phi, e, i; char *offscreen = malloc (LCD_SIZE); ClrScr (); DrawStr ((LCD_WIDTH / 2) - 48, (LCD_HEIGHT / 2) - 3, "", A_NORMAL); FontSetSys (F_4x6); DrawStr (1, LCD_HEIGHT - 7, "(c) 2002 Clemens Fuchslocher", A_NORMAL); for (phi = 0; phi < PERIOD; phi++) { sin_table[phi] = sin (phi / (10 * 3.14)); cos_table[phi] = cos (phi / (10 * 3.14)); } PortSet (offscreen, 239, 127); phi = 0; do { float cos = cos_table[phi]; float sin = sin_table[phi]; memset (offscreen, 0, LCD_SIZE); phi += 2; phi %= PERIOD; i = 0; for (e = 0; e < 24;) { x1 = cube[e++]; y1 = cube[e++]; z1 = cube[e++]; /* * Mathematische Formelsammlung, Lothar Papula, 5. Auflage * 9.1.3.3 Drehung eines kartesischen Koordinatensystems */ /* Rotation um Y Achse */ y_t = (y1 * cos + z1 * -sin); z_t = (y1 * sin + z1 * cos); y1 = y_t; z1 = z_t; /* Rotation um X Achse */ y_t = (y1 * cos + z1 * -sin); z_t = (y1 * sin + z1 * cos); y1 = y_t; z1 = z_t; /* Rotation um Z Achse */ x_t = (x1 * cos + y1 * -sin); y_t = (x1 * sin + y1 * cos); x1 = x_t; y1 = y_t; /* 3D -> 2D Projektion, MC Extra 3/95 */ dots[i++] = 60 * x1 / (z1 - 80) + LCD_WIDTH / 2; dots[i++] = 60 * y1 / (z1 - 80) + LCD_HEIGHT / 2; } DrawLine (dots[0], dots[1], dots[2], dots[3], A_NORMAL); DrawLine (dots[0], dots[1], dots[6], dots[7], A_NORMAL); DrawLine (dots[6], dots[7], dots[4], dots[5], A_NORMAL); DrawLine (dots[4], dots[5], dots[2], dots[3], A_NORMAL); DrawLine (dots[4], dots[5], dots[12], dots[13], A_NORMAL); DrawLine (dots[6], dots[7], dots[14], dots[15], A_NORMAL); DrawLine (dots[12], dots[13], dots[14], dots[15], A_NORMAL); DrawLine (dots[8], dots[9], dots[10], dots[11], A_NORMAL); DrawLine (dots[0], dots[1], dots[8], dots[9], A_NORMAL); DrawLine (dots[10], dots[11], dots[2], dots[3], A_NORMAL); DrawLine (dots[10], dots[11], dots[12], dots[13], A_NORMAL); DrawLine (dots[14], dots[15], dots[8], dots[9], A_NORMAL); LCD_restore (offscreen); } while (!kbhit ()); ngetchx (); PortRestore (); free (offscreen); }