home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / rad386 / radiosit / src / data_str.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-24  |  5.8 KB  |  226 lines

  1. #ifndef DATA_S
  2.  
  3. #define DATA_S
  4.  
  5. #define MAXCHANNELS 3
  6. #define MAXSOURCES 10
  7.  
  8. #define EPSILON 0.00001
  9. #define LARGE 1e30
  10.  
  11. #define UNDEFINED -1
  12.  
  13. #define MAX_REFLECTION_TYPE 3
  14. /* For surface_reflection_type */
  15. #define DIFFUSE 0
  16. #define MIRROR 1
  17. #define OTHER_REFLECTION 2
  18.  
  19. #define For_Grids_Only 0
  20. #define For_Main_Surfaces_Only 1
  21. #define MAX_GEOMETRY_TYPE 10
  22. /* For surface_geometry_type */
  23. #define QUADRILATERAL 0
  24. #define SPHERE 1
  25. #define BUBBLE 2
  26. #define CYLINDER 3
  27. #define TUBE 4
  28. #define CONE 5
  29. #define CUP  6
  30. #define RING 7
  31. #define POLYGON 8
  32. #define OTHER_GEOMETRY 9
  33.  
  34. #define point_on_line(s,d,t,p) {(p).x=(s).x+t*(d).x;(p).y=(s).y+t*(d).y;(p).z=(s).z+t*(d).z;}
  35. #define project_point(p,P,i) {\
  36.     switch(i){\
  37.         case 0 : /* X axis */\
  38.             p.x = (P).y; p.y = (P).z; break;\
  39.         case 1 : /* Y axis */\
  40.             p.x = (P).z; p.y = (P).x; break;\
  41.         case 2 : /* Z axis */\
  42.             p.x = (P).x; p.y = (P).y; break;\
  43.     }\
  44. }
  45.         
  46. #define set_t(lo,hi)   if ((nroots > 1)&&(roots[1] > EPSILON)&&\
  47.             ((roots[0] < EPSILON)||(roots[1] < roots[0]))&&\
  48.             check(roots[1],ray_start,ray_direction,lo,hi))\
  49.                  t = roots[1];\
  50.                 else if((roots[0] > EPSILON)&&\
  51.             check(roots[0],ray_start,ray_direction,lo,hi))\
  52.                 t = roots[0]
  53. #define circle_inverse_mapping(r,x,y,u) {\
  54.         double value=x/r;\
  55.         if (value > 1.) u = 0;\
  56.         else if (value < -1.) u = 0.5;\
  57.         else u = acos(value)/(2.*PI);\
  58.         if (y < 0.) u = 1. - u;\
  59. }
  60.  
  61.     typedef struct SECONDARYRAY{
  62.         Point3 start;
  63.         Vector3 direction;
  64.         double weight;
  65.         struct SECONDARYRAY *next;
  66.     } SecondaryRay;
  67.  
  68.     typedef struct{
  69.         Point3 start;
  70.         Vector3 direction;
  71.         double path_length;
  72.         long number;
  73.         int channel;
  74.         int source_number;
  75.         double weight;
  76.         SecondaryRay *sec_ray_list;
  77. #if defined (DEBUG)
  78.             long intersections;
  79. #endif
  80.     }Ray;
  81.  
  82. typedef struct {
  83.         double strength[MAXCHANNELS]; 
  84.             /*Related to Wattage of the Source Light.*/
  85.         int oindex;
  86.         int emission_type; /* 0 - Diffuse, 1 - Directional,...*/
  87.         Vector3 dir;
  88.         double spread;
  89.         Matrix4 xform;
  90. }Source;
  91.  
  92.     typedef struct{
  93.         double normalized_flux_density[MAXCHANNELS];
  94.         double area;
  95.     }Surface_Grid_structure;
  96. #define grid_u(n,u) (object[n].grid_h_reso*u)
  97. #define grid_v(n,v) (object[n].grid_v_reso*v)
  98. #define gridindex(n,u,v) (\
  99.     (((v)<0)?0:(((v)>=object[n].grid_v_reso)?(object[n].grid_v_reso-1):(v)))\
  100.     *object[n].grid_h_reso+\
  101.     (((u)<0)?0:(((u)>=object[n].grid_h_reso)?(object[n].grid_h_reso-1):(u)))\
  102.     )
  103.  
  104. typedef struct{
  105.     Surface_Grid_structure *grid;
  106.     int grid_v_reso,grid_h_reso;
  107.     char surface_geometry_type;
  108.     char surface_reflection_type;
  109.     double reflectance[MAXCHANNELS]; /* Hemispherical Reflectance */
  110.     void *object_specific_structure;
  111.     /* Following two entities for acceleration of ray object
  112.        intersection using Spacial Enumeration Technique. */
  113.     struct {             
  114.         long ray_num;
  115.         double t,u,v;
  116.     }mail_box;
  117.     Box3 bbox;
  118.     int start_grid_index; /* For Radiosity Use */
  119.     double normalized_flux_density[MAXCHANNELS];
  120. } Obj;
  121.  
  122.  
  123.         /* Begin object_specific_structures */
  124.         typedef struct{
  125.             int nvertices;
  126.             Point3 *vertex_list;
  127.             /* Computed data */
  128.                         Vector3 plane_normal;
  129.                         double plane_constant;
  130.             char dominant_axis_flag;
  131.                 /* 0 - for X-axis, 1 - for Y-axis, 2 - for Z axis */
  132.             Matrix4 local_trans;
  133.         }Polygon;
  134.  
  135.                 typedef struct{
  136.                         Point3 P00,P10,P11,P01;
  137.             /* Computed data */
  138.                         Vector3 plane_normal;
  139.                         double plane_constant;
  140.                         Vector3 Na,Nb,Nc;
  141.                         Vector3 Qux,Quy,Qvx,Qvy;
  142.                         double Du0,Du1,Du2,Dux,Duy,Dv0,Dv1,Dv2,Dvx,Dvy;
  143.                         Matrix4 local_trans;
  144.                 }Quadrilateral;
  145.  
  146.                 typedef struct{
  147.                         Point3 center;
  148.                         double radius;
  149.                 }Sphere;
  150.  
  151.         typedef struct{
  152.             Point3 base_point1, base_point2;
  153.             double radius;
  154.             /* Computed data */
  155.             double height;
  156.             Matrix4 world_to_object, object_to_world;
  157.         } Cylinder;
  158.  
  159.         typedef struct{
  160.             Point3 apex_point;
  161.             double apex_radius;
  162.             Point3 base_point;
  163.             /* Computed data */
  164.             double base_radius;
  165.             Vector3 axis;
  166.             Matrix4 world_to_object, object_to_world;
  167.             double distance;
  168.         } Cone; /* 0 <= apex_radius <= base_radius */
  169.  
  170.         typedef struct{
  171.             Point3 center;
  172.             Vector3 normal;
  173.             double inner_radius,outer_radius ;
  174.             /* Computed data */
  175.             Matrix4 world_to_object,object_to_world;
  176.         } Ring;
  177.  
  178. typedef struct{
  179.     Box3 extent;
  180.     int *intersecting_object_list;
  181.     int nobjects;
  182. } Voxel;
  183.  
  184.  
  185. typedef struct{
  186.         Box3 extent;
  187.         Voxel *voxels;
  188.         int x_subdivision,y_subdivision,z_subdivision;
  189.         Point3 voxel_size;
  190.         Point3 voxel_density;
  191. }Volume_grid;
  192.  
  193. #define x2voxel(v,a) (((a)-(v).extent.min.x)*(v).voxel_density.x)
  194. #define y2voxel(v,a) (((a)-(v).extent.min.y)*(v).voxel_density.y)
  195. #define z2voxel(v,a) (((a)-(v).extent.min.z)*(v).voxel_density.z)
  196. #define voxel2x(v,a) ((a)*(v).voxel_size.x+(v).extent.min.x)
  197. #define voxel2y(v,a) ((a)*(v).voxel_size.y+(v).extent.min.y)
  198. #define voxel2z(v,a) ((a)*(v).voxel_size.z+(v).extent.min.z)
  199. #define voxel_index(v,x,y,z) ((x*(v).y_subdivision+y)*(v).z_subdivision+z)
  200. #define voxel_addr(v,x,y,z) ((v).voxels+voxel_index(v,x,y,z))
  201.  
  202. extern int color_channels;
  203. extern int number_objects;
  204. extern int light_sources;
  205. extern Obj *object;
  206. extern Source source[];
  207. extern Volume_grid volume_grid;
  208. extern int total_surface_grid_points;
  209. extern long total_rays;
  210. extern int intensity_out_flag;
  211. extern int verbose_output_flag;
  212.  
  213. void mirror_reflection();
  214. void align_Z_to_axis();
  215. void align_axis_to_Z();
  216. Vector3 transform_vector();
  217. int bounds_overlap();
  218. Point3 get_bilinear();
  219. double *alloc_counters();
  220. void scale();
  221. void translate();
  222. void *calloc();
  223. void bound_transform();
  224.  
  225. #endif
  226.