home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / vexsrc / object.cpp < prev    next >
C/C++ Source or Header  |  1995-03-29  |  4KB  |  192 lines

  1. /*****************************************************************************
  2.                                   ATTENTION!
  3.                            this source is VOTEWARE,
  4.               you may only use it to the conditions listed below:
  5.  
  6.   -You may modify it, or use parts of it in your own source as long as
  7.     this header stays on top of all files containing this source.
  8.   -You must give proper credit to the author, Niklas Beisert / pascal.
  9.   -You may not use it in commercial productions without the written
  10.     permission of the author.
  11.   -AND MOST IMPORTANT: you have to buy an Assembly '94 CD-ROM
  12.     by Sound Solutions (if you don't have it already) and vote for VEX-InTrO
  13.     in the PC-64k-Intro-Compo! (if you have already sent your voting card,
  14.     buy another one and fill it out CORRECTLY!!!)
  15. *****************************************************************************/
  16.  
  17.  
  18.  
  19. // read the object tree
  20.  
  21. #include <stdlib.h>
  22. #include <mem.h>
  23. //#include <io.h>
  24. #include "ovlio.h"
  25. #include "ints.h"
  26. #include "matrix.h"
  27. #include "vect.h"
  28.  
  29. object *readobject(int file)
  30. {
  31.   char type;
  32.   oread(file, &type, 1);
  33.   switch (type)
  34.   {
  35.   case 0:
  36.     return new objectnode(file);
  37.   case 1:
  38.     return new stdobject(file);
  39.   case 2:
  40.   default:
  41.     return new lightobject(file);
  42.   }
  43. }
  44.  
  45. stdobject::stdobject(int file)
  46. {
  47.   o.mid.v[0]=o.mid.v[1]=o.mid.v[2]=0;
  48.   o.id=-1;
  49.   oread(file, &o.vertnum, 2);
  50.   oread(file, &o.normnum, 2);
  51.   oread(file, &o.planenum, 2);
  52.   oread(file, &o.rad, 4);
  53.  
  54.   o.verts=new vector[o.vertnum];
  55.   o.norms=new vector[o.normnum];
  56.   if (o.planenum)
  57.     o.planes=new plane[o.planenum];
  58.   else
  59.     o.planes=0;
  60.  
  61.   oread(file, o.verts, 12*o.vertnum);
  62.   oread(file, o.norms, 12*o.normnum);
  63.  
  64.   short i;
  65.   for (i=0; i<o.planenum; i++)
  66.   {
  67.     plane &p=o.planes[i];
  68.     short x;
  69.     oread(file, &x, 2);
  70.     p.b=(x==-1)?0:&o.planes[x];
  71.     oread(file, &x, 2);
  72.     p.m=(x==-1)?0:&o.planes[x];
  73.     oread(file, &x, 2);
  74.     p.f=(x==-1)?0:&o.planes[x];
  75.     oread(file, &p.opt, 1);
  76.     oread(file, &p.disp, 1);
  77.     oread(file, &p.nr.c0, 1);
  78.     oread(file, &p.nr.cn, 1);
  79.     oread(file, &p.mid, 2);
  80.     oread(file, &p.nr.n, 2);
  81.     oread(file, &p.num, 2);
  82.     oread(file, &p.v, 2*o.planes[i].num);
  83.     p.v[p.num]=p.v[0];
  84.     switch (p.disp)
  85.     {
  86.     case DISP_TEXT:
  87.     case DISP_TEXTX:
  88.       oread(file, &p.textnum, 2);
  89.     case DISP_SHADED:
  90.       oread(file, &p.ct, 4*p.num);
  91.       p.ct[p.num]=p.ct[0];
  92.       break;
  93.     }
  94.   }
  95.  
  96.   short buflen;
  97.   oread(file, &buflen, 2);
  98.   events=new char[buflen];
  99.   oread(file, events, buflen);
  100.   evptr=events;
  101.   active=1;
  102.  
  103.   t=new transform(file);
  104. };
  105.  
  106. stdobject::~stdobject()
  107. {
  108.   delete events;
  109.   delete t;
  110. }
  111.  
  112. void stdobject::getobject(const matrix &m)
  113. {
  114.   while (*(long*)evptr<=curtime)
  115.   {
  116. //    long t=*(long*)evptr;
  117.     char cmd=evptr[4];
  118.     evptr+=5;
  119.     switch (cmd)
  120.     {
  121.     case 0:
  122.       active=0;
  123.       break;
  124.     case 1:
  125.       active=1;
  126.       break;
  127.     case 2:
  128.       o.id=*evptr++;
  129.       break;
  130.     }
  131.   }
  132.  
  133.   if (!active)
  134.     return;
  135.   matrix x;
  136.   t->makexform(x);
  137.   matmul(o.xform, m, x);
  138.   addobject(o);
  139. }
  140.  
  141. objectnode::objectnode(int file)
  142. {
  143.   oread(file, &objnum, 1);
  144.   short i;
  145.   o=new object*[objnum];
  146.   for (i=0; i<objnum; i++)
  147.     o[i]=readobject(file);
  148.   t=new transform(file);
  149. };
  150.  
  151. objectnode::~objectnode()
  152. {
  153.   short i;
  154.   for (i=0; i<objnum; i++)
  155.     delete o[i];
  156.   delete o;
  157.   delete t;
  158. }
  159.  
  160. void objectnode::getobject(const matrix &m)
  161. {
  162.   matrix x;
  163.   t->makexform(x);
  164.   matmul(x, m, x);
  165.   short i;
  166.   for (i=0; i<objnum; i++)
  167.     o[i]->getobject(x);
  168. }
  169.  
  170. lightobject::lightobject(int file)
  171. {
  172.   intens=dtol(5);
  173.   t=new transform(file);
  174. }
  175.  
  176. lightobject::~lightobject()
  177. {
  178.   delete t;
  179. }
  180.  
  181. void lightobject::getobject(const matrix &m)
  182. {
  183.   if (!intens)
  184.     return;
  185.   matrix x;
  186.   t->makexform(x);
  187.   matmul(x, m, x);
  188.   vector z={0,0,0};
  189.   vecxform(&z, &z, x, 1);
  190.   addlight(z, intens);
  191. }
  192.