#include #include #include #include #include #include #include #include "wgt3d.h" /* Virtual Modeller version 0.5 Beta Requires Turbo C++, WGT v4.0 to recompile. This source requires the WordUp Graphics Toolkit version 4.0 to recompile. This library will not be available until the first quarter of 1994. */ void saveobject(void); void loadobject(void); void displaytitle(void); point3d mypoints[400]; /* Stores 400 initial 3D points */ point3d finp[400]; /* Stores 400 rotated 3D points */ int ROTATIONS=8; /* Default number of rotations */ int i; /* Looping */ int curx=0,cury=10,curz=170; /* Rotation amount in each axis */ block other; /* Temporary screen */ color pal[256]; /* A VGA palette */ int d,e; /* Misc/Looping */ int temp; int xdir=1,ydir=1,xpos=0,ypos=0; /* Offset of object on screen (not used) */ tpolypoint mypoly[4]; /* Max polygon has 4 vertices */ int sortpoly[200]; /* Sorted list for 300 polygons */ int ztotal[200]; /* Average Z coord of 4 vertices for each polygon */ /* Polygons are sorted by this number */ int maxpoly=200; int px[100],py[100]; /* Stores coordinates of 100 points that you click on. */ int faces[200][4]; /* Stores 200 polygon faces */ int oldmode; /* Mode before program was run */ int textx[4],texty[4]; /* Offsets into our texture bitmap */ block ourtexture; /* A texture bitmap */ int tmode; /* Texture mode, either normal or xray */ typedef struct { /* Used to keep track what portion of the */ int x1,y1,x2,y2; /* screen has been changed, so we can update */ } rect; /* the least amount of video memory */ rect lastrect,thisrect; char c,polytype; /* Saves a custom 3D object file format */ /* Not used in this program yet */ void saveobject(void) { int i; FILE *objfile; objfile=fopen("object.3d","wt"); fprintf(objfile,"WGT 3D Object File\n"); /* Number of points in this object */ fprintf(objfile,"%i\n",maxpoly); /* Write the points */ for (i=0; i400) { wtextcolor(255); wgtprintf(0,0,NULL,"Object too large!"); delay(1000); goto startover; } mypoints[d+i*ROTATIONS].x=(icos[d*(360/ROTATIONS)]*px[i])>>14; mypoints[d+i*ROTATIONS].y=(isin[d*(360/ROTATIONS)]*px[i])>>14; mypoints[d+i*ROTATIONS].z=py[i]-100; } maxpoly*=ROTATIONS; if (maxpoly>200) { wtextcolor(255); wgtprintf(0,0,NULL,"Object too large!"); delay(1000); goto startover; } /* Generate the list of polygons. Each polygon is made up of 4 3D points. */ d=0; for (i=0; i319) lastrect.x2=319; if (lastrect.y1<0) lastrect.y1=0; if (lastrect.y2>199) lastrect.y2=199; wsetcolor(0); wbar(lastrect.x1,lastrect.y1,lastrect.x2,lastrect.y2); /* Clear out the area that was drawn in last frame */ wsetrotation(curx,cury,curz); wrotatepoints(mypoints,finp,maxpoly*4); /* Rotate our 3D points and store the rotated values into finp */ /* Calculate a unique z value for each polygon, to be used for sorting */ for (d=0; dztotal[sortpoly[d]]) { temp=sortpoly[e]; sortpoly[e]=sortpoly[d]; sortpoly[d]=temp; } } /* Now go through the list of polygons and draw each in order */ for (d=0; d250) mypoly[e].sx=250; } if (mypoly[e].xthisrect.x2) thisrect.x2=mypoly[e].x; if (mypoly[e].ythisrect.y2) thisrect.y2=mypoly[e].y; /* See if the polygon is larger than the current area to update. If it is, enlarge the area so all polygons fit inside. */ } /* Draw our polygons using WGT's commands */ if (polytype=='T') wtexturedpoly(mypoly,3,xpos,ypos,ourtexture,tmode); else if (polytype=='G') wgouraudpoly(mypoly,3,xpos,ypos); else if (polytype=='S') { /* Get an average colour to use depending on the vertices */ wsetcolor((mypoly[0].sx+mypoly[1].sx+mypoly[2].sx+mypoly[3].sx)/4); wsolidpoly(mypoly,3,xpos,ypos); } else if (polytype=='W') { wsetcolor((mypoly[0].sx+mypoly[1].sx+mypoly[2].sx+mypoly[3].sx)/4); whollowpoly(mypoly,3,xpos,ypos); } } /* Adds a small amount to the rotation in each axis, and checks for the wrap around 360 degrees. */ curx+=5; if (curx>359) curx-=360; cury+=4; if (cury>359) cury-=360; curz+=3; if (curz>359) curz-=360; if (lastrect.x1>thisrect.x1) lastrect.x1=thisrect.x1; if (lastrect.x2thisrect.y1) lastrect.y1=thisrect.y1; if (lastrect.y2319) lastrect.x2=319; if (lastrect.y1<0) lastrect.y1=0; if (lastrect.y2>199) lastrect.y2=199; wcopyscreen(lastrect.x1,lastrect.y1,lastrect.x2,lastrect.y2,other, lastrect.x1,lastrect.y1,NULL); /* Copy from our second page to the visual page. */ lastrect.x1=thisrect.x1; lastrect.y1=thisrect.y1; lastrect.x2=thisrect.x2; lastrect.y2=thisrect.y2; /* Make the last rectangle = current rectangle */ } while (!kbhit()); } while (getch() !='q'); wfreeblock(ourtexture); wsetmode(oldmode); } void displaytitle(void) { clrscr(); printf(" л л ллллл ллл ллллл л л ллллл л \n"); printf(" л л л л л л л л л л л \n"); printf(" л л л ллл л л л ллллл л \n"); printf(" л л л л л л л л л л л \n"); printf(" л лллллл л л л ллллл л л ллллл \n"); printf("\n"); printf(" л л лл ллл ллл л л ллл ллл \n"); printf(" лл лл л л л л л л л л л л \n"); printf(" л л л л л л л лл л л лл ллл \n"); printf(" л л л л л л л л л л л л \n"); printf(" л л лл ллл ллл ллл ллл ллл л л \n"); printf("\n"); printf(" Public Domain - Written by Chris Egerter\n"); printf(" Press any key to continue \n"); getch(); while (kbhit()) getch(); }