home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / vexsrc / stars.cpp < prev    next >
C/C++ Source or Header  |  1995-03-29  |  3KB  |  123 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. // oh my god.. this starfield is so slow...
  20.  
  21. //#include <io.h>
  22. #include "ovlio.h"
  23. #include <stdlib.h>
  24. #include "ints.h"
  25. #include "matrix.h"
  26. #include "draw3d.h"
  27. #include "vect.h"
  28.  
  29. #define NUMPOINTS 256
  30.  
  31. static vector *p3, *p2;
  32. static char *p;
  33. static long lasttime;
  34. static transform *t;
  35. static char *events;
  36. static char *evptr;
  37. static short active;
  38. static long speed;
  39. static long maxcolor;
  40.  
  41. short initstars(short file)
  42. {
  43.   p3=new vector[NUMPOINTS];
  44.   p2=new vector[NUMPOINTS];
  45.   p=new char[NUMPOINTS*3];
  46.   if (!p3||!p2||!p)
  47.     return 0;
  48.   short i;
  49.   for (i=0; i<NUMPOINTS; i++)
  50.   {
  51.     p2[i].v[0]=(long)rand()*2-32768;
  52.     p2[i].v[1]=(long)rand()*2-32768;
  53.     p2[i].v[2]=(long)rand()*2-32768;
  54.   }
  55.   lasttime=curtime;
  56.  
  57.   short buflen;
  58.   oread(file, &buflen, 2);
  59.   events=new char[buflen];
  60.   oread(file, events, buflen);
  61.   evptr=events;
  62.   active=0;
  63.   speed=dtol(0.25);
  64.   maxcolor=dtol(32);
  65.  
  66.   t=new transform(file);
  67.  
  68.   return 1;
  69. }
  70.  
  71. void closestars()
  72. {
  73.   delete p3;
  74.   delete p2;
  75.   delete p;
  76.   delete events;
  77.   delete t;
  78. }
  79.  
  80. void drawstars()
  81. {
  82.   while (*(long*)evptr<=curtime)
  83.   {
  84. //    long t=*(long*)evptr;
  85.     char cmd=evptr[4];
  86.     evptr+=5;
  87.     switch (cmd)
  88.     {
  89.     case 0:
  90.       active=0;
  91.       break;
  92.     case 1:
  93.       active=1;
  94.       break;
  95.     case 2:
  96.       speed=*(long*)evptr;
  97.       evptr+=4;
  98.       break;
  99.     case 3:
  100.       maxcolor=*(long*)evptr;
  101.       evptr+=4;
  102.       break;
  103.     }
  104.   }
  105.  
  106.   if (!active)
  107.     return;
  108.   long tm=IntMul(curtime-lasttime, speed);
  109.  
  110.   short i;
  111.   for (i=0; i<NUMPOINTS; i++)
  112.     p2[i].v[2]=(short)(p2[i].v[2]+tm);
  113.  
  114.   matrix m;
  115.   t->makexform(m);
  116.   vecxform(p3, p2, m, NUMPOINTS);
  117.  
  118.   short n=calcpoints3d(p, p3, NUMPOINTS, dtol(200), dtol(180), dtol(1), maxcolor);
  119.   rdrawpointlst(p, n, scrpage<<14);
  120.  
  121.   lasttime=curtime;
  122. }
  123.