home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / povsrc.sit / SOURCE / VECTOR.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-03  |  2.7 KB  |  69 lines

  1. /****************************************************************************
  2. *                vector.h
  3. *
  4. *  This module contains macros to perform operations on vectors.
  5. *
  6. *  from Persistence of Vision Raytracer 
  7. *  Copyright 1992 Persistence of Vision Team
  8. *---------------------------------------------------------------------------
  9. *  Copying, distribution and legal info is in the file povlegal.doc which
  10. *  should be distributed with this file. If povlegal.doc is not available
  11. *  or for more info please contact:
  12. *
  13. *       Drew Wells [POV-Team Leader] 
  14. *       CIS: 73767,1244  Internet: 73767.1244@compuserve.com
  15. *       Phone: (213) 254-4041
  16. * This program is based on the popular DKB raytracer version 2.12.
  17. * DKBTrace was originally written by David K. Buck.
  18. * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  19. *
  20. *****************************************************************************/
  21.  
  22.  
  23. /* Misc. Vector Math Macro Definitions */
  24.  
  25. extern DBL VTemp;
  26.  
  27. /* Vector Add */
  28. #define VAdd(a, b, c) {(a).x=(b).x+(c).x;(a).y=(b).y+(c).y;(a).z=(b).z+(c).z;}
  29.  
  30. /* Vector Subtract */
  31. #define VSub(a, b, c) {(a).x=(b).x-(c).x;(a).y=(b).y-(c).y;(a).z=(b).z-(c).z;}
  32.  
  33. /* Scale - Multiply Vector by a Scalar */
  34. #define VScale(a, b, k) {(a).x=(b).x*(k);(a).y=(b).y*(k);(a).z=(b).z*(k);}
  35.  
  36. /* Inverse Scale - Divide Vector by a Scalar */
  37. #define VInverseScale(a, b, k) {(a).x=(b).x/(k);(a).y=(b).y/(k);(a).z=(b).z/(k);}
  38.  
  39. /* Dot Product - Gives Scalar angle (a) between two vectors (b) and (c) */
  40. #define VDot(a, b, c) {a=(b).x*(c).x+(b).y*(c).y+(b).z*(c).z;}
  41.  
  42. /* Cross Product - returns Vector (a) = (b) x (c) 
  43.    WARNING:  a must be different from b and c.*/
  44. #define VCross(a,b,c) {(a).x=(b).y*(c).z-(b).z*(c).y; \
  45. (a).y=(b).z*(c).x-(b).x*(c).z; \
  46.                        (a).z=(b).x*(c).y-(b).y*(c).x;}
  47.  
  48. /* Evaluate - returns Vector (a) = Multiply Vector (b) by Vector (c) */
  49. #define VEvaluate(a, b, c) {(a).x=(b).x*(c).x;(a).y=(b).y*(c).y;(a).z=(b).z*(c).z;}
  50.  
  51. /* Square a Vector */
  52. #define    VSqr(a) {(a).x*(a).x;(a).y*(a).y;(a).z*(a).z;}
  53.  
  54. /* Simple Scalar Square Macro */
  55. #define    Sqr(a)    ((a)*(a))
  56.  
  57. /* Square a Vector (b) and Assign to another Vector (a) */
  58. #define VSquareTerms(a, b) {(a).x=(b).x*(b).x;(a).y=(b).y*(b).y;(a).z=(b).z*(b).z;}
  59.  
  60. /* Vector Length - returs Scalar Euclidean Length (a) of Vector (b) */
  61. #define VLength(a, b) {a=sqrt((b).x*(b).x+(b).y*(b).y+(b).z*(b).z);}
  62.  
  63. /* Normalize a Vector - returns a vector (length of 1) that points at (b) */
  64. #define VNormalize(a,b) {VTemp=sqrt((b).x*(b).x+(b).y*(b).y+(b).z*(b).z);(a).x=(b).x/VTemp;(a).y=(b).y/VTemp;(a).z=(b).z/VTemp;}
  65.  
  66. /* Compute a Vector (a) Halfway Between Two Given Vectors (b) and (c) */
  67. #define VHalf(a, b, c) {(a).x=0.5*((b).x+(c).x);(a).y=0.5*((b).y+(c).y);(a).z=0.5*((b).z+(c).z);}
  68.