home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / povsrc.sit / SOURCE / FRAME.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-03  |  27.1 KB  |  1,092 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 1992 Persistence of Vision Team
  9. *---------------------------------------------------------------------------
  10. *  Copying, distribution and legal info is in the file povlegal.doc which
  11. *  should be distributed with this file. If povlegal.doc is not available
  12. *  or for more info please contact:
  13. *
  14. *       Drew Wells [POV-Team Leader] 
  15. *       CIS: 73767,1244  Internet: 73767.1244@compuserve.com
  16. *       Phone: (213) 254-4041
  17. * This program is based on the popular DKB raytracer version 2.12.
  18. * DKBTrace was originally written by David K. Buck.
  19. * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  20. *
  21. *****************************************************************************/
  22.  
  23. /* Generic header for all modules */
  24. #include <math.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include "config.h"
  28.  
  29.  
  30. #ifndef READ_ENV_VAR_BEFORE 
  31. #define READ_ENV_VAR_BEFORE 
  32. #endif
  33. #ifndef READ_ENV_VAR_AFTER
  34. #define READ_ENV_VAR_AFTER if ((Option_String_Ptr = getenv("POVRAYOPT")) != NULL) read_options(Option_String_Ptr);   
  35. #endif
  36.  
  37. #ifndef CONFIG_MATH
  38. #define CONFIG_MATH
  39. #endif
  40.  
  41. #ifndef EPSILON
  42. #define EPSILON 1.0e-10
  43. #endif
  44.  
  45. #ifndef FILE_NAME_LENGTH
  46. #define FILE_NAME_LENGTH 150
  47. #endif
  48.  
  49. #ifndef HUGE_VAL
  50. #define HUGE_VAL 1.0e+17
  51. #endif
  52.  
  53. #ifndef DBL_FORMAT_STRING
  54. #define DBL_FORMAT_STRING "%lf"
  55. #endif
  56.  
  57. #ifndef DEFAULT_OUTPUT_FORMAT
  58. #define DEFAULT_OUTPUT_FORMAT   'd'
  59. #endif
  60.  
  61. #ifndef RED_RAW_FILE_EXTENSION
  62. #define RED_RAW_FILE_EXTENSION ".red"
  63. #endif
  64.  
  65. #ifndef GREEN_RAW_FILE_EXTENSION
  66. #define GREEN_RAW_FILE_EXTENSION ".grn"
  67. #endif
  68.  
  69. #ifndef BLUE_RAW_FILE_EXTENSION
  70. #define BLUE_RAW_FILE_EXTENSION ".blu"
  71. #endif
  72.  
  73. #ifndef FILENAME_SEPARATOR
  74. #define FILENAME_SEPARATOR "/"
  75. #endif
  76.  
  77. /* 0==yes 1==no 2==opt */
  78. #ifndef CASE_SENSITIVE_DEFAULT
  79. #define CASE_SENSITIVE_DEFAULT 0 
  80. #endif
  81.  
  82. #ifndef READ_FILE_STRING
  83. #define READ_FILE_STRING "rb"
  84. #endif
  85.  
  86. #ifndef WRITE_FILE_STRING
  87. #define WRITE_FILE_STRING "wb"
  88. #endif
  89.  
  90. #ifndef APPEND_FILE_STRING
  91. #define APPEND_FILE_STRING "ab"
  92. #endif
  93.  
  94. #ifndef NORMAL
  95. #define NORMAL '0'
  96. #endif
  97.  
  98. #ifndef GREY
  99. #define GREY   'G'
  100. #endif
  101.  
  102. #ifndef START_TIME
  103. #define START_TIME time(&tstart);     
  104. #endif
  105.  
  106. #ifndef STOP_TIME
  107. #define STOP_TIME  time(&tstop);
  108. #endif
  109.  
  110. #ifndef TIME_ELAPSED
  111. #define TIME_ELAPSED difftime (tstop, tstart);
  112. #endif
  113.  
  114. #ifndef STARTUP_POVRAY
  115. #define STARTUP_POVRAY
  116. #endif
  117.  
  118. #ifndef PRINT_OTHER_CREDITS
  119. #define PRINT_OTHER_CREDITS
  120. #endif
  121.  
  122. #ifndef TEST_ABORT
  123. #define TEST_ABORT
  124. #endif
  125.  
  126. #ifndef FINISH_POVRAY
  127. #define FINISH_POVRAY
  128. #endif
  129.  
  130. #ifndef COOPERATE
  131. #define COOPERATE 
  132. #endif
  133.  
  134. #ifndef DBL
  135. #define DBL double
  136. #endif
  137.  
  138. #ifndef ACOS
  139. #define ACOS acos
  140. #endif
  141.  
  142. #ifndef SQRT
  143. #define SQRT sqrt
  144. #endif
  145.  
  146. #ifndef POW
  147. #define POW pow
  148. #endif
  149.  
  150. #ifndef COS
  151. #define COS cos
  152. #endif
  153.  
  154. #ifndef SIN
  155. #define SIN sin
  156. #endif
  157.  
  158. #ifndef labs
  159. #define labs(x) (long) ((x<0)?-x:x)
  160. #endif
  161.  
  162. #ifndef max
  163. #define max(x,y) ((x<y)?y:x)
  164. #endif
  165.  
  166. #ifndef STRLN
  167. #define STRLN(x) x
  168. #endif
  169.  
  170. #ifndef PARAMS
  171. #define PARAMS(x) x
  172. #endif
  173.  
  174. #ifndef ANSIFUNC
  175. #define ANSIFUNC 1
  176. #endif
  177.  
  178. #ifndef M_PI
  179. #define M_PI 3.1415926535897932384626
  180. #endif
  181.  
  182. #ifndef TRUE
  183. #define TRUE 1
  184. #define FALSE 0
  185. #endif
  186.  
  187. #ifndef IFF_SWITCH_CAST
  188. #define IFF_SWITCH_CAST (int)
  189. #endif
  190.  
  191. #ifndef PRINT_CREDITS
  192. #define PRINT_CREDITS print_credits();
  193. #endif
  194.  
  195. #ifndef PRINT_STATS
  196. #define PRINT_STATS print_stats();
  197. #endif
  198.  
  199. #ifndef MAX_CONSTANTS
  200. #define MAX_CONSTANTS 1000
  201. #endif
  202.  
  203. #ifndef WAIT_FOR_KEYPRESS
  204. #define WAIT_FOR_KEYPRESS
  205. #endif
  206.  
  207. /* If compiler version is undefined, then make it 'u' for unknown */
  208. #ifndef COMPILER_VER
  209. #define COMPILER_VER ".u"
  210. #endif
  211.  
  212.  
  213. /* These values determine the minumum and maximum distances
  214.    that qualify as ray-object intersections */
  215. #define Small_Tolerance 0.001
  216. #define Max_Distance 1.0e7
  217.  
  218. typedef struct q_entry INTERSECTION;
  219. typedef struct Vector_Struct VECTOR;
  220. typedef DBL MATRIX [4][4];
  221. typedef struct Colour_Struct COLOUR;
  222. typedef struct Colour_Map_Entry COLOUR_MAP_ENTRY;
  223. typedef struct Colour_Map_Struct COLOUR_MAP;
  224. typedef struct Transformation_Struct TRANSFORMATION;
  225. typedef struct Image_Struct IMAGE;
  226. typedef struct Texture_Struct TEXTURE;
  227. typedef struct Method_Struct METHODS;
  228. typedef struct Viewpoint_Struct VIEWPOINT;
  229. typedef struct Object_Shape SHAPE;
  230. typedef struct Object_Struct OBJECT;
  231. typedef struct Sphere_Shape SPHERE;
  232. typedef struct Light_Source_Shape LIGHT_SHAPE;
  233. typedef struct Quadric_Shape QUADRIC;
  234. typedef struct Poly_Shape POLY;
  235. typedef struct Bicubic_Patch_Shape BICUBIC_PATCH;
  236. typedef struct Triangle_Shape TRIANGLE;
  237. typedef struct Smooth_Triangle_Shape SMOOTH_TRIANGLE;
  238. typedef struct Plane_Shape PLANE;
  239. typedef struct Box_Shape BOX;
  240. typedef struct Blob_Shape BLOB;
  241. typedef struct CSG_Type CSG_SHAPE;
  242. typedef struct Composite_Object_Struct COMPOSITE;
  243. typedef struct Ray_Struct RAY;
  244. typedef struct Frame_Struct FRAME;
  245. typedef struct prioq_struct PRIOQ;
  246. typedef int TOKEN;
  247. typedef int CONSTANT;
  248. typedef struct Chunk_Header_Struct CHUNK_HEADER;
  249. typedef struct Data_File_Struct DATA_FILE;
  250. typedef struct complex_block complex;
  251. typedef struct Height_Field_Shape HEIGHT_FIELD;
  252. typedef short WORD;
  253.  
  254.  
  255. struct Vector_Struct
  256. {
  257.    DBL x, y, z;
  258. };
  259.  
  260.  
  261. struct Colour_Struct
  262. {
  263.    DBL Red, Green, Blue, Alpha;
  264. };
  265.  
  266.  
  267. struct Colour_Map_Entry
  268. {
  269.    DBL start, end;
  270.    COLOUR Start_Colour, End_Colour;
  271. };
  272.  
  273.  
  274. struct Colour_Map_Struct
  275. {
  276.    int Number_Of_Entries;
  277.    COLOUR_MAP_ENTRY *Colour_Map_Entries;
  278.    int Transparency_Flag;
  279. };
  280.  
  281.  
  282. struct Transformation_Struct
  283. {
  284.    MATRIX matrix;
  285.    MATRIX inverse;
  286. };
  287.  
  288.  
  289. /* Types for reading IFF files. */
  290. typedef struct {
  291.    unsigned short Red, Green, Blue, Alpha;
  292. } IMAGE_COLOUR;
  293.  
  294. struct Image_Line
  295. {
  296.    unsigned char *red, *green, *blue;
  297. };
  298.  
  299. typedef struct Image_Line IMAGE_LINE;
  300.  
  301. struct Image_Struct
  302. {
  303.    DBL width, height;
  304.    int iwidth, iheight;
  305.    int Map_Type;
  306.    int Interpolation_Type;
  307.    short Once_Flag;
  308.    short Use_Colour_Flag;
  309.    VECTOR Image_Gradient;
  310.    short Colour_Map_Size;
  311.    IMAGE_COLOUR *Colour_Map;
  312.    union {
  313.       IMAGE_LINE *rgb_lines;
  314.       unsigned char **map_lines;
  315.    }    data;  
  316. };
  317.  
  318. /* Image/Bump Map projection methods */
  319. #define PLANAR_MAP      0
  320. #define SPHERICAL_MAP   1
  321. #define CYLINDRICAL_MAP 2
  322. #define PARABOLIC_MAP   3
  323. #define HYPERBOLIC_MAP  4
  324. #define TORUS_MAP       5
  325. #define PIRIFORM_MAP    6
  326. #define OLD_MAP         7
  327.  
  328. /* Bit map interpolation types */
  329. #define NO_INTERPOLATION 0
  330. #define NEAREST_NEIGHBOR 1
  331. #define BILINEAR         2
  332. #define CUBIC_SPLINE     3
  333. #define NORMALIZED_DIST  4 
  334.  
  335.  
  336. /* Coloration texture list */
  337. #define NO_TEXTURE               0
  338. #define COLOUR_TEXTURE           1
  339. #define BOZO_TEXTURE             2
  340. #define MARBLE_TEXTURE           3
  341. #define WOOD_TEXTURE             4
  342. #define CHECKER_TEXTURE          5
  343. #define CHECKER_TEXTURE_TEXTURE  6
  344. #define SPOTTED_TEXTURE          7
  345. #define AGATE_TEXTURE            8
  346. #define GRANITE_TEXTURE          9
  347. #define GRADIENT_TEXTURE        10
  348. #define IMAGEMAP_TEXTURE        11
  349. #define PAINTED1_TEXTURE        12 
  350. #define PAINTED2_TEXTURE        13 
  351. #define PAINTED3_TEXTURE        14 
  352. #define ONION_TEXTURE           15 
  353. #define LEOPARD_TEXTURE         16 
  354. #define BRICK_TEXTURE           17 /* RHA 2/92 for brick */
  355. #define MATERIAL_MAP_TEXTURE    99 /* Not really colored, but... CdW */
  356.  
  357. /* Normal perturbation (bumpy) texture list  */
  358. #define NO_BUMPS   0
  359. #define WAVES      1
  360. #define RIPPLES    2
  361. #define WRINKLES   3
  362. #define BUMPS      4
  363. #define DENTS      5
  364. #define BUMPY1     6
  365. #define BUMPY2     7
  366. #define BUMPY3     8
  367. #define BUMPMAP    9
  368.  
  369. struct Texture_Struct
  370. {
  371.    TEXTURE *Next_Texture;
  372.    TEXTURE *Next_Material;
  373.    int Number_Of_Materials;
  374.    DBL Object_Reflection;
  375.    DBL Object_Ambient;
  376.    DBL Object_Diffuse, Object_Brilliance;
  377.    DBL Object_Index_Of_Refraction;
  378.    DBL Object_Refraction, Object_Transmit;
  379.    DBL Object_Specular, Object_Roughness;
  380.    DBL Object_Phong, Object_PhongSize;
  381.    DBL Bump_Amount;
  382.    DBL Texture_Randomness;
  383.    DBL Frequency;
  384.    DBL Phase;
  385.    int Texture_Number;
  386.    int Bump_Number;
  387.    int Texture_Index;
  388.    TRANSFORMATION *Texture_Transformation;
  389.    COLOUR *Colour1;
  390.    COLOUR *Colour2;
  391.    DBL Turbulence;
  392.    VECTOR Texture_Gradient;
  393.    COLOUR_MAP *Colour_Map;
  394.    IMAGE *Image;
  395.    IMAGE *Bump_Image;
  396.    IMAGE *Material_Image;
  397.    short Metallic_Flag, Once_Flag, Constant_Flag;
  398.    int Octaves; /* dmf, 1/92 for turb */
  399.    DBL Mortar;  /* rha, 2/92 for brick */
  400. };
  401.  
  402. /* Object/shape types */
  403. #define SPHERE_TYPE            0
  404. #define TRIANGLE_TYPE          1
  405. #define SMOOTH_TRIANGLE_TYPE   2
  406. #define PLANE_TYPE             3
  407. #define QUADRIC_TYPE           4
  408. #define POLY_TYPE              5
  409. #define BICUBIC_PATCH_TYPE     6
  410. #define COMPOSITE_TYPE         7
  411. #define OBJECT_TYPE            8
  412. #define CSG_UNION_TYPE         9
  413. #define CSG_INTERSECTION_TYPE 10
  414. #define CSG_DIFFERENCE_TYPE   11
  415. #define VIEWPOINT_TYPE        12
  416. #define HEIGHT_FIELD_TYPE     13
  417. #define POINT_LIGHT_TYPE      14
  418. #define SPOT_LIGHT_TYPE       15
  419. #define BOX_TYPE              16
  420. #define BLOB_TYPE             17
  421.  
  422. struct Object_Struct
  423. {
  424.    METHODS *Methods;
  425.    int Type;
  426.    struct Object_Struct *Next_Object;
  427.    /*   struct Object_Struct *Next_Light_Source; */
  428.    SHAPE *Bounding_Shapes;
  429.    SHAPE *Clipping_Shapes;
  430.    SHAPE *Shape;
  431.    char No_Shadow_Flag;
  432.    COLOUR *Object_Colour;
  433.    TEXTURE *Object_Texture;
  434. };
  435.  
  436.  
  437. typedef INTERSECTION *(*INTERSECTION_METHOD)PARAMS((OBJECT *, RAY *));
  438. typedef int (*ALL_INTERSECTIONS_METHOD)PARAMS((OBJECT *, RAY *, PRIOQ *));
  439. typedef int (*INSIDE_METHOD)PARAMS((VECTOR *, OBJECT *));
  440. typedef void (*NORMAL_METHOD)PARAMS((VECTOR *, OBJECT *, VECTOR *));
  441. typedef void *(*COPY_METHOD)PARAMS((OBJECT *));
  442. typedef void (*TRANSLATE_METHOD)PARAMS((OBJECT *, VECTOR *));
  443. typedef void (*ROTATE_METHOD)PARAMS((OBJECT *, VECTOR *));
  444. typedef void (*SCALE_METHOD)PARAMS((OBJECT *, VECTOR *));
  445. typedef void (*INVERT_METHOD)PARAMS((OBJECT *));
  446.  
  447. struct Method_Struct
  448. {
  449.    INTERSECTION_METHOD Intersection_Method;
  450.    ALL_INTERSECTIONS_METHOD All_Intersections_Method;
  451.    INSIDE_METHOD Inside_Method;
  452.    NORMAL_METHOD Normal_Method;
  453.    COPY_METHOD Copy_Method;
  454.    TRANSLATE_METHOD Translate_Method;
  455.    ROTATE_METHOD Rotate_Method;
  456.    SCALE_METHOD Scale_Method;
  457.    INVERT_METHOD Invert_Method;
  458. };
  459.  
  460.  
  461. #define All_Intersections(x,y,z) ((*((x)->Methods->All_Intersections_Method)) (x,y,z))
  462. #define Intersection(x,y) ((INTERSECTION *) ((*((x)->Methods->Intersection_Method)) (x,y)))
  463. #define Inside(x,y) ((*((y)->Methods->Inside_Method)) (x,y))
  464. #define Normal(x,y,z) ((*((y)->Methods->Normal_Method)) (x,y,z))
  465. #define Copy(x) ((*((x)->Methods->Copy_Method)) (x))
  466. #define Translate(x,y) ((*((x)->Methods->Translate_Method)) (x,y))
  467. #define Scale(x,y) ((*((x)->Methods->Scale_Method)) (x,y))
  468. #define Rotate(x,y) ((*((x)->Methods->Rotate_Method)) (x,y))
  469. #define Invert(x) ((*((x)->Methods->Invert_Method)) (x))
  470.  
  471. struct Viewpoint_Struct
  472. {
  473.    METHODS *Methods;
  474.    int Type;
  475.    VECTOR Location;
  476.    VECTOR Direction;
  477.    VECTOR Up;
  478.    VECTOR Right;
  479.    VECTOR Sky;
  480. };
  481.  
  482.  
  483. struct Object_Shape
  484. {
  485.    METHODS *Methods;
  486.    int Type;
  487.    struct Object_Shape *Next_Object;
  488.    void *Parent_Object;
  489.    TEXTURE *Shape_Texture;
  490.    COLOUR *Shape_Colour;
  491. };
  492.  
  493.  
  494. struct Sphere_Shape
  495. {
  496.    METHODS *Methods;
  497.    int Type;
  498.    SHAPE *Next_Object;
  499.    OBJECT *Parent_Object;
  500.    TEXTURE *Shape_Texture;
  501.    COLOUR *Shape_Colour;
  502.    VECTOR  Center;
  503.    DBL     Radius;
  504.    DBL     Radius_Squared;
  505.    DBL     Inverse_Radius;
  506.    VECTOR  VPOtoC;
  507.    DBL     VPOCSquared;
  508.    short   VPinside, VPCached, Inverted;
  509. };
  510.  
  511. struct Box_Shape
  512. {
  513.    METHODS *Methods;
  514.    int Type;
  515.    SHAPE *Next_Object;
  516.    OBJECT *Parent_Object;
  517.    TEXTURE *Shape_Texture;
  518.    COLOUR *Shape_Colour;
  519.    TRANSFORMATION *Transform;
  520.    VECTOR bounds[2];
  521.    short Inverted;
  522. };
  523.  
  524. /* Blob types */
  525. typedef struct {
  526.    VECTOR pos;
  527.    DBL radius2;
  528.    DBL coeffs[3];
  529.    DBL tcoeffs[5];
  530. } Blob_Element;
  531.  
  532. typedef struct blob_list_struct *blobstackptr;
  533. struct blob_list_struct {
  534.    Blob_Element elem;
  535.    blobstackptr next;
  536. };
  537.  
  538. typedef struct {
  539.    int type, index;
  540.    DBL bound;
  541. } Blob_Interval;
  542.  
  543. struct Blob_Shape
  544. {
  545.    METHODS *Methods;
  546.    int Type;
  547.    SHAPE *Next_Object;
  548.    OBJECT *Parent_Object;
  549.    TEXTURE *Shape_Texture;
  550.    COLOUR *Shape_Colour;
  551.    TRANSFORMATION *Transform;
  552.    short Inverted;
  553.    int count;
  554.    DBL threshold;
  555.    Blob_Element *list;
  556.    Blob_Interval *intervals;
  557.    int Sturm_Flag;
  558. };
  559.  
  560. struct Light_Source_Shape
  561. {
  562.    METHODS *Methods;
  563.    int Type;
  564.    SHAPE *Next_Object;
  565.    OBJECT *Parent_Object;
  566.    TEXTURE *Shape_Texture;
  567.    COLOUR *Shape_Colour;
  568.    VECTOR  Center, Points_At;
  569.    LIGHT_SHAPE *Next_Light_Source;
  570.    short Inverted;
  571.    DBL Coeff, Radius, Falloff;
  572. };
  573.  
  574. struct Quadric_Shape
  575. {
  576.    METHODS *Methods;
  577.    int Type;
  578.    SHAPE *Next_Object;
  579.    OBJECT *Parent_Object;
  580.    TEXTURE *Shape_Texture;
  581.    COLOUR *Shape_Colour;
  582.    VECTOR  Object_2_Terms;
  583.    VECTOR  Object_Mixed_Terms;
  584.    VECTOR  Object_Terms;
  585.    DBL Object_Constant;
  586.    DBL Object_VP_Constant;
  587.    int Constant_Cached;
  588.    int Non_Zero_Square_Term;
  589. };
  590.  
  591.  
  592. #define GIF 0   /* These are the types of image maps which can be used as a */
  593. #define POT 1   /* height field. */
  594. #define TGA 2
  595.  
  596. typedef struct {
  597.    DBL min_y, max_y;
  598. } HF_BLOCK;
  599.  
  600. struct Height_Field_Shape
  601. {
  602.    METHODS *Methods;
  603.    int Type;
  604.    SHAPE *Next_Object;
  605.    OBJECT *Parent_Object;
  606.    TEXTURE *Shape_Texture;
  607.    COLOUR *Shape_Colour;
  608.    TRANSFORMATION *Transformation;
  609.    BOX *bounding_box;
  610.    DBL Block_Size;
  611.    DBL Inv_Blk_Size;
  612.    HF_BLOCK **Block;
  613.    float **Map;
  614. };
  615.  
  616. #define MAX_ORDER 7
  617.  
  618. struct Poly_Shape
  619. {
  620.    METHODS *Methods;
  621.    int Type;
  622.    SHAPE *Next_Object;
  623.    OBJECT *Parent_Object;
  624.    TEXTURE *Shape_Texture;
  625.    COLOUR *Shape_Colour;
  626.    TRANSFORMATION *Transform;
  627.    short Inverted;
  628.    int Order, Sturm_Flag;
  629.    DBL *Coeffs;
  630. };
  631.  
  632.  
  633. typedef struct Bezier_Node_Struct BEZIER_NODE;
  634. typedef struct Bezier_Child_Struct BEZIER_CHILDREN;
  635. typedef struct Bezier_Vertices_Struct BEZIER_VERTICES;
  636.  
  637.  
  638. struct Bezier_Child_Struct
  639. {
  640.    BEZIER_NODE *Children[4];
  641. };
  642.  
  643.  
  644. struct Bezier_Vertices_Struct
  645. {
  646.    VECTOR Vertices[4];
  647. };
  648.  
  649.  
  650. struct Bezier_Node_Struct
  651. {
  652.    int Node_Type;      /* Is this an interior node, or a leaf */
  653.    VECTOR Center;      /* Center of sphere bounding the (sub)patch */
  654.    DBL Radius_Squared; /* Radius of bounding sphere (squared) */
  655.    int Count;          /* # of subpatches associated with this node */
  656.    void *Data_Ptr;     /* Either pointer to vertices or pointer to children */
  657. };
  658.  
  659.  
  660. #define BEZIER_INTERIOR_NODE 0
  661. #define BEZIER_LEAF_NODE 1
  662. #define MAX_BICUBIC_INTERSECTIONS 32
  663.  
  664.  
  665. struct Bicubic_Patch_Shape
  666. {
  667.    METHODS *Methods;
  668.    int Type;
  669.    SHAPE *Next_Object;
  670.    OBJECT *Parent_Object;
  671.    TEXTURE *Shape_Texture;
  672.    COLOUR *Shape_Colour;
  673.    int Patch_Type, U_Steps, V_Steps;
  674.    VECTOR Control_Points[4][4];
  675.    VECTOR Bounding_Sphere_Center;
  676.    DBL Bounding_Sphere_Radius;
  677.    DBL Flatness_Value;
  678.    int Intersection_Count;
  679.    VECTOR Normal_Vector[MAX_BICUBIC_INTERSECTIONS];
  680.    VECTOR Intersection_Point[MAX_BICUBIC_INTERSECTIONS];
  681.    VECTOR **Interpolated_Grid, **Interpolated_Normals, **Smooth_Normals;
  682.    DBL **Interpolated_D;
  683.    BEZIER_NODE *Node_Tree;
  684. };
  685.  
  686.  
  687. #define X_AXIS 0
  688. #define Y_AXIS 1
  689. #define Z_AXIS 2
  690.  
  691.  
  692. struct Triangle_Shape
  693. {
  694.    METHODS *Methods;
  695.    int Type;
  696.    SHAPE *Next_Object;
  697.    OBJECT *Parent_Object;
  698.    TEXTURE *Shape_Texture;
  699.    COLOUR *Shape_Colour;
  700.    VECTOR  Normal_Vector;
  701.    DBL     Distance;
  702.    DBL     VPNormDotOrigin;
  703. unsigned int  VPCached:1;
  704. unsigned int  Dominant_Axis:2;
  705. unsigned int  Inverted:1;
  706. unsigned int  vAxis:2;  /* used only for smooth triangles */
  707.    VECTOR  P1, P2, P3;
  708.    short int Degenerate_Flag;
  709. };
  710.  
  711.  
  712. struct Smooth_Triangle_Shape
  713. {
  714.    METHODS *Methods;
  715.    int Type;
  716.    SHAPE *Next_Object;
  717.    OBJECT *Parent_Object;
  718.    TEXTURE *Shape_Texture;
  719.    COLOUR *Shape_Colour;
  720.    VECTOR  Normal_Vector;
  721.    DBL     Distance;
  722.    DBL     VPNormDotOrigin;
  723. unsigned int  VPCached:1;
  724. unsigned int  Dominant_Axis:2;
  725. unsigned int  Inverted:1;
  726. unsigned int  vAxis:2;         /* used only for smooth triangles */
  727.    VECTOR  P1, P2, P3;
  728.    short int Degenerate_Flag;  /* do not move this field */
  729.    VECTOR  N1, N2, N3, Perp;
  730.    DBL  BaseDelta;
  731. };
  732.  
  733.  
  734.  
  735. struct Plane_Shape
  736. {
  737.    METHODS *Methods;
  738.    int Type;
  739.    SHAPE *Next_Object;
  740.    OBJECT *Parent_Object;
  741.    TEXTURE *Shape_Texture;
  742.    COLOUR *Shape_Colour;
  743.    VECTOR  Normal_Vector;
  744.    DBL     Distance;
  745.    DBL     VPNormDotOrigin;
  746.    int     VPCached;
  747. };
  748.  
  749.  
  750. struct CSG_Type
  751. {
  752.    METHODS *Methods;
  753.    int Type;
  754.    SHAPE *Next_Object;
  755.    OBJECT *Parent_Object;
  756.    SHAPE *Shapes;
  757. };
  758.  
  759.  
  760. struct Composite_Object_Struct
  761. {
  762.    METHODS *Methods;
  763.    int Type;
  764.    OBJECT *Next_Object;
  765.    /*   OBJECT *Next_Light_Source;*/
  766.    SHAPE *Bounding_Shapes;
  767.    SHAPE *Clipping_Shapes;
  768.    OBJECT *Objects;
  769. };
  770.  
  771.  
  772. #define MAX_CONTAINING_OBJECTS 10
  773.  
  774. struct Ray_Struct
  775. {
  776.    VECTOR Initial;               /*  Xo  Yo  Zo  */
  777.    VECTOR Direction;             /*  Xv  Yv  Zv  */
  778.    VECTOR Initial_2;             /*  Xo^2  Yo^2  Zo^2  */
  779.    VECTOR Direction_2;           /*  Xv^2  Yv^2  Zv^2  */
  780.    VECTOR Initial_Direction;     /*  XoXv  YoYv  ZoZv  */
  781.    VECTOR Mixed_Initial_Initial; /*  XoYo  XoZo  YoZo  */
  782.    VECTOR Mixed_Dir_Dir;         /*  XvYv  XvZv  YvZv  */
  783.    VECTOR Mixed_Init_Dir;        /*  XoYv+XvYo  XoZv+XvZo  YoZv+YvZo  */
  784.    int Containing_Index;
  785.    TEXTURE *Containing_Textures [MAX_CONTAINING_OBJECTS];
  786.    DBL Containing_IORs [MAX_CONTAINING_OBJECTS];
  787.    int Quadric_Constants_Cached;
  788. };
  789.  
  790.  
  791. struct Frame_Struct
  792. {
  793.    VIEWPOINT View_Point;
  794.    int Screen_Height, Screen_Width;
  795.    LIGHT_SHAPE *Light_Sources;
  796.    OBJECT *Objects;
  797.    DBL Atmosphere_IOR, Antialias_Threshold;
  798.    DBL Fog_Distance;
  799.    COLOUR Fog_Colour;
  800. };
  801.  
  802.  
  803. #define DISPLAY 1
  804. #define VERBOSE 2
  805. #define DISKWRITE 4
  806. #define PROMPTEXIT 8
  807. #define ANTIALIAS 16
  808. #define DEBUGGING 32
  809. #define RGBSEPARATE 64
  810. #define EXITENABLE 128
  811. #define CONTINUE_TRACE 256
  812. #define VERBOSE_FILE 512
  813.  
  814. #define Make_Colour(c,r,g,b) { (c)->Red=(r);(c)->Green=(g);(c)->Blue=(b); (c)->Alpha=0.0; }
  815.  
  816. #define Make_Vector(v,a,b,c) { (v)->x=(a);(v)->y=(b);(v)->z=(c); }
  817.  
  818. /* Definitions for PRIOQ structure */
  819.  
  820. struct q_entry
  821. {
  822.    DBL Depth;
  823.    OBJECT *Object;
  824.    VECTOR Point;
  825.    SHAPE *Shape;
  826. };
  827.  
  828. struct prioq_struct
  829. {
  830.    struct prioq_struct *next_pq;
  831.    struct q_entry *queue;
  832.    unsigned int current_entry, queue_size;
  833. };
  834.  
  835.  
  836. /* Token Definitions for Parser */
  837. /* This list must have the same number of tokens as list in tokenize.c */
  838. #define AGATE_TOKEN                  0
  839. #define ALL_TOKEN                    1
  840. #define ALPHA_TOKEN                  2
  841. #define AMBIENT_TOKEN                3
  842. #define AMPERSAND_TOKEN              4
  843. #define AT_TOKEN                     5
  844. #define BACK_QUOTE_TOKEN             6
  845. #define BACK_SLASH_TOKEN             7
  846. #define BAR_TOKEN                    8
  847. #define BICUBIC_PATCH_TOKEN          9
  848. #define BLUE_TOKEN                  10
  849. #define BRILLIANCE_TOKEN            11
  850. #define BOZO_TOKEN                  12
  851. #define BOUNDED_TOKEN               13
  852. #define BUMPS_TOKEN                 14
  853. #define CHECKER_TOKEN               15
  854. #define CHECKER_TEXTURE_TOKEN       16
  855. #define CLIPPED_TOKEN               17
  856. #define COLON_TOKEN                 18
  857. #define COLOR_TOKEN                 19
  858. #define COLOUR_TOKEN                20
  859. #define COLOR_MAP_TOKEN             21
  860. #define COLOUR_MAP_TOKEN            22
  861. #define COMMA_TOKEN                 23
  862. #define COMPOSITE_TOKEN             24
  863. #define CONCENTRATION_TOKEN         25
  864. #define CUBIC_TOKEN                 26
  865. #define DASH_TOKEN                  27
  866. #define DECLARE_TOKEN               28
  867. #define DENTS_TOKEN                 29
  868. #define DIFFERENCE_TOKEN            30
  869. #define DIFFUSE_TOKEN               31
  870. #define DIRECTION_TOKEN             32
  871. #define DOLLAR_TOKEN                33
  872. #define DUMP_TOKEN                  34
  873. #define EQUALS_TOKEN                35
  874. #define EXCLAMATION_TOKEN           36
  875. #define FLOAT_TOKEN                 37
  876. #define FOG_TOKEN                   38
  877. #define FREQUENCY_TOKEN             39
  878. #define GIF_TOKEN                   40
  879. #define GRADIENT_TOKEN              41
  880. #define GRANITE_TOKEN               42
  881. #define GREEN_TOKEN                 43
  882. #define HASH_TOKEN                  44
  883. #define HAT_TOKEN                   45
  884. #define IDENTIFIER_TOKEN            46
  885. #define IFF_TOKEN                   47
  886. #define IMAGEMAP_TOKEN              48
  887. #define INCLUDE_TOKEN               49
  888. #define INTERSECTION_TOKEN          50
  889. #define INVERSE_TOKEN               51
  890. #define IOR_TOKEN                   52
  891. #define LEFT_ANGLE_TOKEN            53
  892. #define LEFT_CURLY_TOKEN            54
  893. #define LEFT_SQUARE_TOKEN           55
  894. #define LIGHT_SOURCE_TOKEN          56
  895. #define LOCATION_TOKEN              57
  896. #define LOOK_AT_TOKEN               58
  897. #define MARBLE_TOKEN                59
  898. #define METALLIC_TOKEN              60
  899. #define OBJECT_TOKEN                61
  900. #define ONCE_TOKEN                  62
  901. #define PERCENT_TOKEN               63
  902. #define PHASE_TOKEN                 64
  903. #define PHONG_TOKEN                 65
  904. #define PHONGSIZE_TOKEN             66
  905. #define PLANE_TOKEN                 67
  906. #define PLUS_TOKEN                  68
  907. #define POINTS_TOKEN                69
  908. #define POINT_AT_TOKEN              70
  909. #define POLYGON_TOKEN               71
  910. #define POLY_TOKEN                  72
  911. #define QUADRIC_TOKEN               73
  912. #define QUARTIC_TOKEN               74 
  913. #define QUESTION_TOKEN              75
  914. #define RAW_TOKEN                   76
  915. #define RED_TOKEN                   77
  916. #define REFLECTION_TOKEN            78 
  917. #define REFRACTION_TOKEN            79
  918. #define REVOLVE_TOKEN               80
  919. #define RIGHT_TOKEN                 81
  920. #define RIGHT_ANGLE_TOKEN           82
  921. #define RIGHT_PAREN_TOKEN           83
  922. #define RIGHT_SQUARE_TOKEN          84
  923. #define RIPPLES_TOKEN               85
  924. #define ROTATE_TOKEN                86
  925. #define ROUGHNESS_TOKEN             87
  926. #define SCALE_TOKEN                 88
  927. #define SEMI_COLON_TOKEN            89
  928. #define SHAPE_TOKEN                 90
  929. #define SINGLE_QUOTE_TOKEN          91
  930. #define SIZE_TOKEN                  92
  931. #define SKY_TOKEN                   93
  932. #define SLASH_TOKEN                 94
  933. #define SMOOTH_TRIANGLE_TOKEN       95
  934. #define SPECULAR_TOKEN              96
  935. #define SPHERE_TOKEN                97
  936. #define SPOTLIGHT_TOKEN             98
  937. #define SPOTTED_TOKEN               99
  938. #define STAR_TOKEN                  100
  939. #define STRING_TOKEN                101
  940. #define STURM_TOKEN                 102
  941. #define TEXTURE_TOKEN               103
  942. #define TILDE_TOKEN                 104
  943. #define TILE2_TOKEN                 105
  944. #define TRANSLATE_TOKEN             106
  945. #define TRANSMIT_TOKEN              107
  946. #define TRIANGLE_TOKEN              108
  947. #define TURBULENCE_TOKEN            109
  948. #define UNION_TOKEN                 110
  949. #define UP_TOKEN                    111
  950. #define VIEW_POINT_TOKEN            112
  951. #define WAVES_TOKEN                 113
  952. #define WOOD_TOKEN                  114
  953. #define WRINKLES_TOKEN              115 
  954. #define PAINTED1_TOKEN              116 
  955. #define PAINTED2_TOKEN              117
  956. #define PAINTED3_TOKEN              118
  957. #define BUMPY1_TOKEN                119
  958. #define BUMPY2_TOKEN                120
  959. #define BUMPY3_TOKEN                121
  960. #define BUMPMAP_TOKEN               122
  961. #define BUMPSIZE_TOKEN              123
  962. #define MATERIAL_MAP_TOKEN          124 
  963. #define ONION_TOKEN                 125
  964. #define LEOPARD_TOKEN               126
  965. #define DUMMY_TOKEN                 127 /* Dummy token to pad list because some colour_tokens are used twice */
  966. #define INTERPOLATE_TOKEN           128
  967. #define HEIGHT_FIELD_TOKEN          129
  968. #define POT_TOKEN                   130 
  969. #define WATER_LEVEL_TOKEN           131
  970. #define USE_COLOUR_TOKEN            132
  971. #define USE_INDEX_TOKEN             133
  972. #define MAPTYPE_TOKEN               134
  973. #define RIGHT_CURLY_TOKEN           135
  974. #define LEFT_PAREN_TOKEN            136
  975. #define TGA_TOKEN                   137 /* ARE 11/91 for tga mapp/heights */
  976. #define CENTER_TOKEN                138 /* ARE 11/91 for spotlight */
  977. #define FALLOFF_TOKEN               139 /* ARE 11/91 for spotlight */
  978. #define TIGHTNESS_TOKEN             140 /* ARE 11/91 for spotlight */
  979. #define RADIUS_TOKEN                141 /* ARE 11/91 for spotlight */
  980. #define NO_SHADOW_TOKEN             142 /* CEY 12/91 for shadowless objects */
  981. #define END_OF_FILE_TOKEN           143
  982. #define MAX_TRACE_LEVEL_TOKEN       144
  983. #define DEFAULT_TOKEN               145
  984. #define BOX_TOKEN                   146 /* ARE 1/92 for boxes */
  985. #define BLOB_TOKEN                  147 /* ARE 1/92 for blobs */
  986. #define THRESHOLD_TOKEN             148 /* ARE 1/92 for blobs */
  987. #define COMPONENT_TOKEN             149 /* ARE 1/92 for blobs */
  988. #define OCTAVES_TOKEN               150 /* DMF 2/92 for turb  */
  989. #define BRICK_TOKEN                 151 /* RHA 2/92 for brick */
  990. #define MORTAR_TOKEN                152 /* RHA 2/92 for brick */
  991. #define LOST_TOKEN                  153
  992. #define LAST_TOKEN                  154
  993.  
  994.  
  995. struct Reserved_Word_Struct
  996. {                                
  997.    TOKEN Token_Number;
  998.    char *Token_Name;
  999. };
  1000.  
  1001. /* Here's where you dump the information on the current token (fm. PARSE.C) */
  1002.  
  1003. struct Token_Struct
  1004. {
  1005.    TOKEN Token_Id;
  1006.    int Token_Line_No;
  1007.    char *Token_String;
  1008.    DBL Token_Float;
  1009.    int Identifier_Number;
  1010.    int Unget_Token, End_Of_File;
  1011.    char *Filename;
  1012. };
  1013.  
  1014. /* Types of constants allowed in DECLARE statement (fm. PARSE.C) */
  1015.  
  1016. #define OBJECT_CONSTANT            0
  1017. #define VIEW_POINT_CONSTANT        1
  1018. #define VECTOR_CONSTANT            2
  1019. #define FLOAT_CONSTANT             3
  1020. #define COLOUR_CONSTANT            4
  1021. #define QUADRIC_CONSTANT           5
  1022. #define POLY_CONSTANT              6
  1023. #define BICUBIC_PATCH_CONSTANT     7
  1024. #define SPHERE_CONSTANT            8
  1025. #define PLANE_CONSTANT             9
  1026. #define TRIANGLE_CONSTANT         10
  1027. #define SMOOTH_TRIANGLE_CONSTANT  11  
  1028. #define CSG_INTERSECTION_CONSTANT 12   
  1029. #define CSG_UNION_CONSTANT        13
  1030. #define CSG_DIFFERENCE_CONSTANT   14
  1031. #define COMPOSITE_CONSTANT        15
  1032. #define TEXTURE_CONSTANT          16
  1033. #define HEIGHT_FIELD_CONSTANT     17
  1034. #define BOX_CONSTANT              18
  1035. #define BLOB_CONSTANT             19
  1036. #define LIGHT_SOURCE_CONSTANT     20
  1037.  
  1038. struct Constant_Struct
  1039. {
  1040.    int Identifier_Number;
  1041.    CONSTANT Constant_Type;
  1042.    char *Constant_Data;
  1043. };
  1044.  
  1045. struct Chunk_Header_Struct {
  1046.    long name;
  1047.    long size;
  1048. };
  1049.  
  1050. struct Data_File_Struct {
  1051.    FILE *File;
  1052.    char *Filename;
  1053.    int Line_Number;
  1054. };
  1055.  
  1056. struct complex_block {
  1057.    DBL r, c;
  1058. };
  1059.  
  1060. #define READ_MODE 0
  1061. #define WRITE_MODE 1
  1062. #define APPEND_MODE 2
  1063.  
  1064. struct file_handle_struct {
  1065.    char *filename;
  1066.    int  mode;
  1067.    int width, height;
  1068.    int buffer_size;
  1069.    char *buffer;
  1070.    FILE *file;
  1071.    char *(*Default_File_Name_p) PARAMS((void));
  1072.    int  (*Open_File_p) PARAMS((struct file_handle_struct *handle,
  1073.       char *name, int *width, int *height, int buffer_size,
  1074.       int mode));
  1075.    void (*Write_Line_p) PARAMS((struct file_handle_struct *handle,
  1076.       COLOUR *line_data, int line_number));
  1077.    int  (*Read_Line_p) PARAMS((struct file_handle_struct *handle,
  1078.       COLOUR *line_data, int *line_number));
  1079.    void (*Read_Image_p) PARAMS((IMAGE *Image, char *filename));
  1080.    void (*Close_File_p) PARAMS((struct file_handle_struct *handle));
  1081. };
  1082.  
  1083. typedef struct file_handle_struct FILE_HANDLE;
  1084.  
  1085. #define Default_File_Name(h) ((*((h)->Default_File_Name_p)) ())
  1086. #define Open_File(h,n,wd,ht,sz,m) ((*((h)->Open_File_p)) (h,n,wd,ht,sz,m))
  1087. #define Write_Line(h,l,n) ((*((h)->Write_Line_p)) (h, l, n))
  1088. #define Read_Line(h,l,n) ((*((h)->Read_Line_p)) (h, l, n))
  1089. #define Read_Image(h,i) ((*((h)->Read_Image_p)) (h, i))
  1090. #define Close_File(h) ((*((h)->Close_File_p)) (h))
  1091.