home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / t3dlib_src_r43.lha / t3dlib.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-02  |  12.8 KB  |  453 lines

  1. /* t3dlib.h - definitions needed to interface to TTDDD library
  2.  *          - written by Glenn M. Lewis - 7/19/91
  3.  *          - Imagine3.0 staging file extensions by Rob Hounsell - Sept 94
  4.  * $Id: t3dlib.h,v 1.28 1995/02/01 22:24:38 glewis Exp glewis $
  5.  */
  6.  
  7. #ifdef AMIGA
  8.  
  9. #ifdef _M68881
  10. #include <m68881.h>
  11. #endif
  12.  
  13. /* The following has been tested using SAS/C on an Amiga by Helge Rasmussen */
  14. #ifdef __SASC
  15. #include <string.h>
  16. #include <stdlib.h>
  17. #include <exec/types.h>
  18. #else
  19. #define  bcopy(s,d,n)    (void)memcpy((d),(s),(n))
  20. #define  bzero(d,n)        (void)memset((d),0,(n))
  21. #define  bcmp(b1,b2,n)    memcmp((b1),(b2),(n))
  22. #define  index            strchr
  23. #define  rindex            strrchr
  24. #endif
  25.  
  26. #else
  27.  
  28. #include <strings.h>
  29. #include <malloc.h>
  30. /*char *calloc();*/
  31.  
  32. #endif
  33.  
  34. #ifdef SYSV
  35. extern char *memcpy(), *memset();
  36. #define bcopy(s,d,n)    (void)memcpy((d),(s),(n))
  37. #define bzero(d,n)        (void)memset((d),0,(n))
  38. #define bcmp(b1,b2,n)    memcmp((b1),(b2),(n))
  39. #define index            strchr
  40. #define rindex            strrchr
  41. #endif
  42.  
  43. #ifndef AMIGA
  44. #ifndef UBYTE
  45. #define UBYTE unsigned char
  46. #endif
  47. #ifndef BYTE
  48. #define BYTE char
  49. #endif
  50.  
  51. #ifndef UWORD
  52. #define UWORD unsigned short
  53. #endif
  54. #ifndef WORD
  55. #define WORD short
  56. #endif
  57.  
  58. #ifndef ULONG
  59. #define ULONG unsigned long
  60. #endif
  61. #ifndef LONG
  62. #define LONG long
  63. #endif
  64. #endif
  65.  
  66. #ifndef FRACT
  67. #define FRACT double
  68. #endif
  69.  
  70. typedef struct { double x,y,z; } XYZ_st;    /* Used to be val[3] */
  71. typedef struct { UBYTE r,g,b;  } RGB_st;    /* Used to be val[3] */
  72. typedef struct { XYZ_st came, rota; double foca; } OBSV;
  73. typedef struct { double at, by; RGB_st to; } FADE;
  74. typedef struct { RGB_st hori, zeni; } SKYC;
  75. typedef char BRSH[81];
  76. typedef struct { XYZ_st tran, scal, rota1, rota2, rota3; } MTRX;
  77. typedef struct { XYZ_st xaxi, yaxi, zaxi; } AXIS;
  78. typedef struct { char path[19]; XYZ_st tran, rota, scal; UWORD info; } STRY;
  79. typedef struct {
  80.     MTRX mtrx;
  81.     char filename[81];
  82. } EXTR;
  83. typedef struct {
  84.     UBYTE type;
  85.     float indx;
  86. } MTTR;
  87. struct OBJECT {
  88.     EXTR *extr;    /* Either EXTR or DESC */
  89.     struct DESC *desc;
  90.     struct OBJECT *parent;    /* whose child this OBJECT is */
  91.     struct OBJECT *child;    /* children of this OBJECT - not for EXTR */
  92.     struct OBJECT *next;    /* At this level in the hierarchy */
  93.     void *user;        /* User-defined data for any purpose */
  94. };
  95. typedef struct OBJECT OBJECT;
  96. typedef struct {
  97.     UWORD num;
  98.     UBYTE *eflg;
  99. } EFLG;
  100. struct FGRP {
  101.     struct FGRP *next;    /* Linked list */
  102.     UWORD num;
  103.     char name[19];    /* 18 allowed in file */
  104.     UWORD *face;
  105. };
  106. typedef struct FGRP FGRP;
  107. typedef struct {
  108.     UWORD  Flags;
  109.     MTRX   TAxis;
  110.     double Params[16];
  111.     UBYTE  PFlags[16];
  112.     UBYTE  SubName[81];
  113.     UBYTE  Length;
  114.     UBYTE  Name[81];
  115. } TXT2;
  116. typedef struct DESC {
  117.     char name[19];
  118.     WORD *shap;
  119.     XYZ_st *posi;
  120.     AXIS *axis;
  121.     XYZ_st *size;
  122.     XYZ_st *pnts;
  123.     RGB_st *colr, *refl, *tran, *spc1;
  124.     UWORD *edge, *face, pcount, ecount, fcount; 
  125.     UBYTE *clst, *rlst, *tlst;
  126.     double *tpar;
  127.     UBYTE *surf;
  128.     MTTR  *mttr;
  129.     UBYTE *spec;
  130.     UBYTE *prp0, *prp1;
  131.     double *ints;
  132.     XYZ_st *int1;
  133.     STRY *stry;
  134.     FGRP *fgrp;
  135.     EFLG *eflg;
  136.     TXT2 *txt2[4];
  137. } DESC;
  138.  
  139. /* extern UBYTE defclst[3], defrlst[3], deftlst[3], defspc1[3]; */
  140.  
  141. /* Add staging FILE information for Imagine support */
  142. /* It appears that the staging FILEs use 3 FRACT's to represent colors
  143.  * instead of 3 UBYTEs...  Hmmm...
  144.  */
  145.  
  146. /* Imagine 2 Chunks: OSIZ, POSN, ALGN, GLB2, LITE, HING, SFILE             */
  147. /* Imagine 3 Chunks: OSZ2, POS2, ALN2, GLB3, LIT2, ASSC, LYR0, FIL3, S3FX, */
  148. /*                   S4FX                                                  */
  149. /* Common Chunks:    PALN, PTH2, TALN, SAXIS, SPFX, S2FX                   */
  150.  
  151. enum chunk_type {OSIZ_CHUNK,
  152.                  POSN_CHUNK,
  153.                  ALGN_CHUNK,
  154.                  PALN_CHUNK,
  155.                  PTH2_CHUNK,
  156.                  TALN_CHUNK,
  157.                  GLB2_CHUNK,
  158.                  SAXIS_CHUNK,
  159.                  LITE_CHUNK,
  160.                  HING_CHUNK,
  161.                  SFILE_CHUNK,
  162.                  OSZ2_CHUNK,
  163.                  POS2_CHUNK,
  164.                  ALN2_CHUNK, 
  165.                  GLB3_CHUNK, 
  166.                  LIT2_CHUNK,
  167.                  ASSC_CHUNK, 
  168.                  LYR0_CHUNK, 
  169.                  FIL3_CHUNK,
  170.                  SPFX_CHUNK,
  171.                  S2FX_CHUNK,
  172.                  S3FX_CHUNK,
  173.                  S4FX_CHUNK };
  174.  
  175.  
  176. struct SAXIS { struct SAXIS *next, *prev; UBYTE chunk_type; UWORD flags, start, stop; };
  177. typedef struct SAXIS SAXIS;
  178.  
  179. struct GLB2 {
  180.     struct GLB2 *next, *prev;
  181.     UBYTE chunk_type;
  182.     UWORD flags, start, stop;
  183.     ULONG sky_blending;
  184.     double starfield;
  185.     ULONG transition;
  186.     /* The following are really colors */
  187.     XYZ_st ambient, horizon, zenith1, zenith2, fog_color;
  188.     double fog_bottom, fog_top, fog_length;
  189.     ULONG brush_seq, backdrop_seq;
  190.     char backdrop[256];            /* Fixed length */
  191.     char globalbrush[256];        /* Variable length */
  192. };
  193. typedef struct GLB2 GLB2;
  194.  
  195. struct LITE {
  196.     struct LITE *next, *prev;
  197.   UBYTE chunk_type;
  198.     UWORD flags, start, stop;
  199.     /* The following are really colors */
  200.     XYZ_st color;
  201.     ULONG transition;
  202. };
  203. typedef struct LITE LITE;
  204.  
  205. struct SFILE {
  206.     struct SFILE *next, *prev;
  207.     UBYTE chunk_type;
  208.     UWORD flags, start, stop;
  209.     double cycles_to_perform;
  210.     double initial_cycle_phase;
  211.     ULONG transition;
  212.     char object_description[256];    /* Variable length */
  213. };
  214. typedef struct SFILE SFILE;
  215.  
  216. struct OSIZ { struct OSIZ *next,*prev; UBYTE chunk_type; UWORD flags, start, stop; XYZ_st size; };
  217. typedef struct OSIZ OSIZ;    /* Size */
  218.  
  219. struct POSN { struct POSN *next,*prev; UBYTE chunk_type; UWORD flags, start, stop; XYZ_st posn; };
  220. typedef struct POSN POSN;    /* Position */
  221.  
  222. struct ALGN { struct ALGN *next,*prev; UBYTE chunk_type; UWORD flags, start, stop; XYZ_st algn; };
  223. typedef struct ALGN ALGN;    /* Alignment */
  224.  
  225. struct HING {
  226.     struct HING *next, *prev;
  227.     UBYTE chunk_type;
  228.     UWORD flags, start, stop;
  229.     char hingeobj[256];            /* Variable length */
  230. };
  231. typedef struct HING HING;    /* Hinge */
  232.  
  233. struct GLB3 {
  234.     struct GLB3 *next, *prev;
  235.     UBYTE chunk_type;
  236.     UWORD flags, start, stop;
  237.     ULONG brush_seq;
  238.     double starfield;
  239.     ULONG transition;
  240.     /* The following are really colors */
  241.     XYZ_st ambient, horizon, zenith1, zenith2, fog_color;
  242.     double fog_bottom, fog_top, fog_length;
  243.     ULONG backdrop_seq;
  244.     char backdrop[256];            /* Fixed length */
  245.     char globalbrush[256];        /* Variable length */
  246. };
  247. typedef struct GLB3 GLB3;
  248.  
  249. struct LIT2 {
  250.     struct LIT2 *next, *prev;
  251.   UBYTE chunk_type;
  252.     UWORD flags, start, stop;
  253.     /* The following are really colors */
  254.     XYZ_st color;
  255.     ULONG transition;
  256. };
  257. typedef struct LIT2 LIT2;
  258.  
  259. struct FIL3 {
  260.     struct FIL3 *next, *prev;
  261.     UBYTE chunk_type;
  262.     UWORD flags, start, stop;
  263.     double cycles_to_perform;
  264.     double initial_cycle_phase;
  265.     double vel_0, vel_1;
  266.     char state[18];            /* Fixed length */
  267.     char object_description[256];    /* Variable length */
  268. };
  269. typedef struct FIL3 FIL3;
  270.  
  271. struct OSZ2 { struct OSZ2 *next,*prev; UBYTE chunk_type; UWORD flags, start, stop; XYZ_st size; double vel_0, vel_1; };
  272. typedef struct OSZ2 OSZ2;    /* Size */
  273.  
  274. struct POS2 { struct POS2 *next,*prev; UBYTE chunk_type; UWORD flags, start, stop; XYZ_st pos2; double vel_0, vel_1;};
  275. typedef struct POS2 POS2;    /* Position */
  276.  
  277. struct ALN2 { struct ALN2 *next,*prev; UBYTE chunk_type; UWORD flags, start, stop; XYZ_st aln2; double vel_0, vel_1; };
  278. typedef struct ALN2 ALN2;    /* Alignment */
  279.  
  280. struct PALN { struct PALN *next,*prev; UBYTE chunk_type; UWORD flags, start, stop; };
  281. typedef struct PALN PALN;        /* Path Alignment */
  282.  
  283. struct PTH2 {
  284.     struct PTH2 *next, *prev;
  285.     UBYTE chunk_type;
  286.     UWORD flags, start, stop;
  287.     ULONG acceleration_frames;
  288.     double start_speed;
  289.     ULONG deacceleration_frames;
  290.     double end_speed;
  291.     char path[256];                /* Variable length */
  292. };
  293. typedef struct PTH2 PTH2;        /* Follow Path */
  294.  
  295. struct TALN {
  296.     struct TALN *next, *prev;
  297.     UBYTE chunk_type;
  298.     UWORD flags, start, stop;
  299.     double initial_y, final_y;
  300.     char trackobj[256];            /* Variable length */
  301. };
  302. typedef struct TALN TALN;    /* Track alignment */
  303.  
  304. struct ASSC {
  305.     struct ASSC *next, *prev;
  306.     UBYTE chunk_type;
  307.     UWORD flags, start, stop;
  308.     char assc_obj[18];            /* Fixed length */
  309. };
  310. typedef struct ASSC ASSC;    /* Associate chunk */
  311.  
  312. struct LYR0 {
  313.     struct LYR0 *next, *prev;
  314.     UBYTE chunk_type;
  315.     UWORD layer;
  316. };
  317. typedef struct LYR0 LYR0;    /* Layer info */
  318.  
  319. struct SPFX {
  320.     struct SPFX *next, *prev;
  321.     UBYTE chunk_type;
  322.     UWORD flags, start, stop;
  323.     char effect[256];            /* Variable length */
  324.     char effect_data[512];        /* uuencoded data, variable length */
  325. };
  326. typedef struct SPFX SPFX;    /* Special Effects chunk */
  327.  
  328. struct SOBJ {
  329.     struct SOBJ *next, *prev;
  330.     /* Required subchunks in the SOBJ chunk... */
  331.     char name[18];    /* CHUNK: Name, fixed=18 */
  332.     UWORD stgf;        /* CHUNK: always zero? */
  333.     /* Possible subchunks in the SOBJ chunk, including Imagine 2.0 & 3.0 */
  334.     OSZ2 *osz2;        /* V3 Size */
  335.     OSIZ *osiz;        /* V2 Size */
  336.     POS2 *pos2;        /* V3 Position */
  337.     POSN *posn;        /* V2 Position */
  338.     ALN2 *aln2;        /* V3 Alignment */
  339.     ALGN *algn;        /* V2 Alignment */
  340.     GLB3 *glb3;        /* V3 Globals */
  341.     GLB2 *glb2;        /* V2 Globals */
  342.     SAXIS *axis;    /* Stagefile AXIS */
  343.     LIT2 *lit2;        /* V3 Light */
  344.     LITE *lite;        /* V2 Light */
  345.     ASSC *assc;        /* V3 Associate object */
  346.     HING *hing;     /* V2 Hinge */
  347.     LYR0 *lyr0;        /* layer in stage editor */
  348.     FIL3 *fil3;        /* V3 external file */
  349.     SFILE *file;    /* V2 external file */
  350.     SPFX *spfx;        /* Special Effect */
  351.     SPFX *s2fx;        /* Special Effect 2 */
  352.     SPFX *s3fx;        /* Special Effect 3 */
  353.     SPFX *s4fx;        /* Special Effect 4 */
  354. };
  355. typedef struct SOBJ SOBJ;
  356.  
  357. typedef struct {
  358.     UWORD maxf, loop;
  359.     /* Just so we don't have to search through the doubly-linked list */
  360.     /* every time we wish to add to the tail, keep a pointer to head&tail */
  361.     SOBJ *head, *tail;
  362. } ISTG;
  363.  
  364. /* Back to old Turbo Silver stuff... */
  365.  
  366. #define STNC BRSH
  367. #define TXTR BRSH
  368. typedef struct {
  369.     BRSH brsh[8];
  370.     STNC stnc[8];
  371.     TXTR txtr[8];
  372.     OBSV *obsv;
  373.     BYTE otrk[19];
  374.     STRY *ostr;
  375.     FADE *fade;
  376.     SKYC *skyc;
  377.     RGB_st *ambi;
  378.     BYTE *glb0;
  379. } INFO;
  380.  
  381. typedef struct {
  382.     INFO *info;            /* The INFO description in the file */
  383.     ISTG *istg;            /* Imagine staging file */
  384.     OBJECT *object;        /* The first object in the world */
  385.     void *user;        /* User-defined data for any purpose */
  386.     /* Some private variables needed to parse input file - don't touch! */
  387.     int num_OBJ, num_DESC, num_TOBJ, cur_line;
  388.     FILE *inp;
  389.     OBJECT *curobj;
  390. } WORLD;
  391.  
  392. typedef struct {
  393.     double minx, maxx, miny, maxy, minz, maxz;
  394. } MBB;
  395.  
  396. #ifdef __STDC__
  397. #define P0()            void
  398. #define P1(a)            a
  399. #define P2(a,b)            a,b
  400. #define P3(a,b,c)        a,b,c
  401. #define P4(a,b,c,d)        a,b,c,d
  402. #define P5(a,b,c,d,e)    a,b,c,d,e
  403. #else
  404. #define P0()        
  405. #define P1(a)        
  406. #define P2(a,b)        
  407. #define P3(a,b,c)    
  408. #define P4(a,b,c,d)    
  409. #define P5(a,b,c,d,e)    
  410. #endif
  411.  
  412. WORLD *read_World(P1(FILE*));            /* world = read_World(FILE *); ..figures out format */
  413. WORLD *free_World(P1(WORLD*));            /* world = free_World(world *);   ...frees a WORLD* */
  414. void merge_World(P1(WORLD*));            /* merge_World(world *); ..optimizes points & edges */
  415. WORLD *read_TTDDD(P1(FILE*));            /* world = read_TTDDD(FILE *);      ...0 on failure */
  416. WORLD *read_TDDD(P1(FILE*));            /* world = read_TDDD(FILE *);       ...0 on failure */
  417. WORLD *read_LWOB(P1(FILE*));            /* world = read_LWOB(FILE *);       ...0 on failure */
  418. WORLD *read_ISTG(P1(FILE*));            /* world = read_ISTG(FILE *);       ...0 on failure */
  419. int write_TTDDD(P2(WORLD*,FILE*));        /* write_TTDDD(world *, FILE *);    ...0 on failure */
  420. int write_TDDD(P2(WORLD*,FILE*));        /* write_TDDD(world *, FILE *);     ...0 on failure */
  421. int write_Rayshade(P2(WORLD*,FILE*));    /* write_Rayshade(world *, FILE *); ...0 on failure */
  422. int write_PostScript(P3(WORLD*,FILE*,int));    /* write_PostScript(world *, FILE *, view); ..ditto */
  423. int write_MIF(P3(WORLD*,FILE*,int));    /* write_MIF(world *, FILE *, view); ..0 on failure */
  424. void calculate_MBB_world(P1(WORLD*));    /* calculate_MBB_world(WORLD *); */
  425. void calculate_MBB(P1(OBJECT*));        /* calculate_MBB(OBJECT *); */
  426. OBJECT *linear_morph(P3(OBJECT*,OBJECT*,double));    /* linear_morph(obj1, obj2, time); /* 0.0<=time<=1.0 */
  427. OBJECT *create_object(P0());            /* p = create_object(); */
  428. OBJECT *free_object(P1(OBJECT*));        /* from freeworld.c */
  429. int count_objects(P2(OBJECT*,OBJECT**));    /* Used by "morph()" */
  430. int morph(P5(WORLD*,WORLD*,int,char*,OBJECT*(*func)()));    /* morph(world1, world2, num, name, morph_function); */
  431. void free_desc(P1(DESC*));                /* free_desc(DESC *); */
  432. void match_points(P3(int,OBJECT*,OBJECT*));    /* match_points(numpoints, obj1, obj2); */
  433. void sort_points(P2(DESC*,int(*cmp)()));
  434. int cmpXYZ(P2(XYZ_st*,XYZ_st*));        /* comparison for sort_points */
  435. void move_extr(P2(OBJECT*,MTRX*));
  436. void OUT_MEM(P1(char*));
  437. void load_staging_frame_objects(P2(WORLD*,int));    /* (world, frame); load a frame's objects */
  438. int write_OFF(P4(WORLD*,char*,int,int));
  439. int write_NFF(P2(WORLD*,FILE*));
  440. int write_DXF(P2(WORLD*,FILE*));
  441. int write_POVRay(P2(WORLD*,FILE*));
  442. int write_Vort(P2(WORLD*,FILE*));
  443. int write_LWOB(P2(WORLD*,FILE*));
  444.  
  445. /* Some stuff for PostScript and MIF output */
  446. extern double XSIZE, YSIZE;    /* (in inches) Default: 8.5x11.0 */
  447.  
  448. #define VIEW_TOP    0    /* eye at (0,0,+inf) */
  449. #define VIEW_FRONT    1    /* eye at (0,-inf,0) */
  450. #define VIEW_ISO    2    /* eye at (+inf,-inf,+inf) */
  451. #define VIEW_RIGHT    3    /* eye at (+inf,0,0) */
  452. #define VIEW_ALL_FOUR 4    /* Place all on the same page */
  453.