All pastes #246427 Raw Edit

Unnamed

public text v1 · immutable
#246427 ·published 2006-11-12 05:20 UTC
rendered paste body
#include <tigcclib.h> 

#define DISTORTION 80

typedef struct
{

    int x;
    int y;
    int z;
  
} _3DPoint;

 
typedef struct
{

    int x;
    int y;
      
} _2DPoint;



/* to join the corners of a cube */
int cube_lines [12] [2] = { {0,1} , {1,2} , {2,3} , {3,0} , {4,5} , {5,6} , {6,7} , {7,4},      
			    {0,4} , {1,5} , {2,6} , {3,7} } ; 

/* ti 89 */
_2DPoint screen_center= { 80 , 50 };

LCD_BUFFER screen;

int _ti89;





void xexit(const char *msg)
{
	LCD_restore(screen);
	if(msg)
		ST_helpMsg(msg);
	exit(1);
}


void draw_cube(_3DPoint cube[8], _3DPoint camera)
{
	
	_2DPoint s_cube[8];   /* the cube in 2d */
	_3DPoint tmp;
	short i,j;

	for (i=0 ; i < 8 ; i++) {

		
		tmp.x = cube[i].x - camera.x;
		tmp.y = cube[i].y - camera.y;
		tmp.z = cube[i].z - camera.z;
		
		/* cconvert the points in 2D */

		if(tmp.z == 0)
			xexit("tmp.z == 0");

		s_cube[i].x = screen_center.x + (DISTORTION * tmp.x )/ tmp.z ;
		s_cube[i].y = screen_center.y - (DISTORTION * tmp.y )/ tmp.z ;
	}

	/* draw the lines */
	for (j=0 ; j < 12; j++) {
		DrawLine( s_cube[ cube_lines[j][0] ].x, s_cube[ cube_lines[j][0] ].y, \
			  s_cube[ cube_lines[j][1] ].x, s_cube[ cube_lines[j][1] ].y, \
			  A_NORMAL );
	}

}



void _main(void)
{
	
	LCD_save(screen);

	ClrScr();

	_3DPoint cube [8] = { {-10,-10,-10},{10,-10,-10},{10,10,-10},{-10,10,-10},
			    {-10,-10,10}, {10,-10,10}, {10,10,10},{-10,10,10} };

	_3DPoint camera = {0,0,40};

	draw_cube(cube, camera);
	ngetchx();
	ClrScr();


	camera.x=2;
	camera.y=5;
	draw_cube(cube, camera);
	ngetchx();
	ClrScr();

	camera.x=-2;
	camera.y=-5;
	draw_cube(cube, camera);
	ngetchx();
	ClrScr();


        LCD_restore(screen);
}