X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=plzpart%2Fvect.c;fp=plzpart%2Fvect.c;h=5a581f44b99332eca1883389f229b77468ba3f5d;hb=21358d1282235770140bc4e2941609122472108d;hp=0000000000000000000000000000000000000000;hpb=fa27309a14377e36db2fd562ae47a3aa071f298b;p=plz.git diff --git a/plzpart/vect.c b/plzpart/vect.c new file mode 100755 index 0000000..5a581f4 --- /dev/null +++ b/plzpart/vect.c @@ -0,0 +1,308 @@ +#include +//#include +//#include +#include +//#include +#include +#include "tweak.h" +#include "../dis/dis.h" + +#define SX sinit[kx] +#define SY sinit[ky] +#define SZ sinit[kz] +#define CX kosinit[kx] +#define CY kosinit[ky] +#define CZ kosinit[kz] + +extern far char (* far vmem)[160]; +extern char far pal[768]; + +extern void clear(); +//extern init(); +extern void shadepal(char far *fpal, char far *ppal, int shade); +extern int init_copper(); +extern int close_copper(); +extern int far cop_rotatev; +extern far int frame_count; +extern far char * far cop_pal; +extern far int do_pal; +extern far int cop_start; +extern far int cop_scrl; + +extern int do_poly(); +extern int getspl(int where); +extern int far sinit[1024]; +extern int far kosinit[1024]; + +char far fpal[768]; + +struct object { + char name[100]; + + int pnts; + struct points_3d { + int x; + int y; + int z; + int xx; + int yy; + int zz; + int xxx; + int yyy; + } point[256]; + + int faces; + struct polygon { + int p1; + int p2; + int p3; + int p4; + int p5; + int p6; + int n; + int color; + } pg[256]; + + int lines; + struct lines { + int p1; + int p2; + int n; + int col; + } lin[256]; + } object={ + "Cube", + 8, // points + { + {125,125,125}, + {125,-125,125}, + {-125,-125,125}, + {-125,125,125}, + {125,125,-125}, + {125,-125,-125}, + {-125,-125,-125}, + {-125,125,-125}, + }, + 6, // faces + { + {1,2,3,0,0,0,0,0}, + {7,6,5,4,0,0,0,0}, + {0,4,5,1,0,0,0,1}, + {1,5,6,2,0,0,0,2}, + {2,6,7,3,0,0,0,1}, + {3,7,4,0,0,0,0,2}} + }; + +struct polygons_to_draw { + int p; + int dis; + } ptodraw[256]; +int polys=0; + +int light_src[6]={0}; +int lls[6]={0}; + +int cxx, cxy, cxz, cyx, cyy, cyz, czx, czy, czz; +int kx=0,ky=0,kz=0,dis=320,tx=0,ty=-50; +int ls_kx=0,ls_ky=0,ls_kz=0,ls_x=0,ls_y=0,ls_z=128; +int page=0; +int frames=0; + +void sort_faces(void); +void draw(int); +void swappage(void); +void rotate(void); +void count_const(void); +void calculate(int); + +void vect() + { + int /*c=0,*/a; + + tw_opengraph(); + + //while(dis_musplus()<13 && !dis_exit()); + frame_count=0; + while(!dis_exit()) + { + a=dis_musplus(); + if(a>=-4 && a<0) break; + swappage(); + while(frame_count<1); frames+=frame_count; frame_count=0; + cop_pal=fpal; do_pal=1; + + calculate(1); + draw(15); + clear(); + } +// tw_closegraph(); + } + +void calculate(int k) + { + //int a; + //static int px=0,py=256; + + getspl(4*256+frames*4); + kx=kx&1023; + ky=ky&1023; + kz=kz&1023; + ls_kx=ls_kx&1023; + ls_ky=ls_ky&1023; + + ls_y=kosinit[ls_kx]>>8; + ls_x=(sinit[ls_kx]>>8)*(sinit[ls_ky]>>8)>>7; + ls_z=(sinit[ls_kx]>>8)*(kosinit[ls_ky]>>8)>>7; + + count_const(); + rotate(); + sort_faces(); + } + +void count_const() + { + //matrix equations: + //X Y Z -> nX + //X Y Z -> nY + //X Y Z -> nZ + // + // 0=Ycos*Zcos 2=Ycos*Zsin 4=-Ysin + // 6=Xsin*Zcos*Ysin 8=Xsin*Ysin*Zsin 10=Ycos*Xsin + // -Xcos*Zsin +Xcos*Zcos + //12=Xcos*Zcos*Ysin 14=Xcos*Ysin*Zsin 16=Ycos*Xcos + // +Xsin*Zsin -Xsin*Zcos + + cxx=CY*CZ>>(15+7); + cxy=CY*SZ>>(15+7); + cxz=-SY>>7; + + cyx=(((SX*CZ+16384L)>>15)*SY - CX*SZ)>>(15+7); + cyy=(((SX*SY+16384L)>>15)*SZ + CX*CZ)>>(15+7); + cyz=CY*SX>>(15+7); + + czx=(((CX*CZ+16384L)>>15)*SY + SX*SZ)>>(15+7); + czy=(((CX*SY+16384L)>>15)*SZ - SX*CZ)>>(15+7); + czz=CY*CX>>(15+7); + + } + +void rotate() + { + int a,/*b,*/x,y,z,xx,yy,zz; + + for(a=0;a>1) + (y*cxy>>1) + (z*cxz>>1))>>7)+tx; + object.point[a].yy=yy=(((x*cyx>>1) + (y*cyy>>1) + (z*cyz>>1))>>7)+ty; + object.point[a].zz=zz=(((x*czx>>1) + (y*czy>>1) + (z*czz>>1))>>7)+dis; + +/* + 1000,1000,1000 + + x*256, y*213, / ( +*/ + + object.point[a].xxx=(xx*256L)/zz+160+160; + object.point[a].yyy=(yy*142L)/zz+66; + } + } + +void sort_faces() + { + int a=0,/*b,*/c,x,y,z,p=0; + long ax,ay,az,bx,by,bz,/*kx,ky,kz,*/nx,ny,nz,s/*,l*/; + + while(a0) { a++; continue; } + + s=(ls_x*nx+ls_y*ny+ls_z*nz)/250000+32; + light_src[p]=s; + c=object.pg[a].color; + if(lls[p]!=light_src[p]) + { + shadepal(&fpal[c*64*3],&pal[c*64*3], light_src[p]); + lls[p]=light_src[p]; + } + + ptodraw[p++].p=a++; + } + polys=p; + } + + +void draw(int notused) + { + int a=0,/*b,*/c/*,f,x,y,z*/; + //long ax,ay,az,bx,by,bz,kx,ky,kz,nx,ny,nz,s; + + for(a=0;a