home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / vexsrc / transfrm.cpp < prev    next >
C/C++ Source or Header  |  1995-03-29  |  3KB  |  104 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. // cool motion functions...
  20. // this uses the compiled (makescn.cpp) "movelist"
  21. // and can handle movement polynomes to the 3rd degree (???)
  22. //            and rotation polynomes to the 2nd degree
  23. // the coefficients are dumped to the .3ds file
  24.  
  25. #include <mem.h>
  26. //#include <io.h>
  27. #include "ovlio.h"
  28. #include "ints.h"
  29. #include "matrix.h"
  30. #include "vect.h"
  31.  
  32. #define CMD_HOM 0
  33. #define CMD_POS 1
  34. #define CMD_MOV 2
  35. #define CMD_ACC 3
  36. #define CMD_AC3 4
  37. #define CMD_AHM 5
  38. #define CMD_ANG 6
  39. #define CMD_ROT 7
  40. #define CMD_AAC 8
  41.  
  42. #pragma argsused
  43. transform::transform(int file)
  44. {
  45.   short buflen;
  46.   oread(file, &buflen, 2);
  47.   events=new char[buflen];
  48.   oread(file, events, buflen);
  49.   evptr=events;
  50.   alev=plev=0;
  51. }
  52.  
  53. transform::~transform()
  54. {
  55.   delete events;
  56. }
  57.  
  58. void transform::parse()
  59. {
  60.   while (*(long*)evptr<=curtime)
  61.   {
  62.     long t=*(long*)evptr;
  63.     char cmd=evptr[4];
  64.     evptr+=5;
  65.     vector v;
  66.     switch (cmd)
  67.     {
  68.     case CMD_HOM: case CMD_POS: case CMD_MOV: case CMD_ACC: case CMD_AC3:
  69.       pt0=t;
  70.       plev=cmd-CMD_HOM;
  71.       memcpy(pos, evptr, 12*plev);
  72.       evptr+=12*plev;
  73.       break;
  74.     case CMD_AHM: case CMD_ANG: case CMD_ROT: case CMD_AAC:
  75.       at0=t;
  76.       alev=cmd-CMD_AHM;
  77.       memcpy(ang, evptr, 12*alev);
  78.       evptr+=12*alev;
  79.       break;
  80.     }
  81.   }
  82. }
  83.  
  84. void transform::makexform(matrix& m)
  85. {
  86.   parse();
  87.  
  88.   vector v;
  89.   matrix t;
  90.  
  91.   vecmove(v, ang, curtime-at0, alev);
  92.   if (v[0])
  93.     makematrotx(m, v[0]);
  94.   else
  95.     makematnorm(m);
  96.   if (v[1])
  97.     matmul(m, makematroty(t, v[1]), m);
  98.   if (v[2])
  99.     matmul(m, makematrotz(t, v[2]), m);
  100.  
  101.   if (plev)
  102.     matxlate(m, vecmove(v, pos, curtime-pt0, plev));
  103. }
  104.