home *** CD-ROM | disk | FTP | other *** search
/ Chestnut's Multimedia Mania / MM_MANIA.ISO / graphics / povsrc20 / vector.h < prev    next >
C/C++ Source or Header  |  1993-07-08  |  4KB  |  79 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 1993 Persistence of Vision Team
  8. *---------------------------------------------------------------------------
  9. *  NOTICE: This source code file is provided so that users may experiment
  10. *  with enhancements to POV-Ray and to port the software to platforms other 
  11. *  than those supported by the POV-Ray Team.  There are strict rules under
  12. *  which you are permitted to use this file.  The rules are in the file
  13. *  named POVLEGAL.DOC which should be distributed with this file. If 
  14. *  POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  15. *  Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  16. *  Forum.  The latest version of POV-Ray may be found there as well.
  17. *
  18. * This program is based on the popular DKB raytracer version 2.12.
  19. * DKBTrace was originally written by David K. Buck.
  20. * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  21. *
  22. *****************************************************************************/
  23.  
  24. /* Misc. Vector Math Macro Definitions */
  25.  
  26. extern DBL VTemp;
  27.  
  28. /* Vector Add */
  29. #define VAdd(a, b, c) {(a).x=(b).x+(c).x;(a).y=(b).y+(c).y;(a).z=(b).z+(c).z;}
  30. #define VAddEq(a, b) {(a).x+=(b).x;(a).y+=(b).y;(a).z+=(b).z;}
  31.  
  32. /* Vector Subtract */
  33. #define VSub(a, b, c) {(a).x=(b).x-(c).x;(a).y=(b).y-(c).y;(a).z=(b).z-(c).z;}
  34. #define VSubEq(a, b) {(a).x-=(b).x;(a).y-=(b).y;(a).z-=(b).z;}
  35.  
  36. /* Scale - Multiply Vector by a Scalar */
  37. #define VScale(a, b, k) {(a).x=(b).x*(k);(a).y=(b).y*(k);(a).z=(b).z*(k);}
  38. #define VScaleEq(a, k) {(a).x*=(k);(a).y*=(k);(a).z*=(k);}
  39.  
  40. /* Inverse Scale - Divide Vector by a Scalar */
  41. #define VInverseScale(a, b, k) {(a).x=(b).x/(k);(a).y=(b).y/(k);(a).z=(b).z/(k);}
  42. #define VInverseScaleEq(a, k) {(a).x/=(k);(a).y/=(k);(a).z/=(k);}
  43.  
  44. /* Dot Product - Gives Scalar angle (a) between two vectors (b) and (c) */
  45. #define VDot(a, b, c) {a=(b).x*(c).x+(b).y*(c).y+(b).z*(c).z;}
  46.  
  47. /* Cross Product - returns Vector (a) = (b) x (c) 
  48.    WARNING:  a must be different from b and c.*/
  49. #define VCross(a,b,c) {(a).x=(b).y*(c).z-(b).z*(c).y; \
  50.                        (a).y=(b).z*(c).x-(b).x*(c).z; \
  51.                        (a).z=(b).x*(c).y-(b).y*(c).x;}
  52.  
  53. /* Evaluate - returns Vector (a) = Multiply Vector (b) by Vector (c) */
  54. #define VEvaluate(a, b, c) {(a).x=(b).x*(c).x;(a).y=(b).y*(c).y;(a).z=(b).z*(c).z;}
  55. #define VEvaluateEq(a, b) {(a).x*=(b).x;(a).y*=(b).y;(a).z*=(b).z;}
  56.  
  57. /* Divide - returns Vector (a) = Divide Vector (b) by Vector (c) */
  58. #define VDiv(a, b, c) {(a).x=(b).x/(c).x;(a).y=(b).y/(c).y;(a).z=(b).z/(c).z;}
  59. #define VDivEq(a, b) {(a).x/=(b).x;(a).y/=(b).y;(a).z/=(b).z;}
  60.  
  61. /* Square a Vector */
  62. #define    VSqr(a) {(a).x*(a).x;(a).y*(a).y;(a).z*(a).z;}
  63.  
  64. /* Simple Scalar Square Macro */
  65. #define    Sqr(a)    ((a)*(a))
  66.  
  67. /* Square a Vector (b) and Assign to another Vector (a) */
  68. #define VSquareTerms(a, b) {(a).x=(b).x*(b).x;(a).y=(b).y*(b).y;(a).z=(b).z*(b).z;}
  69.  
  70. /* Vector Length - returs Scalar Euclidean Length (a) of Vector (b) */
  71. #define VLength(a, b) {a=sqrt((b).x*(b).x+(b).y*(b).y+(b).z*(b).z);}
  72.  
  73. /* Normalize a Vector - returns a vector (length of 1) that points at (b) */
  74. #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;}
  75.  
  76. /* Compute a Vector (a) Halfway Between Two Given Vectors (b) and (c) */
  77. #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);}
  78.  
  79.