home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 12 / CD_ASCQ_12_0294.iso / vrac / pov_mp21.zip / FRAME.H < prev    next >
C/C++ Source or Header  |  1993-12-14  |  28KB  |  1,078 lines

  1. /****************************************************************************
  2. *                   frame.h
  3. *
  4. *  This header file is included by all C modules in POV-Ray. It defines all
  5. *  globally-accessible types and constants.
  6. *
  7. *  from Persistence of Vision Raytracer
  8. *  Copyright 1993 Persistence of Vision Team
  9. *---------------------------------------------------------------------------
  10. *  NOTICE: This source code file is provided so that users may experiment
  11. *  with enhancements to POV-Ray and to port the software to platforms other 
  12. *  than those supported by the POV-Ray Team.  There are strict rules under
  13. *  which you are permitted to use this file.  The rules are in the file
  14. *  named POVLEGAL.DOC which should be distributed with this file. If 
  15. *  POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  16. *  Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  17. *  Forum.  The latest version of POV-Ray may be found there as well.
  18. *
  19. * This program is based on the popular DKB raytracer version 2.12.
  20. * DKBTrace was originally written by David K. Buck.
  21. * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  22. *
  23. *****************************************************************************/
  24.  
  25. /* Generic header for all modules */
  26.  
  27. #include <math.h>
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <limits.h>
  31. #include "config.h"
  32.  
  33.  
  34. /* These are used by POVRAY.C and the machine specific modules */
  35.  
  36. #define POV_RAY_VERSION "2.1"
  37.  
  38. /* This message is for the personal distribution release. */
  39. /*
  40. #define DISTRIBUTION_MESSAGE_1 "This is an unofficial version compiled by:"
  41. #define DISTRIBUTION_MESSAGE_2 "FILL IN NAME HERE........................."
  42. #define DISTRIBUTION_MESSAGE_3 "The POV-Ray Team is not responsible for supporting this version."
  43. */
  44. #define DISTRIBUTION_MESSAGE_1 "This is an unofficial version for Windows NT console compiled by:"
  45. #define DISTRIBUTION_MESSAGE_2 "Gilles Vollant (email : 100144.2636@compuserve.com)"
  46. #define DISTRIBUTION_MESSAGE_3 "The POV-Ray Team is not responsible for supporting this version."
  47.  
  48. #ifndef READ_ENV_VAR_BEFORE 
  49. #define READ_ENV_VAR_BEFORE 
  50. #endif
  51. #ifndef READ_ENV_VAR_AFTER
  52. #define READ_ENV_VAR_AFTER if ((Option_String_Ptr = getenv("POVRAYOPT")) != NULL) read_options(Option_String_Ptr);   
  53. #endif
  54.  
  55. #ifndef CONFIG_MATH
  56. #define CONFIG_MATH
  57. #endif
  58.  
  59. #ifndef EPSILON
  60. #define EPSILON 1.0e-10
  61. #endif
  62.  
  63. #ifndef FILE_NAME_LENGTH
  64. #define FILE_NAME_LENGTH 150
  65. #endif
  66.  
  67. #ifndef HUGE_VAL
  68. #define HUGE_VAL 1.0e+17
  69. #endif
  70.  
  71. #ifndef BOUND_HUGE
  72. #define BOUND_HUGE 1.0e30
  73. #endif
  74.  
  75. #ifndef DBL_FORMAT_STRING
  76. #define DBL_FORMAT_STRING "%lf"
  77. #endif
  78.  
  79. #ifndef DEFAULT_OUTPUT_FORMAT
  80. #define DEFAULT_OUTPUT_FORMAT   'd'
  81. #endif
  82.  
  83. #ifndef RED_RAW_FILE_EXTENSION
  84. #define RED_RAW_FILE_EXTENSION ".red"
  85. #endif
  86.  
  87. #ifndef GREEN_RAW_FILE_EXTENSION
  88. #define GREEN_RAW_FILE_EXTENSION ".grn"
  89. #endif
  90.  
  91. #ifndef BLUE_RAW_FILE_EXTENSION
  92. #define BLUE_RAW_FILE_EXTENSION ".blu"
  93. #endif
  94.  
  95. #ifndef FILENAME_SEPARATOR
  96. #define FILENAME_SEPARATOR "/"
  97. #endif
  98.  
  99. /* 0==yes 1==no 2==opt */
  100. #ifndef CASE_SENSITIVE_DEFAULT
  101. #define CASE_SENSITIVE_DEFAULT 0
  102. #endif
  103.  
  104. #ifndef READ_FILE_STRING
  105. #define READ_FILE_STRING "rb"
  106. #endif
  107.  
  108. #ifndef WRITE_FILE_STRING
  109. #define WRITE_FILE_STRING "wb"
  110. #endif
  111.  
  112. #ifndef APPEND_FILE_STRING
  113. #define APPEND_FILE_STRING "ab"
  114. #endif
  115.  
  116. #ifndef NORMAL
  117. #define NORMAL '0'
  118. #endif
  119.  
  120. #ifndef GREY
  121. #define GREY   'G'
  122. #endif
  123.  
  124. #ifndef START_TIME
  125. #define START_TIME time(&tstart);     
  126. #endif
  127.  
  128. #ifndef STOP_TIME
  129. #define STOP_TIME  time(&tstop);
  130. #endif
  131.  
  132. #ifndef TIME_ELAPSED
  133. #define TIME_ELAPSED difftime (tstop, tstart);
  134. #endif
  135.  
  136. #ifndef STARTUP_POVRAY
  137. #define STARTUP_POVRAY
  138. #endif
  139.  
  140. #ifndef PRINT_OTHER_CREDITS
  141. #define PRINT_OTHER_CREDITS
  142. #endif
  143.  
  144. #ifndef TEST_ABORT
  145. #define TEST_ABORT
  146. #endif
  147.  
  148. #ifndef FINISH_POVRAY
  149. #define FINISH_POVRAY
  150. #endif
  151.  
  152. #ifndef COOPERATE
  153. #define COOPERATE 
  154. #endif
  155.  
  156. #ifndef DBL
  157. #define DBL double
  158. #endif
  159.  
  160. #ifndef ACOS
  161. #define ACOS acos
  162. #endif
  163.  
  164. #ifndef SQRT
  165. #define SQRT sqrt
  166. #endif
  167.  
  168. #ifndef POW
  169. #define POW pow
  170. #endif
  171.  
  172. #ifndef COS
  173. #define COS cos
  174. #endif
  175.  
  176. #ifndef SIN
  177. #define SIN sin
  178. #endif
  179.  
  180. #ifndef labs
  181. #define labs(x) (long) ((x<0)?-x:x)
  182. #endif
  183.  
  184. #ifndef max
  185. #define max(x,y) ((x<y)?y:x)
  186. #endif
  187.  
  188. #ifndef STRLN
  189. #define STRLN(x) x
  190. #endif
  191.  
  192. #ifndef PARAMS
  193. #define PARAMS(x) x
  194. #endif
  195.  
  196. #ifndef ANSIFUNC
  197. #define ANSIFUNC 1
  198. #endif
  199.  
  200. #ifndef M_PI
  201. #define M_PI 3.1415926535897932384626
  202. #endif
  203.  
  204. #ifndef TRUE
  205. #define TRUE 1
  206. #define FALSE 0
  207. #endif
  208.  
  209. #ifndef IFF_SWITCH_CAST
  210. #define IFF_SWITCH_CAST (int)
  211. #endif
  212.  
  213. #ifndef PRINT_CREDITS
  214. #define PRINT_CREDITS print_credits();
  215. #endif
  216.  
  217. #ifndef PRINT_STATS
  218. #define PRINT_STATS print_stats();
  219. #endif
  220.  
  221. #ifndef MAX_CONSTANTS
  222. #define MAX_CONSTANTS 1000
  223. #endif
  224.  
  225. #ifndef WAIT_FOR_KEYPRESS
  226. #define WAIT_FOR_KEYPRESS
  227. #endif
  228.  
  229. #ifndef CDECL
  230. #define CDECL
  231. #endif
  232.  
  233. #ifndef MAX_BUFSIZE
  234. #define MAX_BUFSIZE INT_MAX
  235. #endif
  236.  
  237. /* If compiler version is undefined, then make it 'u' for unknown */
  238. #ifndef COMPILER_VER
  239. #define COMPILER_VER ".u"
  240. #endif
  241.  
  242. #ifndef QSORT_FUNCT_RET
  243. #define QSORT_FUNCT_RET int CDECL
  244. #endif
  245.  
  246. #ifndef QSORT_FUNCT_PARAM
  247. #define QSORT_FUNCT_PARAM void *
  248. #endif
  249.  
  250. #ifndef MAIN_RETURN_TYPE
  251. #define MAIN_RETURN_TYPE void
  252. #endif
  253.  
  254. #ifndef MAIN_RETURN_STATEMENT
  255. #define MAIN_RETURN_STATEMENT
  256. #endif
  257.  
  258. /* These values determine the minumum and maximum distances
  259.    that qualify as ray-object intersections */
  260. #define Small_Tolerance 0.001
  261. #define Max_Distance 1.0e7
  262.  
  263. typedef struct istk_entry INTERSECTION;
  264. typedef struct Vector_Struct VECTOR;
  265. typedef DBL MATRIX [4][4];
  266. typedef struct Bounding_Box_Struct BBOX;
  267. typedef struct Colour_Struct COLOUR;
  268. typedef struct Colour_Map_Entry COLOUR_MAP_ENTRY;
  269. typedef struct Colour_Map_Struct COLOUR_MAP;
  270. typedef struct Transform_Struct TRANSFORM;
  271. typedef struct Image_Struct IMAGE;
  272. typedef struct Texture_Struct TEXTURE;
  273. typedef struct Material_Texture_Struct MATERIAL;
  274. typedef struct Tiles_Texture_Struct TILES;
  275. typedef struct Pattern_Struct TPATTERN;
  276. typedef struct Pigment_Struct PIGMENT;
  277. typedef struct Tnormal_Struct TNORMAL;
  278. typedef struct Finish_Struct FINISH;
  279. typedef struct Method_Struct METHODS;
  280. typedef struct Camera_Struct CAMERA;
  281. typedef struct Object_Struct OBJECT;
  282. typedef struct Composite_Struct COMPOSITE;
  283. typedef struct Sphere_Struct SPHERE;
  284. typedef struct Quadric_Struct QUADRIC;
  285. typedef struct Poly_Struct POLY;
  286. typedef struct Disc_Struct DISC;
  287. typedef struct Cone_Struct CYLINDER;
  288. typedef struct Cone_Struct CONE;
  289. typedef struct Light_Source_Struct LIGHT_SOURCE;
  290. typedef struct Bicubic_Patch_Struct BICUBIC_PATCH;
  291. typedef struct Triangle_Struct TRIANGLE;
  292. typedef struct Smooth_Triangle_Struct SMOOTH_TRIANGLE;
  293. typedef struct Plane_Struct PLANE;
  294. typedef struct CSG_Struct CSG;
  295. typedef struct Box_Struct BOX;
  296. typedef struct Blob_Struct BLOB;
  297. typedef struct Ray_Struct RAY;
  298. typedef struct Frame_Struct FRAME;
  299. typedef struct istack_struct ISTACK;
  300. typedef int TOKEN;
  301. typedef int CONSTANT;
  302. typedef struct Chunk_Header_Struct CHUNK_HEADER;
  303. typedef struct Data_File_Struct DATA_FILE;
  304. typedef struct complex_block complex;
  305. typedef struct Height_Field_Struct HEIGHT_FIELD;
  306. typedef short WORD;
  307.  
  308. struct Vector_Struct
  309.   {
  310.    DBL x, y, z;
  311.   };
  312. #define Destroy_Vector(x) if ((x)!=NULL) free(x)
  313. #define Destroy_Float(x) if ((x)!=NULL) free(x)
  314.  
  315. struct Colour_Struct
  316.   {
  317.    DBL Red, Green, Blue, Filter;
  318.   };
  319.  
  320. #define Make_Colour(c,r,g,b) {(c)->Red=(r);(c)->Green=(g);(c)->Blue=(b);(c)->Filter=0.0;}
  321. #define Make_ColourA(c,r,g,b,a) {(c)->Red=(r);(c)->Green=(g);(c)->Blue=(b);(c)->Filter=(a);}
  322. #define Make_Vector(v,a,b,c) { (v)->x=(a);(v)->y=(b);(v)->z=(c); }
  323. #define Destroy_Colour(x) if ((x)!=NULL) free(x)
  324. #define MAX_COLOUR_MAP_ENTRIES 40
  325.  
  326. struct Colour_Map_Entry
  327.   {
  328.    DBL value;
  329.    COLOUR Colour;
  330.   };
  331.  
  332. struct Colour_Map_Struct
  333.   {
  334.    int Number_Of_Entries, Transparency_Flag, Users;
  335.    COLOUR_MAP_ENTRY *Colour_Map_Entries;
  336.   };
  337.  
  338. struct Transform_Struct
  339.   {
  340.    MATRIX matrix;
  341.    MATRIX inverse;
  342.   };
  343.  
  344. #define Destroy_Transform(x) if ((x)!=NULL) free(x)
  345.  
  346. /* Types for reading IFF files. */
  347. typedef struct {unsigned short Red, Green, Blue, Filter;} IMAGE_COLOUR;
  348.  
  349. struct Image_Line
  350.   {
  351.    unsigned char *red, *green, *blue;
  352.   };
  353.  
  354. typedef struct Image_Line IMAGE_LINE;
  355.  
  356. /* Legal image attributes */
  357. #define GIF_FILE   1
  358. #define POT_FILE   2
  359. #define DUMP_FILE  4
  360. #define IFF_FILE   8
  361. #define TGA_FILE  16
  362. #define GRAD_FILE 32
  363.  
  364. #define IMAGE_FILE    GIF_FILE+DUMP_FILE+IFF_FILE+GRAD_FILE+TGA_FILE
  365. #define NORMAL_FILE   GIF_FILE+DUMP_FILE+IFF_FILE+GRAD_FILE+TGA_FILE
  366. #define MATERIAL_FILE GIF_FILE+DUMP_FILE+IFF_FILE+GRAD_FILE+TGA_FILE
  367. #define HF_FILE       GIF_FILE+POT_FILE+TGA_FILE
  368.  
  369. struct Image_Struct
  370.   {
  371.    int Map_Type;
  372.    int File_Type;
  373.    int Interpolation_Type;
  374.    short Once_Flag;
  375.    short Use_Colour_Flag;
  376.    VECTOR Gradient;
  377.    DBL width, height;
  378.    int iwidth, iheight;
  379.    short Colour_Map_Size;
  380.    IMAGE_COLOUR *Colour_Map;
  381.    union 
  382.     {
  383.      IMAGE_LINE *rgb_lines;
  384.      unsigned char **map_lines;
  385.     } data;  
  386.   };
  387.  
  388. /* Texture types */
  389. #define PNF_TEXTURE     0
  390. #define TILE_TEXTURE    1
  391. #define MAT_TEXTURE     2
  392.  
  393. /* Image/Bump Map projection types */
  394. #define PLANAR_MAP      0
  395. #define SPHERICAL_MAP   1
  396. #define CYLINDRICAL_MAP 2
  397. #define PARABOLIC_MAP   3
  398. #define HYPERBOLIC_MAP  4
  399. #define TORUS_MAP       5
  400. #define PIRIFORM_MAP    6
  401. #define OLD_MAP         7
  402.  
  403. /* Bit map interpolation types */
  404. #define NO_INTERPOLATION 0
  405. #define NEAREST_NEIGHBOR 1
  406. #define BILINEAR         2
  407. #define CUBIC_SPLINE     3
  408. #define NORMALIZED_DIST  4
  409.  
  410. /* Coloration pigment list */
  411. #define NO_PIGMENT               0
  412. #define COLOUR_PIGMENT           1
  413. #define BOZO_PIGMENT             2
  414. #define MARBLE_PIGMENT           3
  415. #define WOOD_PIGMENT             4
  416. #define CHECKER_PIGMENT          5
  417. #define SPOTTED_PIGMENT          6
  418. #define AGATE_PIGMENT            7
  419. #define GRANITE_PIGMENT          8
  420. #define GRADIENT_PIGMENT         9
  421. #define IMAGE_MAP_PIGMENT       10
  422. #define PAINTED1_PIGMENT        11 
  423. #define PAINTED2_PIGMENT        12 
  424. #define PAINTED3_PIGMENT        13 
  425. #define ONION_PIGMENT           14 
  426. #define LEOPARD_PIGMENT         15 
  427. #define BRICK_PIGMENT           16
  428. #define MANDEL_PIGMENT          17
  429. #define HEXAGON_PIGMENT         18
  430. #define RADIAL_PIGMENT          19
  431.  
  432.  
  433. /* Normal perturbation (bumpy) texture list  */
  434. #define NO_NORMAL  0
  435. #define WAVES      1
  436. #define RIPPLES    2
  437. #define WRINKLES   3
  438. #define BUMPS      4
  439. #define DENTS      5
  440. #define BUMPY1     6
  441. #define BUMPY2     7
  442. #define BUMPY3     8
  443. #define BUMP_MAP   9
  444.  
  445. /* Pattern flags */
  446. #define NO_FLAGS      0
  447. #define HAS_FILTER    1
  448. #define FULL_BLOCKING 2
  449. #define HAS_TURB      4
  450. #define POST_DONE     8
  451.  
  452. #define TPATTERN_FIELDS int Type, Octaves, Flags; VECTOR Turbulence;  \
  453.   DBL omega, lambda, Frequency, Phase; IMAGE *Image; TRANSFORM *Trans;
  454.  
  455. #define INIT_TPATTERN_FIELDS(p,t) p->Type=t; p->Octaves=6; p->Image=NULL; \
  456.  p->Frequency=1.0; p->Phase=0.0;\
  457.  p->Trans=NULL; p->Flags=NO_FLAGS; p->omega=0.5;p->lambda=2.0; \
  458.  Make_Vector(&(p->Turbulence),0.0,0.0,0.0);
  459.  
  460. /* This is an abstract structure that is never actually used.
  461.    Pigment and Tnormal are descendents of this primative type */
  462.  
  463. struct Pattern_Struct
  464.   {
  465.    TPATTERN_FIELDS
  466.   };
  467.  
  468. struct Pigment_Struct
  469.   {
  470.    TPATTERN_FIELDS
  471.    COLOUR *Colour1;
  472.    COLOUR Quick_Colour;
  473.    COLOUR_MAP *Colour_Map;
  474.    VECTOR Colour_Gradient;
  475.    DBL Mortar, Agate_Turb_Scale;
  476.    int Iterations; /* mhs 10/92 for fractal textures */
  477.   };
  478.  
  479. struct Tnormal_Struct
  480.   {
  481.    TPATTERN_FIELDS
  482.    DBL Amount;
  483.   };
  484.  
  485. struct Finish_Struct
  486.   {
  487.    DBL Reflection, Ambient, Diffuse, Brilliance, Index_Of_Refraction;
  488.    DBL Refraction, Specular, Roughness, Phong, Phong_Size;
  489.    DBL Crand;
  490.    short Metallic_Flag;
  491.   };
  492.  
  493. #define Destroy_Finish(x) if ((x)!=NULL) free(x)
  494.  
  495. #define TEXTURE_FIELDS unsigned char Type,Flags; TEXTURE *Next_Material; \
  496.  TEXTURE *Next_Layer;
  497. #define TRANS_TEXTURE_FIELDS TEXTURE_FIELDS TRANSFORM *Trans;
  498.  
  499. struct Texture_Struct
  500.   {
  501.    TEXTURE_FIELDS
  502.    PIGMENT *Pigment;
  503.    TNORMAL *Tnormal;
  504.    FINISH *Finish;
  505.   };
  506.  
  507. struct Tiles_Texture_Struct
  508.   {
  509.    TRANS_TEXTURE_FIELDS
  510.    TEXTURE *Tile1;
  511.    TEXTURE *Tile2;
  512.   };
  513.  
  514. struct Material_Texture_Struct
  515.   {
  516.    TRANS_TEXTURE_FIELDS
  517.    TEXTURE *Materials;
  518.    IMAGE *Image;
  519.    int Num_Of_Mats;
  520.   };
  521.  
  522. /* Object types */
  523. #define BASIC_OBJECT            0
  524. #define PATCH_OBJECT            1   /* Has no inside, no inverse */
  525. #define TEXTURED_OBJECT         2   /* Has texture, possibly in children */
  526.  
  527. #define CHILDREN_FLAGS (PATCH_OBJECT+TEXTURED_OBJECT)
  528.                     /* Reverse inherited flags */
  529.  
  530. #define COMPOUND_OBJECT         4   /* Has children field */
  531. #define STURM_OK_OBJECT         8   /* STRUM legal */
  532. #define WATER_LEVEL_OK_OBJECT  16   /* WATER_LEVEL legal */
  533. #define LIGHT_SOURCE_OBJECT    32   /* link me in frame.light_sources */
  534. #define BOUNDING_OBJECT        64   /* This is a holder for bounded object */
  535. #define SMOOTH_OK_OBJECT      128   /* SMOOTH legal */
  536. #define IS_CHILD_OBJECT       256   /* Object is inside a COMPOUND */
  537. #define DOUBLE_ILLUMINATE     512   /* Illuminate both sides of surface to
  538.                        avoid normal purturb bug */
  539.  
  540. #define COMPOSITE_OBJECT       (BOUNDING_OBJECT)
  541. #define SPHERE_OBJECT          (BASIC_OBJECT)
  542. #define PLANE_OBJECT           (BASIC_OBJECT)
  543. #define QUADRIC_OBJECT         (BASIC_OBJECT)
  544. #define BOX_OBJECT             (BASIC_OBJECT)
  545. #define CONE_OBJECT            (BASIC_OBJECT)
  546. #define DISC_OBJECT            (BASIC_OBJECT)
  547. #define HEIGHT_FIELD_OBJECT    (BASIC_OBJECT+WATER_LEVEL_OK_OBJECT+SMOOTH_OK_OBJECT)
  548. #define TRIANGLE_OBJECT        (PATCH_OBJECT)
  549. #define SMOOTH_TRIANGLE_OBJECT (PATCH_OBJECT+DOUBLE_ILLUMINATE)
  550. #define BICUBIC_PATCH_OBJECT   (PATCH_OBJECT+DOUBLE_ILLUMINATE)
  551. #define UNION_OBJECT           (COMPOUND_OBJECT)
  552. #define MERGE_OBJECT           (COMPOUND_OBJECT)
  553. #define INTERSECTION_OBJECT    (COMPOUND_OBJECT)
  554. #define CUBIC_OBJECT           (STURM_OK_OBJECT)
  555. #define QUARTIC_OBJECT         (STURM_OK_OBJECT)
  556. #define POLY_OBJECT            (STURM_OK_OBJECT)
  557. #define BLOB_OBJECT            (STURM_OK_OBJECT)
  558. #define LIGHT_OBJECT           (COMPOUND_OBJECT+PATCH_OBJECT+LIGHT_SOURCE_OBJECT)
  559.  
  560. typedef int (*ALL_INTERSECTIONS_METHOD)PARAMS((OBJECT *, RAY *, ISTACK *));
  561. typedef int (*INSIDE_METHOD)PARAMS((VECTOR *, OBJECT *));
  562. typedef void (*NORMAL_METHOD)PARAMS((VECTOR *, OBJECT *, VECTOR *));
  563. typedef void *(*COPY_METHOD)PARAMS((OBJECT *));
  564. typedef void (*TRANSLATE_METHOD)PARAMS((OBJECT *, VECTOR *));
  565. typedef void (*ROTATE_METHOD)PARAMS((OBJECT *, VECTOR *));
  566. typedef void (*SCALE_METHOD)PARAMS((OBJECT *, VECTOR *));
  567. typedef void (*TRANSFORM_METHOD)PARAMS((OBJECT *, TRANSFORM *));
  568. typedef void (*INVERT_METHOD)PARAMS((OBJECT *));
  569. typedef void (*DESTROY_METHOD)PARAMS((OBJECT *));
  570.  
  571. struct Method_Struct
  572.   {
  573.    ALL_INTERSECTIONS_METHOD All_Intersections_Method;
  574.    INSIDE_METHOD Inside_Method;
  575.    NORMAL_METHOD Normal_Method;
  576.    COPY_METHOD Copy_Method;
  577.    TRANSLATE_METHOD Translate_Method;
  578.    ROTATE_METHOD Rotate_Method;
  579.    SCALE_METHOD Scale_Method;
  580.    TRANSFORM_METHOD Transform_Method;
  581.    INVERT_METHOD Invert_Method;
  582.    DESTROY_METHOD Destroy_Method;
  583.   };
  584.  
  585. #define All_Intersections(x,y,z) ((*((x)->Methods->All_Intersections_Method)) (x,y,z))
  586. #define Inside(x,y) ((*((y)->Methods->Inside_Method)) (x,y))
  587. #define Normal(x,y,z) ((*((y)->Methods->Normal_Method)) (x,y,z))
  588. #define Copy(x) ((*((x)->Methods->Copy_Method)) (x))
  589. #define Translate(x,y) ((*((x)->Methods->Translate_Method)) (x,y))
  590. #define Scale(x,y) ((*((x)->Methods->Scale_Method)) (x,y))
  591. #define Rotate(x,y) ((*((x)->Methods->Rotate_Method)) (x,y))
  592. #define Transform(x,y) ((*((x)->Methods->Transform_Method)) (x,y))
  593. #define Invert(x) ((*((x)->Methods->Invert_Method)) (x))
  594. #define Destroy(x) ((*((x)->Methods->Destroy_Method)) (x))
  595.  
  596. #define Destroy_Camera(x) if ((x)!=NULL) free(x)
  597.  
  598. struct Camera_Struct
  599.   {
  600.    VECTOR Location;
  601.    VECTOR Direction;
  602.    VECTOR Up;
  603.    VECTOR Right;
  604.    VECTOR Sky;
  605.   };
  606.  
  607. struct Bounding_Box_Struct {
  608.    VECTOR Lower_Left, Lengths;
  609.    };
  610.  
  611. /* These fields are common to all objects */
  612.  
  613. #define OBJECT_FIELDS \
  614.  METHODS *Methods;\
  615.  int Type;\
  616.  OBJECT *Sibling;\
  617.  TEXTURE *Texture;\
  618.  OBJECT *Bound;\
  619.  OBJECT *Clip;\
  620.  BBOX Bounds;\
  621.  short No_Shadow_Flag;
  622.  
  623. /* These fields are common to all compound objects */
  624. #define COMPOUND_FIELDS \
  625.  OBJECT_FIELDS \
  626.  OBJECT *Children;
  627.  
  628. #define INIT_OBJECT_FIELDS(o,t,m)\
  629.  o->Type=t;o->Methods= m;o->Sibling=NULL;o->Texture=NULL;\
  630.  o->Bound=NULL;o->Clip=NULL;o->No_Shadow_Flag=FALSE;\
  631.  Make_Vector(&o->Bounds.Lower_Left, -BOUND_HUGE/2, -BOUND_HUGE/2, -BOUND_HUGE/2)\
  632.  Make_Vector(&o->Bounds.Lengths, BOUND_HUGE, BOUND_HUGE, BOUND_HUGE)
  633.  
  634. /* This is an abstract structure that is never actually used.
  635.    All other objects are descendents of this primative type */
  636.  
  637. struct Object_Struct
  638.   {
  639.    OBJECT_FIELDS
  640.   };
  641.  
  642. struct CSG_Struct
  643.   {
  644.    COMPOUND_FIELDS
  645.   };
  646.  
  647. struct Light_Source_Struct
  648.   {
  649.    COMPOUND_FIELDS
  650.    COLOUR Colour;
  651.    VECTOR Center, Points_At, Axis1, Axis2;
  652.    DBL Coeff, Radius, Falloff;
  653.    LIGHT_SOURCE *Next_Light_Source;
  654.    unsigned char Light_Type, Area_Light, Jitter, Track;
  655.    int    Area_Size1, Area_Size2;
  656.    int    Adaptive_Level;
  657.    COLOUR **Light_Grid;
  658.    OBJECT *Shadow_Cached_Object;
  659.   };
  660.  
  661. /* Light source types */
  662. #define POINT_SOURCE     1
  663. #define SPOT_SOURCE      2
  664.  
  665. #define BUNCHING_FACTOR 4
  666. struct Composite_Struct
  667.   {
  668.    OBJECT_FIELDS
  669.    unsigned short int Entries;
  670.    OBJECT *Objects[BUNCHING_FACTOR];
  671.   };
  672.  
  673. struct Sphere_Struct
  674.   {
  675.    OBJECT_FIELDS
  676.    TRANSFORM *Trans; 
  677.    VECTOR  Center;
  678.    DBL     Radius;
  679.    DBL     Radius_Squared;
  680.    DBL     Inverse_Radius;
  681.    VECTOR  CMOtoC;
  682.    DBL     CMOCSquared;
  683.    short   CMinside, CMCached, Inverted;
  684.   };
  685.  
  686. struct Quadric_Struct
  687.   {
  688.    OBJECT_FIELDS
  689.    VECTOR  Square_Terms;
  690.    VECTOR  Mixed_Terms;
  691.    VECTOR  Terms;
  692.    DBL Constant;
  693.    DBL CM_Constant;
  694.    short Constant_Cached;
  695.    short Non_Zero_Square_Term;
  696.   };
  697.  
  698. typedef unsigned short HF_val;
  699.  
  700. typedef struct {
  701.    HF_val min_y, max_y;
  702. } HF_BLOCK;
  703.  
  704. typedef struct {
  705.     float x, z;
  706.     VECTOR normal;
  707. } Cached_Normals;
  708.  
  709. typedef short HF_Normals[3];
  710. #define HF_CACHE_SIZE 16
  711. #define LOWER_TRI 0
  712. #define UPPER_TRI 1
  713.  
  714.  
  715.  
  716. struct Height_Field_Struct
  717.   {
  718.    OBJECT_FIELDS 
  719.    TRANSFORM *Trans; 
  720.    BOX *bounding_box;
  721.    DBL Block_Size;
  722.    DBL Inv_Blk_Size;
  723.    HF_BLOCK **Block;
  724.    HF_val **Map;
  725.    int Inverted;
  726.    int cache_pos;
  727.    Cached_Normals Normal_Vector[HF_CACHE_SIZE];
  728.    int Smoothed;
  729.    HF_Normals **Normals;
  730.    };
  731.  
  732. struct Box_Struct
  733.   {
  734.    OBJECT_FIELDS 
  735.    TRANSFORM *Trans; 
  736.    VECTOR bounds[2];
  737.    short Inverted;
  738.   };
  739.  
  740. #define MAX_ORDER 15
  741.  
  742. #define STURM_FIELDS  OBJECT_FIELDS int Sturm_Flag;
  743.  
  744. /* Number of coefficients of a three variable polynomial of order x */
  745. #define term_counts(x) (((x)+1)*((x)+2)*((x)+3)/6)
  746.  
  747. struct Poly_Struct
  748.   {
  749.    STURM_FIELDS
  750.    TRANSFORM *Trans;
  751.    short Inverted;
  752.    int Order;
  753.    DBL *Coeffs;
  754.   };
  755.  
  756. struct Disc_Struct {
  757.    OBJECT_FIELDS
  758.    TRANSFORM *Trans; /* Transformation of a Disc object */
  759.    VECTOR center;    /* Center of the disc */
  760.    VECTOR normal;    /* Direction perpendicular to the disc (plane normal) */
  761.    DBL d;            /* The constant part of the plane equation */
  762.    DBL iradius2;     /* Distance from center to inner circle of the disc */
  763.    DBL oradius2;     /* Distance from center to outer circle of the disc */
  764.    short Inverted;
  765.    };
  766.  
  767. struct Cone_Struct {
  768.    OBJECT_FIELDS
  769.    TRANSFORM *Trans;   /* Transformation of a Cone object */
  770.    short int cyl_flag; /* Is this a cone or a cylinder? */
  771.    short int closed;   /* Currently unused - for making caps on the cone */
  772.    VECTOR apex;        /* Center of the top of the cone */
  773.    VECTOR base;        /* Center of the bottom of the cone */
  774.    DBL apex_radius;    /* Radius of the cone at the top */
  775.    DBL base_radius;    /* Radius of the cone at the bottom */
  776.    DBL dist;           /* Distance to end of cone in canonical coords */
  777.    short Inverted;
  778.    };
  779.  
  780. typedef struct Bezier_Node_Struct BEZIER_NODE;
  781. typedef struct Bezier_Child_Struct BEZIER_CHILDREN;
  782. typedef struct Bezier_Vertices_Struct BEZIER_VERTICES;
  783.  
  784. struct Bezier_Child_Struct
  785.   {
  786.    BEZIER_NODE *Children[4];
  787.   };
  788.  
  789. struct Bezier_Vertices_Struct
  790.   {
  791.    float uvbnds[4];
  792.    VECTOR Vertices[4];
  793.   };
  794.  
  795. struct Bezier_Node_Struct
  796.   {
  797.    int Node_Type;      /* Is this an interior node, or a leaf */
  798.    VECTOR Center;      /* Center of sphere bounding the (sub)patch */
  799.    DBL Radius_Squared; /* Radius of bounding sphere (squared) */
  800.    int Count;          /* # of subpatches associated with this node */
  801.    void *Data_Ptr;     /* Either pointer to vertices or pointer to children */
  802.   };
  803.  
  804. #define BEZIER_INTERIOR_NODE 0
  805. #define BEZIER_LEAF_NODE 1
  806.  
  807. #define MAX_PATCH_TYPE 4
  808.  
  809. struct Bicubic_Patch_Struct
  810.   {
  811.    OBJECT_FIELDS
  812.    int Patch_Type, U_Steps, V_Steps;
  813.    VECTOR Control_Points[4][4];
  814.    VECTOR Bounding_Sphere_Center;
  815.    DBL Bounding_Sphere_Radius;
  816.    DBL Flatness_Value;
  817.    BEZIER_NODE *Node_Tree;
  818.   };
  819.    
  820. #define X_AXIS 0
  821. #define Y_AXIS 1
  822. #define Z_AXIS 2
  823.  
  824. struct Triangle_Struct
  825.   {
  826.    OBJECT_FIELDS
  827.    VECTOR  Normal_Vector;
  828.    DBL     Distance;
  829.    DBL     CMNormDotOrigin;
  830.    unsigned int  CMCached:1;
  831.    unsigned int  Dominant_Axis:2;
  832.    unsigned int  vAxis:2;  /* used only for smooth triangles */
  833.    VECTOR  P1, P2, P3;
  834.    short int Degenerate_Flag;
  835.   };
  836.  
  837. struct Smooth_Triangle_Struct
  838.   {
  839.    OBJECT_FIELDS
  840.    VECTOR  Normal_Vector;
  841.    DBL     Distance;
  842.    DBL     CMNormDotOrigin;
  843.    unsigned int  CMCached:1;
  844.    unsigned int  Dominant_Axis:2;
  845.    unsigned int  vAxis:2;         /* used only for smooth triangles */
  846.    VECTOR  P1, P2, P3;
  847.    short int Degenerate_Flag;
  848.    VECTOR  N1, N2, N3, Perp;
  849.    DBL  BaseDelta;
  850.   };
  851.  
  852. struct Plane_Struct
  853.   {
  854.    OBJECT_FIELDS
  855.    VECTOR  Normal_Vector;
  856.    DBL     Distance;
  857.    DBL     CMNormDotOrigin;
  858.    int     CMCached;
  859.   };
  860.  
  861. typedef struct {
  862.    VECTOR pos;
  863.    DBL radius2;
  864.    DBL coeffs[3];
  865.    DBL tcoeffs[5];
  866.    } Blob_Element;
  867.  
  868. typedef struct blob_list_struct *blobstackptr;
  869. struct blob_list_struct {
  870.    Blob_Element elem;
  871.    blobstackptr next;
  872.    };
  873.  
  874. typedef struct {
  875.    int type, index;
  876.    DBL bound;
  877.    } Blob_Interval;
  878.  
  879. struct Blob_Struct
  880.    {
  881.    STURM_FIELDS
  882.    TRANSFORM *Trans;
  883.    short Inverted;
  884.    int count;
  885.    DBL threshold;
  886.    Blob_Element **list;
  887.    Blob_Interval *intervals;
  888. };
  889.  
  890. #define MAX_CONTAINING_OBJECTS 10
  891.  
  892. struct Ray_Struct
  893.   {
  894.    VECTOR Initial;               /*  Xo  Yo  Zo  */
  895.    VECTOR Direction;             /*  Xv  Yv  Zv  */
  896.    VECTOR Initial_2;             /*  Xo^2  Yo^2  Zo^2  */
  897.    VECTOR Direction_2;           /*  Xv^2  Yv^2  Zv^2  */
  898.    VECTOR Initial_Direction;     /*  XoXv  YoYv  ZoZv  */
  899.    VECTOR Mixed_Initial_Initial; /*  XoYo  XoZo  YoZo  */
  900.    VECTOR Mixed_Dir_Dir;         /*  XvYv  XvZv  YvZv  */
  901.    VECTOR Mixed_Init_Dir;        /*  XoYv+XvYo  XoZv+XvZo  YoZv+YvZo  */
  902.    int Containing_Index;
  903.    TEXTURE *Containing_Textures [MAX_CONTAINING_OBJECTS];
  904.    DBL Containing_IORs [MAX_CONTAINING_OBJECTS];
  905.    int Quadric_Constants_Cached;
  906.   };
  907.  
  908. struct Frame_Struct
  909.   {
  910.    CAMERA *Camera;
  911.    int Screen_Height, Screen_Width;
  912.    LIGHT_SOURCE *Light_Sources;
  913.    OBJECT *Objects;
  914.    DBL Atmosphere_IOR, Antialias_Threshold;
  915.    DBL Fog_Distance;
  916.    COLOUR Fog_Colour;
  917.    COLOUR Background_Colour;
  918.   };
  919.  
  920. #define DISPLAY 1
  921. #define VERBOSE 2
  922. #define DISKWRITE 4
  923. #define PROMPTEXIT 8
  924. #define ANTIALIAS 16
  925. #define DEBUGGING 32
  926. #define RGBSEPARATE 64
  927. #define EXITENABLE 128
  928. #define CONTINUE_TRACE 256
  929. #define VERBOSE_FILE 512
  930. #define JITTER 1024
  931.  
  932. /* Definitions for ISTACK structure */
  933.  
  934. struct istk_entry
  935.   {
  936.    DBL Depth;
  937.    VECTOR IPoint;
  938.    VECTOR INormal;
  939.    int NFlag;
  940.    OBJECT *Object;
  941.   };
  942.  
  943. struct istack_struct
  944.   {
  945.    struct istack_struct *next;
  946.    struct istk_entry *istack;
  947.    unsigned int top_entry;
  948.   };
  949.  
  950. #define itop(i) i->istack[i->top_entry]
  951. #define push_entry(d,v,o,i) itop(i).Depth=d; itop(i).IPoint=v; \
  952.  itop(i).NFlag=0; itop(i).Object=o; incstack(i);
  953. #define push_normal_entry(d,v,n,o,i) itop(i).Depth=d; itop(i).IPoint=v; \
  954.  itop(i).INormal=n; itop(i).NFlag=1; itop(i).Object=o; incstack(i);
  955. #define push_copy(i,e) itop(i)= *e; incstack(i);
  956. #define pop_entry(i) (i->top_entry > 0)?&(i->istack[--i->top_entry]):NULL
  957.  
  958. #define MAX_STRING_INDEX 41 
  959.  
  960. struct Reserved_Word_Struct
  961.   {
  962.    TOKEN Token_Number;
  963.    char *Token_Name;
  964.   };
  965.  
  966. /* Here's where you dump the information on the current token (fm. PARSE.C) */
  967.  
  968. struct Token_Struct
  969.   {
  970.    TOKEN Token_Id;
  971.    int Token_Line_No;
  972.    char *Token_String;
  973.    DBL Token_Float;
  974.    TOKEN Begin_Id;
  975.    int Constant_Index;
  976.    int Unget_Token, End_Of_File;
  977.    char *Filename, *Constant_Data;
  978.   };
  979.  
  980. /* Types of constants allowed in DECLARE statement (fm. PARSE.C) */
  981.  
  982. #define COLOUR_CONSTANT         0
  983. #define VECTOR_CONSTANT         1
  984. #define FLOAT_CONSTANT          2
  985. #define PIGMENT_CONSTANT        3
  986. #define TNORMAL_CONSTANT        4
  987. #define FINISH_CONSTANT         5
  988. #define TEXTURE_CONSTANT        6
  989. #define OBJECT_CONSTANT         7
  990. #define COLOUR_MAP_CONSTANT     8
  991. #define TRANSFORM_CONSTANT      9
  992. #define CAMERA_CONSTANT        10
  993.  
  994. /* CSG types */
  995. #define CSG_UNION_TYPE             1
  996. #define CSG_INTERSECTION_TYPE      2
  997. #define CSG_DIFFERENCE_TYPE        4
  998. #define CSG_MERGE_TYPE             8
  999. #define CSG_SINGLE_TYPE           16
  1000.  
  1001. struct Constant_Struct
  1002.   {
  1003.    int Identifier_Number;
  1004.    CONSTANT Constant_Type;
  1005.    char *Constant_Data;
  1006.   };
  1007.  
  1008. struct Chunk_Header_Struct 
  1009.   {
  1010.    long name;
  1011.    long size;
  1012.   };
  1013.  
  1014. struct Data_File_Struct 
  1015.   {
  1016.    FILE *File;
  1017.    char *Filename;
  1018.    int Line_Number;
  1019.   };
  1020.  
  1021. struct complex_block 
  1022.   {
  1023.    DBL r, c;
  1024.   };
  1025.  
  1026. #define READ_MODE 0
  1027. #define WRITE_MODE 1
  1028. #define APPEND_MODE 2
  1029.  
  1030. struct file_handle_struct 
  1031.   {
  1032.    char *filename;
  1033.    int  mode;
  1034.    int width, height;
  1035.    int buffer_size;
  1036.    char *buffer;
  1037.    FILE *file;
  1038.    char *(*Default_File_Name_p) PARAMS((void));
  1039.    int  (*Open_File_p) PARAMS((struct file_handle_struct *handle,
  1040.            char *name, int *width, int *height, int buffer_size,
  1041.            int mode));
  1042.    void (*Write_Line_p) PARAMS((struct file_handle_struct *handle,
  1043.            COLOUR *line_data, int line_number));
  1044.    int  (*Read_Line_p) PARAMS((struct file_handle_struct *handle,
  1045.            COLOUR *line_data, int *line_number));
  1046.    void (*Read_Image_p) PARAMS((IMAGE *Image, char *filename));
  1047.    void (*Close_File_p) PARAMS((struct file_handle_struct *handle));
  1048.   };
  1049.  
  1050. typedef struct file_handle_struct FILE_HANDLE;
  1051.  
  1052. #define Default_File_Name(h) ((*((h)->Default_File_Name_p)) ())
  1053. #define Open_File(h,n,wd,ht,sz,m) ((*((h)->Open_File_p)) (h,n,wd,ht,sz,m))
  1054. #define Write_Line(h,l,n) ((*((h)->Write_Line_p)) (h, l, n))
  1055. #define Read_Line(h,l,n) ((*((h)->Read_Line_p)) (h, l, n))
  1056. #define Read_Image(h,i) ((*((h)->Read_Image_p)) (h, i))
  1057. #define Close_File(h) ((*((h)->Close_File_p)) (h))
  1058.  
  1059.  
  1060. #define Q_FULL_AMBIENT 1
  1061. #define Q_QUICKC       2
  1062. #define Q_SHADOW       4
  1063. #define Q_AREA_LIGHT   8
  1064. #define Q_REFRACT     16
  1065. #define Q_REFLECT     32
  1066. #define Q_NORMAL      64
  1067.  
  1068. #define QUALITY_0 Q_QUICKC+Q_FULL_AMBIENT
  1069. #define QUALITY_1 QUALITY_0
  1070. #define QUALITY_2 QUALITY_1-Q_FULL_AMBIENT
  1071. #define QUALITY_3 QUALITY_2
  1072. #define QUALITY_4 QUALITY_3+Q_SHADOW
  1073. #define QUALITY_5 QUALITY_4+Q_AREA_LIGHT
  1074. #define QUALITY_6 QUALITY_5-Q_QUICKC+Q_REFRACT
  1075. #define QUALITY_7 QUALITY_6
  1076. #define QUALITY_8 QUALITY_7+Q_REFLECT+Q_NORMAL
  1077. #define QUALITY_9 QUALITY_8
  1078.