home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / source / rayce27s / vector.h < prev   
Encoding:
C/C++ Source or Header  |  1994-02-02  |  1.3 KB  |  38 lines

  1. /*
  2.  * inline vector operations, definitions:
  3.  */
  4.  
  5.  
  6. #ifndef _VECTOR
  7. #define _VECTOR
  8.  
  9. #define setvector(a,xx,yy,zz) ((a).x = xx, (a).y = yy, (a).z = zz)
  10.  
  11. #define vdot(a,b)     (((a).x * (b).x) + ((a).y * (b).y) + ((a).z*(b).z) )
  12. #define veclen(a)    (sqrt(vdot((a),(a))))
  13. #define quickveclen(a)    (ABS((a).x) + ABS((a).y) + ABS((a).z))
  14.  
  15. #define svproduct(t, s, v)     ((t).x = (s)*(v).x, (t).y= (v).y* (s), (t).z = (s)*(v).z)
  16. #define vadd(t, a, b)         ((t).x = (a).x + (b).x, (t).y  =(a).y + (b).y, (t).z = (a).z + (b).z)
  17. #define vcproduct(t, a, b)     ((t).x = (a).x*(b).x, (t).y = (a).y*(b).y, (t).z = (a).z*(b).z)
  18. #define vneg(t,a)         ((t).x = -(a).x, (t).y = -(a).y, (t).z = -(a).z)
  19. #define vsub(t, a, b)         ((t).x = (a).x-(b).x, (t).y = (a).y-(b).y, (t).z = (a).z-(b).z)
  20.  
  21. #ifdef DEBUG
  22. #define norm(t,a)         (tmpdouble = veclen((a)),  \
  23.    (tmpdouble < EPSILON && (debug_options & DEBUGRUNTIME)) ? warning ("NNV %d %s ", __LINE__, __FILE__), setvector(t, 0,0,0) : \
  24.    svproduct(t, 1/tmpdouble, (a)))
  25. #else
  26. #define norm(t,a)         (tmpdouble = veclen((a)),  \
  27.     svproduct(t, 1/tmpdouble, (a)))
  28. #endif
  29.  
  30.  
  31. #define vabs(a,b)        ((a).x = ABS((b).x), (a).y = ABS((b).y), (a).z = ABS((b).z))
  32.  
  33. /* warning: don't use vcross(a,a,b) */
  34. #define vcross(t, a, b)     ((t).x = (a).y*(b).z-(a).z*(b).y, \
  35.     (t).y = (a).z*(b).x - (a).x*(b).z, (t).z = (a).x*(b).y-(a).y*(b).x)
  36.  
  37. #endif
  38.