/* * Project: Triangles * Copyright (c) 1994 Sega of America, Inc. * All Rights Reserved. * * File: icos.c * Description: Triangle routines * Authors: jef * Start Date: ? * Revision History: * */ #include #include #include "shmath.h" #include "icos.h" #include "logger.h" #include "demo.h" #include "poly.h" #include "util.h" #include "shmatrix.h" XYZ icosVerts[NUM_ICOS_VERTS] = { /* 0 */ FIXED(-1.612335), FIXED(0.847656), FIXED(-0.525696), /* 1 */ FIXED(-0.006317), FIXED(0.846497), FIXED(-1.691437), /* 2 */ FIXED(0.003357), FIXED(1.894257), FIXED(-0.001343), /* 3 */ FIXED(-1.002960), FIXED(-0.847656), FIXED(-1.369446), /* 4 */ FIXED(1.610870), FIXED(0.846497), FIXED(-0.519562), /* 5 */ FIXED(-0.988831), FIXED(0.847382), FIXED(1.365845), /* 6 */ FIXED(1.002960), FIXED(0.847656), FIXED(1.369446), /* 7 */ FIXED(-1.610870), FIXED(-0.846497), FIXED(0.519562), /* 8 */ FIXED(0.988831), FIXED(-0.847382), FIXED(-1.365845), /* 9 */ FIXED(1.612335), FIXED(-0.847656), FIXED(0.525696), /*10 */ FIXED(0.006317), FIXED(-0.846497), FIXED(1.691437), /*11 */ FIXED(-0.003357), FIXED(-1.894257), FIXED(0.001343), }; Card16 icosFaces[NUM_ICOS_FACES][3] = { 11, 3, 8, /* face 1 */ 11, 8, 9, /* face 2 */ 11, 9, 10, /* face 3 */ 11, 10, 7, /* face 4 */ 11, 7, 3, /* face 5 */ 1, 8, 3, /* face 6 */ 4, 9, 8, /* face 7 */ 6, 10, 9, /* face 8 */ 5, 7, 10, /* face 9 */ 0, 3, 7, /* face 10 */ 3, 0, 1, /* face 11 */ 8, 1, 4, /* face 12 */ 9, 4, 6, /* face 13 */ 10, 6, 5, /* face 14 */ 7, 5, 0, /* face 15 */ 2, 1, 0, /* face 16 */ 2, 4, 1, /* face 17 */ 2, 6, 4, /* face 18 */ 2, 5, 6, /* face 19 */ 2, 0, 5, /* face 20 */ }; void icosInit( void ) { LOG( BEGIN, icosInit, 0); LOG( END, icosInit, 0); } void icosCreate( Icosahedron *poly, Fixed32 centerX, Fixed32 centerY, Fixed32 centerZ, Fixed32 faceLength ) { int i; Sint16 j = 0; LOG( BEGIN, icosCreate, poly); /* center of rotation */ poly->centerX = centerX; poly->centerY = centerY; poly->centerZ = centerZ; poly->faceLength = faceLength / 2; /* faces 1-20 */ for (i=0; i< NUM_ICOS_FACES; ++i ) { poly->faces[i].color = colors[i]; } /* vertices 1-12 */ for (i=0; i< NUM_ICOS_VERTS; ++i ) { poly->vert[i].x = MUL_FIXED(poly->faceLength, icosVerts[i].x); poly->vert[i].y = MUL_FIXED(poly->faceLength, icosVerts[i].y); poly->vert[i].z = MUL_FIXED(poly->faceLength, icosVerts[i].z); } LOG( END, icosCreate, poly); } void icosXformVert( Icosahedron *poly ) { int i; for (i=0; ivert[i], &poly->xformVert[i] ); } } void icosParProj( Icosahedron * poly ) { int i; for (i=0; iprojVert[i].x = fixedToInt( poly->xformVert[i].x ) + CENTER_X; poly->projVert[i].y = fixedToInt( poly->xformVert[i].y ) + CENTER_Y; } } #define PPD 256 void icosPerProj( Icosahedron *poly ) { int i; char buf[64]; for (i=0; iprojVert[i].x = fixedToInt( FixedMul( FixedDiv( poly->xformVert[i].x, poly->xformVert[i].z), intToFixed( PPD ) ) ) + CENTER_X; poly->projVert[i].y = fixedToInt( FixedMul( FixedDiv( poly->xformVert[i].y, poly->xformVert[i].z), intToFixed( PPD ) ) ) + CENTER_Y; #if 0 sprintf(buf, "%d %d, %d\n", fixedToInt(poly->xformVert[i].y), (poly->projVert[i].x), (poly->projVert[i].y)); Print8( 1, i+1, buf ); #endif } } void icosCalcFace( Icosahedron *poly ) { int i; for (i=0; ifaces[i].v[0].x = (poly->projVert[(icosFaces[i][0])].x); poly->faces[i].v[0].y = (poly->projVert[(icosFaces[i][0])].y); poly->faces[i].v[1].x = (poly->projVert[(icosFaces[i][1])].x); poly->faces[i].v[1].y = (poly->projVert[(icosFaces[i][1])].y); poly->faces[i].v[2].x = (poly->projVert[(icosFaces[i][2])].x); poly->faces[i].v[2].y = (poly->projVert[(icosFaces[i][2])].y); } } void icosMove( Icosahedron *poly ) { icosXformVert( poly ); icosPerProj( poly ); icosCalcFace( poly ); } void icosDraw( Icosahedron *poly ) { int i; int flag = 1; for (i=0; ifaces[i]) ) { cTriFill( &poly->faces[i], poly->faces[i].color ); } } }