home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / raytrace / radiance / simplerd.lha / simplerad / FinalFTP / Light / geo.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-20  |  5.3 KB  |  147 lines

  1. /**********************************************************************/
  2. /* Geometric primitives (general)                                     */
  3. /*                                                                    */
  4. /* Copyright (C) 1992, Bernard Kwok                                   */
  5. /* All rights reserved.                                               */
  6. /* Revision 1.0                                                       */
  7. /* May, 1992                                                          */
  8. /**********************************************************************/
  9. #ifndef GEO_H
  10. #define GEO_H
  11.  
  12. #ifndef IRIS4D
  13. typedef double Matrix[4][4];              /* 4x4 transformation matrix */
  14. static Matrix Identity = {
  15.   1.0, 0.0, 0.0, 0.0,
  16.   0.0, 1.0, 0.0, 0.0,
  17.   0.0, 0.0, 1.0, 0.0,
  18.   0.0, 0.0, 0.0, 1.
  19.   };  
  20. #endif /* IRIS4D */
  21.  
  22. #define Point_On_Ray(v1,s,v2,r)    (r).x = (v1).x + (s)*(v2).x, \
  23.                 (r).y = (v1).y + (s)*(v2).y, \
  24.                 (r).z = (v1).z + (s)*(v2).z
  25. /* Two components are "equal"         */
  26. #define MIN_EQUAL (0.000001)
  27. #define equal(a, b) (fabs((a) - (b)) < MIN_EQUAL)
  28.  
  29. /**********************************************************************/
  30. /* 2D / 3D  geometry */
  31. /**********************************************************************/
  32. typedef struct { double x,y; } Vector2;   /* 2D Vector */
  33. typedef Vector2 point2;                  /* 2D Point  */
  34. typedef struct { int x,y;}  Intpoint2; /* 2d integer point */
  35. typedef struct { double element[3][3]; } Matrix3; 
  36. typedef struct Box2dStruct { point2 min, max; } Box2; /* 2d box */
  37.  
  38. typedef struct { int x,y,z; } Intpoint3; /* 3d integer point */
  39. typedef struct { double element[4][4]; } Matrix4; 
  40. typedef struct { double x,y,z; } point3; /* 3D Point  */
  41. typedef struct { point3 min, max; } Box;
  42.  
  43. /**********************************************************************/
  44. typedef struct { double x,y,z; } Vector; /* 3D Vector */
  45. typedef struct {double x,y,z,h;} point4; /* 4D Point  */
  46.  
  47. typedef struct {  
  48.   Vector n;                      /* normal */
  49.   Vector p;                      /* point on plane */
  50.   double d;                      /* distance from origin to plane */
  51. } Plane;                         /* A plane */
  52.  
  53. typedef struct {               
  54.   point3 start;                  /* Start point */
  55.   Vector dir;                    /* vector direction */
  56. } line;                          /* A line */
  57.  
  58. typedef struct {
  59.   Vector min, max;             /* Upper and lower bounds of box */
  60. } BoundingBoxType;               /* bounding box (axis aligned) */
  61.  
  62. typedef struct {
  63.   double r;                    /* Radius of sphere */
  64.   Vector pos;                  /* Position of sphere */
  65. } BoundingSphereType;          /* bounding sphere (axis aligned) */
  66.  
  67. /**********************************************************************/
  68. /* 2-D library */
  69. /**********************************************************************/
  70. double vdot2(); 
  71. double vlen2();
  72. Vector2 *vnegate2();
  73. Vector2 *vnorm2();
  74. Vector2 *vscale2();
  75. Vector2 *vadd2();
  76. Vector2 *vsub2();
  77. Vector2 *vinterp2();
  78. Vector2 *vcomb2();
  79. Vector2 *vmult2();
  80. double vdist2();
  81. Vector2 *vperp2();
  82. Vector2 *vnew2();
  83. Vector2 *vdup2();
  84. point2 *vtransform2();
  85. Matrix3 *multmatrix2();
  86.  
  87. /**********************************************************************/
  88. /* 3-D library */
  89. /**********************************************************************/
  90. double dot();                    /* dot product */
  91. Vector cross();                  /* cross product */
  92. double norm();                   /* vector normalization */
  93. double geo_line();               /* vector from 2 pts */
  94. Vector *vadd();                  /* vector add */
  95. Vector *vsub();                  /* vector subtract */
  96. Vector *vnegate();
  97. Vector *vmult();
  98. Vector *vcomb();                 /* linear combination of 2 vectors */
  99. Vector *vscalar();
  100. double vdist();
  101. double vlen();
  102. Vector *vscale();
  103. Vector *vmiddle();
  104. Vector *vinterp();
  105. Vector *vnew();
  106. Vector *vdup();
  107. Vector polynorm();               /* polygon normal from vertices */
  108. double Power();                  /* fast power function for positive ints */
  109.  
  110. Vector *reflection();            /* ideal reflection vector */
  111. Vector *refraction();            /* ideal simple refraction vector */
  112. Vector *geo_h();                 /* 'half-way' reflection vector */
  113. Vector *geo_ht();                /* 'half-way' refraction vector */
  114.  
  115. /**********************************************************************/
  116. /* Matrix library */
  117. /**********************************************************************/
  118. void copymatrix();               /* copy matrices */
  119. int same_matrix();               /* check if 2 matrices are the same */
  120. void mult_matrix();               /* multiply 2 matrices */
  121. void smult_matrix();
  122. Vector vtransform();             /* Matrix * vector */
  123. point3 *ptransform();
  124. Vector vrotate();                /* Rotate a vector */
  125. void transpose_matrix();
  126. int invert_matrix();             /* Invert matrix */
  127. void cr_rotatez();
  128. void rotatex_matrix();
  129. void rotatey_matrix();
  130. void rotatez_matrix();
  131. void scale_matrix();
  132. void translate_matrix();
  133. void subtract_matrix();
  134. void ZPerspective_matrix();
  135. void reorthogonalize_matrix();
  136. void adjoint();
  137. double det4x4();
  138. double det3x3();
  139. double det2x2();
  140.  
  141. void print_vector();             /* print 3D vector */
  142. void print_vector2();
  143. void print_matrix();             /* print a 4x4 matrix */
  144.  
  145. #endif /* GEO_H */
  146.  
  147.