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