home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / raytrace / renaisnc / lib.lha / Lib / 4D.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-04  |  4.5 KB  |  211 lines

  1. /*
  2.   File: 4D.h
  3.   Author: K.R. Sloan, Jr.
  4.   Last Modified: 15 August 1985
  5.          04 November 1986 by Karen Foltz
  6.   Purpose: definitions for a 4D homogeneous coordinate manipulation package
  7.  */
  8.  
  9. #define X 0
  10. #define Y 1
  11. #define Z 2
  12. #define W 3
  13.  
  14. typedef struct P4D { double P[4]; } PointType4D;
  15. typedef struct V4D { double V[4]; } VectorType4D;
  16. typedef struct T4D { double T[4][4]; } TransformType4D;
  17.  
  18. /*
  19. ** The origin [0 0 0 1] in homogeneous coordinates. 
  20. */
  21. extern PointType4D Origin;
  22.  
  23. /*
  24. ** The smallest number distinguishable from zero due to error in calculations.
  25. */
  26. extern double epsilon;
  27.  
  28. /*
  29. ** CreatePoint(x,y,z,w) double x,y,z,w;
  30. ** Return the point in homogeneous coordinates [x y z w].
  31. */
  32. extern PointType4D CreatePoint4D();    
  33.  
  34. /*
  35. ** PxT4D(P, T) PointType4D P; TransformType4D T;
  36. ** Multiplies a point times a transformation matrix.
  37. */
  38. extern PointType4D PxT4D();            
  39.  
  40. /*
  41. ** VxT4D(V, T) VectorType4D V; TransformType4D T;
  42. ** Multiplies a vector times a transformation matrix.
  43. */
  44. extern VectorType4D VxT4D();            
  45.  
  46. /*
  47. ** NormalxT4D(NormalVector, TInverse)
  48. **
  49. ** Returns a vector normal to a plane whose points are transformed
  50. ** by T.
  51. */
  52. extern VectorType4D NormalxT4D();
  53.  
  54.  
  55. /*
  56. ** TxT4D(A, B) TransformType4D A, B;            
  57. ** Multiplies two transformation matrices.
  58. */
  59. extern TransformType4D TxT4D();        
  60.  
  61. /*
  62. ** Transpose4D(T) TransformType4D T; 
  63. ** Finds the transpose of a matix.
  64. */
  65. extern TransformType4D Transpose4D(); 
  66.  
  67. /*
  68. ** Identity4D()
  69. ** Returns the identity matrix.
  70. */
  71. extern TransformType4D Identity4D();
  72.  
  73. /*
  74. ** Translate4D(V) VectorType4D V;                   
  75. ** Returns the tranformation matrix which translates by vector V.
  76. */
  77. extern TransformType4D Translate4D();  
  78.  
  79. /*
  80. ** Scale4D(P) PointType4D P;
  81. ** Returns the tranformation matrix which scales by [x y z w].
  82. */
  83. extern TransformType4D Scale4D();      
  84.  
  85. /*
  86. ** UniformScale4D(s) double s;
  87. ** Returns the tranformation matrix which scales uniformly by s.
  88. */
  89. extern TransformType4D UniformScale4D();
  90.  
  91. /*
  92. ** Rotate4D(P0, P, Radians) PointType4D P0, P; double Radians;
  93. ** Returns the transformation matrix which rotates by angle "Radians" 
  94. ** about the vector(P0,P).  (use right hand rule for positive angle)
  95. */
  96. extern TransformType4D Rotate4D();     
  97.  
  98. /*
  99. ** Perspective4D(f) double f;  
  100. */
  101. extern TransformType4D Perspective4D();
  102.  
  103. /*
  104. ** CreateVector4D(a,b,c) double a,b,c;
  105. ** Returns the vector represented in homogeneous coordinates as [a b c 0].
  106. */
  107. extern VectorType4D CreateVector4D(); 
  108.  
  109. /*
  110. ** PrintPoint4D(f,P) FILE *f; PointType4D P; 
  111. ** Print the value of the point to the file.
  112. */
  113. extern void PrintPoint4D();    
  114.  
  115. /*
  116. ** PrintVector4D(f,v) FILE *f; VectorType4D v; 
  117. ** Print the value of the vector to the file.
  118. */
  119. extern void PrintVector4D();    
  120.  
  121. /*
  122. ** PrintTransform4D(f,T) FILE *f; TransformType4D T; 
  123. ** Print the value of the transformation matrix to the file.
  124. */
  125. extern void PrintTransform4D(); 
  126.  
  127. /* 
  128. ** Cross4D(v1,v2) VectorType4D v1,v2;
  129. ** Return the cross product of the two vectors: v1 X v2
  130. */
  131. extern VectorType4D Cross4D();
  132.  
  133. /*
  134. ** Dot4D(v1,v2) VectorType4D v1,v2;
  135. ** Return the dot product of the two vectors: v1 . v2
  136. */
  137. extern double Dot4D();
  138.  
  139. /*
  140. ** Normalize(V) VectorType4D V;
  141. ** Return a vector with the same direction, but of length 1.
  142. */
  143. extern VectorType4D Normalize();
  144.  
  145.  
  146. /*
  147. ** PVadd(P,V) PointType4D P; VectorType4D V;
  148. ** Return the point P + V
  149. */
  150. extern PointType4D PVadd();
  151.  
  152. /*
  153. ** Ratio4D(P0,P1,t) PointType4D P0,P1; double t;
  154. ** Return the point specified by the parameter t on the line (P0,P1) in 
  155. ** parametric form.
  156. */
  157. extern PointType4D Ratio4D();
  158.  
  159. /*
  160. ** Pdiff(P1,P0)  PointType4D P1,P0;
  161. ** Return the vector P1-P0 
  162. */
  163. extern VectorType4D Pdiff();
  164.  
  165. /*
  166. ** Vscale(s,V) double s; VectorType4D V;
  167. ** Return the vector s*V
  168. */
  169. extern VectorType4D Vscale();
  170.  
  171. /*
  172. ** Vadd(V1,V2) VectorType4D V1,V2;
  173. ** Return the vector V1 + V2
  174. */
  175. extern VectorType4D Vadd();
  176.  
  177. /*
  178. ** Vmag(V) VectorType4D V;
  179. ** Return the magnitude of the vector
  180. */
  181. extern double Vmag();
  182.  
  183. /*
  184. ** Vneg(V), VectorType4D V;
  185. ** Returns the vector -V
  186. */
  187. extern VectorType4D Vneg();
  188.  
  189. /*
  190. ** Midpoint(P1,P2), PointType4D P1,P2;
  191. ** Returns the midpoint of the line segment (P1, P2)
  192. */
  193. extern PointType4D Midpoint();
  194.  
  195. /*
  196. ** NormalizePoint(P1) PointType4D *P1; 
  197. ** Normalize P1 to the equivalent homogeneous coordinate point for which W = 1.
  198. */
  199.  
  200. #define NormalizePoint(P1) \
  201. { \
  202.   register double *p = (P1)->P; \
  203.   register double  w = p[W]; \
  204. \
  205.   if (w != 1.0) {\
  206.           /* We are assuming that the order in P is:  X, Y, Z, W  */ \
  207.       *p++ /= w; *p++ /= w; *p++ /= w;\
  208.       *p = 1.0;\
  209.   }\
  210. }
  211.