Mercurial > hg > forks > pwpunix
view final_isi/3d.c @ 69:c13a2f8c5b10
Rename files and some minor cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 01 Jun 2012 17:41:15 +0300 |
parents | final_isi/fisi3d.c@53676367d46f |
children | e76a4e19363d |
line wrap: on
line source
#include "wrapper.h" /*****/ char txr_wsygn[16*16]={ /* syaani/sininen. hieno. parempi keltapunas„vyiss„? */ 0x11,0x19,0x97,0x97,0x97,0x11,0x11,0x11,0x79,0x97,0x97,0x97,0x11,0x11,0x11,0x11, 0x11,0x79,0x97,0x97,0x97,0x79,0x19,0x11,0x79,0x97,0x97,0x97,0x11,0x19,0x11,0x11, 0x11,0x11,0x91,0x97,0x97,0x97,0x19,0x11,0x19,0x97,0x97,0x97,0x79,0x19,0x11,0x11, 0x11,0x19,0x79,0x97,0x97,0x97,0x19,0x11,0x11,0x91,0x97,0x97,0x97,0x19,0x11,0x11, 0x11,0x91,0x97,0x97,0x97,0x91,0x11,0x11,0x19,0x79,0x97,0x97,0x97,0x79,0x11,0x11, 0x11,0x19,0x97,0x77,0x97,0x11,0x11,0x11,0x19,0x97,0x97,0x97,0x91,0x19,0x11,0x11, 0x11,0x79,0x97,0x97,0x97,0x97,0x79,0x19,0x11,0x97,0x97,0x97,0x79,0x19,0x11,0x11, 0x11,0x11,0x91,0x97,0x77,0x97,0x19,0x11,0x11,0x91,0x97,0x97,0x97,0x79,0x10,0x10, 0x11,0x11,0x11,0x97,0x77,0x97,0x19,0x11,0x11,0x11,0x97,0x77,0x97,0x11,0x11,0x10, 0x11,0x19,0x79,0x97,0x97,0x97,0x19,0x11,0x19,0x79,0x97,0x97,0x97,0x19,0x11,0x10, 0x11,0x19,0x97,0x97,0x97,0x91,0x11,0x11,0x19,0x97,0x97,0x97,0x91,0x19,0x11,0x10, 0x11,0x19,0x97,0x77,0x97,0x11,0x11,0x11,0x11,0x97,0x77,0x97,0x79,0x19,0x11,0x11, 0x11,0x79,0x97,0x97,0x97,0x79,0x19,0x11,0x10,0x97,0x97,0x97,0x97,0x19,0x11,0x11, 0x11,0x11,0x91,0x97,0x97,0x97,0x19,0x11,0x19,0x79,0x97,0x97,0x97,0x11,0x11,0x11, 0x11,0x19,0x79,0x97,0x97,0x97,0x19,0x11,0x19,0x97,0x97,0x97,0x91,0x19,0x11,0x11, 0x11,0x79,0x97,0x97,0x97,0x79,0x19,0x11,0x79,0x97,0x97,0x97,0x79,0x19,0x11,0x10 }; char txr_dunneon[16*16]={ /* neonjuovia. k„ytett„v„. */ 0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x00,0x08,0x80,0x80,0x08,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x80, 0x80,0x80,0x08,0x00,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x00,0x08,0x80,0x80,0x00,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x08,0x80,0x80,0x08,0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x08,0x80,0x80,0x08,0x00,0x80,0x80,0x80,0x00,0x08,0x80,0x80,0x80, 0x80,0x80,0x08,0x00,0x80,0x80,0x08,0x00,0x80,0x80,0x80,0x00,0x08,0x80,0x80,0x80, 0x80,0x80,0x08,0x00,0x80,0x80,0x08,0x08,0x80,0x80,0x80,0x08,0x08,0x80,0x80,0x80, 0x80,0x80,0x08,0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x80, 0x80,0x80,0x08,0x00,0x08,0x80,0x80,0x08,0x80,0x80,0x80,0x00,0x08,0x80,0x80,0x80, 0x80,0x80,0x80,0x00,0x08,0x80,0x80,0x08,0x80,0x80,0x08,0x00,0x08,0x80,0x80,0x80, 0x80,0x80,0x08,0x00,0x80,0x80,0x80,0x08,0x80,0x80,0x08,0x08,0x08,0x80,0x80,0x80, 0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x00,0x08,0x80,0x80,0x80, 0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x80 }; char txr_unneon[16*16]={ 0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x78, 0x78,0x78,0x78,0x00,0x07,0x78,0x78,0x07,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x78, 0x78,0x78,0x07,0x00,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x78, 0x78,0x78,0x78,0x00,0x07,0x78,0x78,0x00,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x78, 0x78,0x78,0x78,0x07,0x78,0x78,0x07,0x00,0x78,0x78,0x78,0x00,0x78,0x78,0x78,0x78, 0x78,0x78,0x78,0x07,0x78,0x78,0x07,0x00,0x78,0x78,0x78,0x00,0x07,0x78,0x78,0x78, 0x78,0x78,0x07,0x00,0x78,0x78,0x07,0x00,0x78,0x78,0x78,0x00,0x07,0x78,0x78,0x78, 0x78,0x78,0x07,0x00,0x78,0x78,0x07,0x07,0x78,0x78,0x78,0x07,0x07,0x78,0x78,0x78, 0x78,0x78,0x07,0x00,0x78,0x78,0x78,0x00,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x78, 0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x78, 0x78,0x78,0x78,0x00,0x78,0x78,0x78,0x00,0x78,0x78,0x78,0x00,0x78,0x78,0x78,0x78, 0x78,0x78,0x07,0x00,0x07,0x78,0x78,0x07,0x78,0x78,0x78,0x00,0x07,0x78,0x78,0x78, 0x78,0x78,0x78,0x00,0x07,0x78,0x78,0x07,0x78,0x78,0x07,0x00,0x07,0x78,0x78,0x78, 0x78,0x78,0x07,0x00,0x78,0x78,0x78,0x07,0x78,0x78,0x07,0x07,0x07,0x78,0x78,0x78, 0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x00,0x07,0x78,0x78,0x78, 0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x78 }; char txr_neon[16*16]={ 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x5c,0x04,0x00,0x00,0x40,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00, 0x00,0x00,0x04,0x5c,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x5c,0x04,0x00,0x00,0x5c,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x40,0x00,0x00,0x04,0x5c,0x00,0x00,0x00,0x5c,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x40,0x00,0x00,0x04,0x5c,0x00,0x00,0x00,0x5c,0x04,0x00,0x00,0x00, 0x00,0x00,0x04,0x5c,0x00,0x00,0x04,0x5c,0x00,0x00,0x00,0x5c,0x04,0x00,0x00,0x00, 0x00,0x00,0x04,0x5c,0x00,0x00,0x04,0x40,0x00,0x00,0x00,0x40,0x04,0x00,0x00,0x00, 0x00,0x00,0x04,0x5c,0x00,0x00,0x00,0x5c,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x5c,0x00,0x00,0x00,0x5c,0x00,0x00,0x00,0x5c,0x00,0x00,0x00,0x00, 0x00,0x00,0x04,0x5c,0x04,0x00,0x00,0x40,0x00,0x00,0x00,0x5c,0x04,0x00,0x00,0x00, 0x00,0x00,0x00,0x5c,0x04,0x00,0x00,0x40,0x00,0x00,0x04,0x5c,0x04,0x00,0x00,0x00, 0x00,0x00,0x04,0x5c,0x00,0x00,0x00,0x04,0x00,0x00,0x04,0x40,0x04,0x00,0x00,0x00, 0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x5c,0x04,0x00,0x00,0x00, 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00 }; char txr_gslime[16*16]={ 0x88,0x80,0x00,0x80,0x80,0x88,0x88,0x88,0x80,0x08,0x00,0x00,0x08,0x88,0x80,0x00, 0x80,0x08,0x00,0x08,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x80,0x88,0x80,0x08,0x00, 0x08,0x00,0x00,0x00,0x08,0x08,0x80,0x00,0x00,0x00,0x08,0x80,0x80,0x00,0x00,0x88, 0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x80,0x00,0x08,0x88,0x80, 0x00,0x08,0x80,0x08,0x00,0x00,0x08,0x88,0x88,0x88,0x00,0x80,0x00,0x08,0x80,0x00, 0x08,0x80,0x80,0x08,0x00,0x08,0x80,0x88,0x88,0x88,0x08,0x80,0x00,0x00,0x00,0x08, 0x88,0x88,0x88,0x80,0x00,0x08,0x80,0x88,0x88,0x88,0x80,0x80,0x00,0x00,0x08,0x80, 0x88,0x88,0x80,0x80,0x00,0x00,0x08,0x80,0x80,0x08,0x00,0x00,0x00,0x80,0x88,0x88, 0x88,0x88,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x88,0x88, 0x80,0x80,0x00,0x00,0x08,0x08,0x00,0x00,0x08,0x80,0x80,0x80,0x80,0x80,0x08,0x88, 0x08,0x00,0x08,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x08,0x08,0x80,0x80,0x08,0x88, 0x80,0x80,0x80,0x80,0x08,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x80, 0x88,0x88,0x88,0x88,0x88,0x80,0x80,0x80,0x08,0x08,0x00,0x00,0x08,0x08,0x00,0x80, 0x88,0x88,0x88,0x88,0x88,0x80,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00, 0x88,0x88,0x88,0x08,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x00,0x00,0x80,0x80,0x00, 0x88,0x08,0x00,0x00,0x00,0x00,0x08,0x08,0x80,0x80,0x80,0x08,0x00,0x88,0x80,0x80 }; char txr_slime[16*16]={ /* vihre„ laikukas. hienokiva. */ 0x22,0x20,0x00,0x20,0x20,0x22,0x22,0x22,0x20,0x02,0x00,0x00,0x02,0x22,0x20,0x00, 0x20,0x02,0x00,0x02,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0x20,0x22,0x20,0x02,0x00, 0x02,0x00,0x00,0x00,0x02,0x02,0x20,0x00,0x00,0x00,0x02,0x20,0x20,0x00,0x00,0x22, 0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x20,0x00,0x02,0x22,0x20, 0x00,0x02,0x20,0x02,0x00,0x00,0x02,0x22,0x22,0x22,0x00,0x20,0x00,0x02,0x20,0x00, 0x02,0x20,0x20,0x02,0x00,0x02,0x20,0x22,0x22,0x22,0x02,0x20,0x00,0x00,0x00,0x02, 0x22,0x22,0x22,0x20,0x00,0x02,0x20,0x22,0x22,0x22,0x20,0x20,0x00,0x00,0x02,0x20, 0x22,0x22,0x20,0x20,0x00,0x00,0x02,0x20,0x20,0x02,0x00,0x00,0x00,0x20,0x22,0x22, 0x22,0x22,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x02,0x22,0x22, 0x20,0x20,0x00,0x00,0x02,0x02,0x00,0x00,0x02,0x20,0x20,0x20,0x20,0x20,0x02,0x22, 0x02,0x00,0x02,0x20,0x20,0x20,0x00,0x00,0x00,0x00,0x02,0x02,0x20,0x20,0x02,0x22, 0x20,0x20,0x20,0x20,0x02,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x20, 0x22,0x22,0x22,0x22,0x22,0x20,0x20,0x20,0x02,0x02,0x00,0x00,0x02,0x02,0x00,0x20, 0x22,0x22,0x22,0x22,0x22,0x20,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00, 0x22,0x22,0x22,0x02,0x00,0x00,0x00,0x00,0x02,0x02,0x02,0x00,0x00,0x20,0x20,0x00, 0x22,0x02,0x00,0x00,0x00,0x00,0x02,0x02,0x20,0x20,0x20,0x02,0x00,0x22,0x20,0x20 }; typedef struct{signed int x,z,y;}xyz; typedef struct{signed int a,r,y;}cyl; typedef struct{int p[3]; int nn; char*txrf,*txrb;}face; typedef struct{ int numvxes; cyl*vxes; xyz*rotated; int numfaces; face*faces; }obj3d; #define sint signed int /** XWING **/ /* xyz cube_vxes[]={ -6000,-1000,2000, -6000,-1000,-2000, 6000,-1000,2000, 6000,-1000,-2000, -1500,2000,0, -1500,-1000,0, 1500,2000,0, 1500,-100,0, 0,2500,0, 0,1000,-1500 }; face cube_faces[]={ 0,4,5, 0, txr_wsygn,txr_dunneon, 1,5,4, 0, txr_wsygn,txr_dunneon, 2,7,6, 0, txr_wsygn,txr_dunneon, 3,6,7, 0, txr_wsygn,txr_dunneon, 9,8,4, 0, txr_wsygn,NULL, 9,7,8, 0, txr_wsygn,NULL, 9,4,5, 0, txr_unneon,NULL, 9,7,6, 0, txr_unneon,NULL, 9,5,6, 0, txr_unneon,NULL }; */ /********/ /********/ cyl xwing_vxes[]={ 134,6082,1000, 134,6082,-1000, 250,6082,1000, 250,6082,-1000, 91,3000,0, /* 2500 */ 151,1802,0, 37,3000,0, /* 2500 */ 254,1503,0, 64,2500,0, 64,1000,-750 }; face xwing_faces[]={ 4,5,0, 0, txr_wsygn,txr_dunneon, 1,5,4, 0, txr_wsygn,txr_dunneon, 7,6,2, 0, txr_wsygn,txr_dunneon, 3,6,7, 0, txr_wsygn,txr_dunneon, 9,8,4, 0, txr_wsygn,NULL, 9,7,8, 0, txr_wsygn,NULL, 9,4,5, 0, txr_unneon,NULL, 9,7,6, 0, txr_unneon,NULL, 9,5,6, 0, txr_unneon,NULL }; obj3d xwing={ 10,xwing_vxes,NULL,9,xwing_faces }; cyl bugi_vxes[]={ 96,2828,0, 32,2828,0, 224,2828,0, 160,2828,0, 0,0,-800, 45,6708,1000, 238,6708,1000, 173,6708,1000, 110,6708,1000 }; face bugi_faces[]={ 4,1,0, 0, txr_slime,NULL, 4,2,1, 0, txr_slime,NULL, 4,3,2, 0, txr_slime,NULL, 4,0,3, 0, txr_slime,NULL, 0,1,5, 0, txr_slime,txr_gslime, 1,2,6, 0, txr_slime,txr_gslime, 2,3,7, 0, txr_slime,txr_gslime, 3,0,8, 0, txr_slime,txr_gslime }; obj3d bugi={ 9,bugi_vxes,NULL,8,bugi_faces }; obj3d obu; #include "sini16.h" sint dvhtab[50]; sint dutab[320]; eggine_init() { int i; dvhtab[0]=32760; for(i=1;i<50;i++)dvhtab[i]=4096/i; dutab[0]=32760; for(i=1;i<320;i++)dutab[i]=(64*256)/i; } eggine_load(sint n) { obj3d*o; if(!n)o=&xwing;else o=&bugi; if(o->rotated==NULL) o->rotated=malloc(o->numvxes*sizeof(xyz)); memcpy(&obu,o,sizeof(obu)); } extern int polytxloop (sint h,char*di,unsigned int x1,sint dx0,sint dx1,char*txr, sint dv,sint du); sint polytxr( char*buf, sint y,sint h,sint x0,sint x1,sint dx0,sint dx1, char*txr){ register sint du; char joo=0; if(y+h>=50)h=49-y; if(h>0)if(y>=0){ if((x0>x1)||((x0==x1)&&(dx0>dx1))) {sint tmp=x0;x0=x1;x1=tmp; tmp=dx0;dx0=dx1;dx1=tmp; joo=1;} x1-=x0;dx1-=dx0; du=x1>>6; if(!du)du=((dx1-dx0)*h) >>6; /* dx1-dx0?? */ if(du)du=(64*256)/du;/*dutab[du];*/ x1=polytxloop(h,buf+80*y+(x0>>8), x1, dx0, dx1, txr, dvhtab[h], du); return (!joo)?x0+x1+h*dx0:x1; } } /*******************************/ extern signed int mul32(signed int a,signed int b); #define jmul32(a,b) (((long)(a)*(long)(b))>>16) eggine_do(char*b,sint rot,int zoom,int basex,int basey) { register sint i; sint j; sint fzed[20],fcez[20]; if(obu.faces==bugi_faces){ bugi_vxes[5].y=bugi_vxes[6].y= 1000+mul32(700,sini16[(taimeri*13)&255]); bugi_vxes[7].y=bugi_vxes[8].y= 1000+mul32(700,sini16[(taimeri*7)&255]); } /***** rotate vertices *****/ {cyl*v=obu.vxes;xyz*r=obu.rotated; for(i=obu.numvxes;i;i--) { r->y=mul32(v->y,zoom)+basey; r->x=mul32(mul32(v->r,sini16[(rot+v->a)&255]),zoom)+basex; r->z=mul32(mul32(v->r,sini16[(rot+v->a+64)&255]),zoom); r++;v++; }} /***** calc facezeds, sort faces *****/ {sint *t=fzed;face*f=obu.faces; for(i=obu.numfaces;i;i--){ *t++=obu.rotated[f->p[0]].z+ obu.rotated[f->p[1]].z+ obu.rotated[f->p[2]].z; f++; }} {sint *t=fcez;sint j=0; for(i=obu.numfaces;i;i--)*t++=j++; } /* stupid bubblesort */ for(i=0;i<obu.numfaces-1;i++){ sint min=fzed[i],where=i; for(j=i+1;j<obu.numfaces;j++){ if(fzed[j]<min){min=fzed[j];where=j;} } {sint tmp=fzed[i];fzed[i]=fzed[where];fzed[where]=tmp;} {sint tmp=fcez[i];fcez[i]=fcez[where];fcez[where]=tmp;} } /***** draw faces *****/ {sint*fc=fcez; for(i=obu.numfaces;i;i--) { face*f=&obu.faces[*fc++]; { sint x0,x1,x2,y0,y1,y2,nz; char*txr; /***************************************/ {xyz*tmp=obu.rotated; x0=tmp[f->p[0]].x<<3; y0=tmp[f->p[0]].y>>5; x1=tmp[f->p[1]].x<<3; y1=tmp[f->p[1]].y>>5; x2=tmp[f->p[2]].x<<3; y2=tmp[f->p[2]].y>>5; } nz=((x1-x0)>>8)*(y2-y0)-((x2-x0)>>8)*(y1-y0); if(nz<0)txr=f->txrf;else txr=f->txrb; if(txr!=NULL) { if(y0!=y2){ sint tmpk,tmpx2; if (y0!=y1) tmpx2=polytxr(b,y0,y1-y0,x0,x0, (x1-x0)/(y1-y0), tmpk=(x2-x0)/(y2-y0), txr); else {tmpk=(x2-x0)/(y2-y0);tmpx2=x0;} if (y1!=y2) polytxr(b,y1,y2-y1,x1,tmpx2, (x2-x1)/(y2-y1), tmpk, txr); } } /***************************************/ } }}/* end drawfaces*/ }