home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / libray / libcommon / vector.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  2.7 KB  |  103 lines

  1. /*
  2.  * vector.h
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * vector.h,v 4.1 1994/08/09 07:55:30 explorer Exp
  17.  *
  18.  * vector.h,v
  19.  * Revision 4.1  1994/08/09  07:55:30  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:02  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0.1.1  91/11/26  21:34:41  cek
  26.  * patch3: Moved EPSILON definition.
  27.  * 
  28.  * Revision 4.0  91/07/17  14:33:11  kolb
  29.  * Initial version.
  30.  * 
  31.  * Added VecNorm macro  93/01/21   [PhB]
  32.  * 
  33.  */
  34. #ifndef VECTOR_H
  35. #define VECTOR_H
  36. #include <math.h>
  37. /*
  38.  * Constants used in projecting onto planes
  39.  */
  40. #define XNORMAL        (char)0
  41. #define YNORMAL        (char)1
  42. #define ZNORMAL        (char)2
  43.  
  44. /*
  45.  * Maximum length
  46.  */
  47. #define FAR_AWAY        1.0E+14
  48.  
  49. typedef struct {
  50.     Float u, v;            /* 2D point */
  51. } Vec2d;
  52.  
  53. typedef struct Vector {
  54.     Float x, y, z;            /* 3D point */
  55. } Vector;
  56.  
  57. /*
  58.  * Linked list of points
  59.  */
  60. typedef struct PointList {
  61.     Vector    vec;            /* Vector data */
  62.     struct    PointList *next;    /* Next in list */
  63. } PointList;
  64.  
  65. /*
  66.  * Project a point in 3-space to the plane whose normal is indicated by "i."
  67.  */
  68. #define VecProject(r, p, i)    {switch(i) { \
  69.                 case XNORMAL: \
  70.                     r.u = (p).y; \
  71.                     r.v = (p).z; \
  72.                     break; \
  73.                 case YNORMAL: \
  74.                     r.u = (p).x; \
  75.                     r.v = (p).z; \
  76.                     break; \
  77.                 case ZNORMAL: \
  78.                     r.u = (p).x; \
  79.                     r.v = (p).y; \
  80.                     break; \
  81.                   } }
  82.  
  83. #define dotp(a, b)    (((a)->x*(b)->x)+((a)->y*(b)->y)+((a)->z*(b)->z))
  84. #define VecSub(a,b,r) (r)->x=(a).x-(b).x,(r)->y=(a).y-(b).y,(r)->z=(a).z-(b).z
  85. #define VecAdd(a,b,r) (r)->x=(a).x+(b).x,(r)->y=(a).y+(b).y,(r)->z=(a).z+(b).z
  86. #define VecScale(s,a,r)  (r)->x=(s)*(a).x,(r)->y=(s)*(a).y,(r)->z=(s)*(a).z
  87. #define VecComb(s1,v1,s2,v2,r)    (r)->x = (s1)*(v1).x + (s2)*(v2).x, \
  88.                  (r)->y = (s1)*(v1).y + (s2)*(v2).y, \
  89.                  (r)->z = (s1)*(v1).z + (s2)*(v2).z
  90. #define VecAddScaled(v1,s,v2,r)    (r)->x = (v1).x + (s)*(v2).x, \
  91.                  (r)->y = (v1).y + (s)*(v2).y, \
  92.                  (r)->z = (v1).z + (s)*(v2).z
  93. #define VecNorm(a)              (sqrt(  (a).x*(a).x + \
  94.                                         (a).y*(a).y +  \
  95.                                         (a).z*(a).z   ))
  96.  
  97. extern void    VecCross(), VecCoordSys(), MakeBump();
  98. extern Float    VecNormCross(), VecNormalize();
  99. extern Float    VecDist();
  100. extern int    Refract();
  101.  
  102. #endif /* VECTOR_H */
  103.