home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / GRAPHICS / rayshade.lzh / funcdefs.h < prev    next >
Text File  |  1990-05-08  |  5KB  |  168 lines

  1. /*
  2.  * funcdefs.h
  3.  *
  4.  * Copyright (C) 1989, Craig E. Kolb
  5.  *
  6.  * This software may be freely copied, modified, and redistributed,
  7.  * provided that this copyright notice is preserved on all copies.
  8.  *
  9.  * There is no warranty or other guarantee of fitness for this software,
  10.  * it is provided solely .  Bug reports or fixes may be sent
  11.  * to the author, who may or may not act on them as he desires.
  12.  *
  13.  * You may not include this software in a program or other software product
  14.  * without supplying the source, or without informing the end-user that the
  15.  * source is available for no extra charge.
  16.  *
  17.  * If you modify this software, you should include a notice giving the
  18.  * name of the person performing the modification, the date of modification,
  19.  * and the reason for such modification.
  20.  *
  21.  * $Id: funcdefs.h,v 3.0 89/10/27 02:05:50 craig Exp $
  22.  *
  23.  * $Log:    funcdefs.h,v $
  24.  * Revision 3.0  89/10/27  02:05:50  craig
  25.  * Baseline for first official release.
  26.  * 
  27.  */
  28.  
  29. /*
  30.  * This file should eventually disappear; function declarations should
  31.  * appear as externs where needed.  Macros should be moved to a separate file.
  32.  */
  33. /*
  34.  * Normal routines
  35.  */
  36. int    nrmsph(), nrmbox(), nrmtri(), nrmsup(),nrmplane(), nrmcyl(),
  37.         nrmpoly(), nrmcone(), nrmhf();
  38. /*
  39.  * Intersection routines
  40.  */
  41. double     intsph(), intbox(), inttri(), intsup(),intplane(), crossp(), intcyl(),
  42.         intpoly(), intcone(), inthf();
  43. /*
  44.  * Extent-box finding routines
  45.  */
  46. int    sphextent(),boxextent(),triextent(),supextent(),planeextent(),
  47.         cylextent(), polyextent(), coneextent(), hfextent();
  48.  
  49. /*
  50.  * Object creation routines
  51.  */
  52. Object *maksph(), *makbox(), *maktri(), *maksup(), *makplane(), *makcyl(),
  53.       *makpoly(), *makcone(), *makhf(), *new_object();
  54. /*
  55.  * Intersection routines.
  56.  */
  57. double    int_grid(), int_list(), int_primitive(), IntBounds();
  58.  
  59. /*
  60.  * Misc.
  61.  */
  62. char *Malloc(), *Calloc(), *strsave();
  63. double    normalize(), Noise();
  64.  
  65. /*
  66.  * Transformations
  67.  */
  68. Trans *new_trans();
  69. TransInfo *new_transinfo();
  70.  
  71. /*
  72.  * Surfaces
  73.  */
  74. Surface    *find_surface(), *make_surface(), *get_surface();
  75. SurfaceList *add_surface();
  76. /*
  77.  * Objects
  78.  */
  79. Object *add_child_named(), *add_child(), *get_object_named();
  80.  
  81. extern double ftmp;  /* Yick -- keeps us from evaluating twice during fabs. */
  82.  
  83. /*
  84.  * Macros
  85.  */
  86.  
  87. /*
  88.  * Absolute value -- uses "ftmp" to store value of argument, which
  89.  * keeps us from evaluating expressions more than once.
  90.  */
  91. #define    fabs(x)            ((ftmp=(x)) < 0. ? -(ftmp) : (ftmp))
  92. #define abs(x)             ((x) < 0 ? -(x) : (x))
  93.  
  94. #ifdef SYSV
  95. double drand48();
  96. /*
  97.  * nrand() returns a uniformly distributed random variable between 0 and 1.
  98.  */
  99. #define nrand()            (drand48())
  100. #else
  101. long random();
  102. #define nrand()            ((double)random() / (double)((1 << 31) - 1))
  103. #endif
  104.  
  105. #ifdef MULTIMAX
  106. /*
  107.  * On the multimax, allocate large pieces of memory as shared memory.
  108.  */
  109. extern char *share_malloc(), *share_calloc();
  110. #define mallocprim()        (Primitive *)share_malloc(sizeof(Primitive))
  111. #else
  112. /*
  113.  * Otherwise, malloc is malloc, etc.
  114.  */
  115. #define share_malloc(x)        Malloc(x)
  116. #define share_calloc(x,y)    Calloc(x,y)
  117. #define mallocprim()        (Primitive *)Malloc(sizeof(Primitive))
  118. #endif
  119.  
  120. /*
  121.  * Return a uniformly distributed random variable between -s/2 and s/2.
  122.  */
  123. #define jitter(s)        ((nrand() * (s)) - (s)/2.)
  124. /*
  125.  * Dot product
  126.  */
  127. #define dotp(a, b)        (((a)->x*(b)->x)+((a)->y*(b)->y)+((a)->z*(b)->z))
  128. /*
  129.  * Close enough for us.
  130.  */
  131. #define equal(a, b)        (fabs((a) - (b)) < EPSILON)
  132. /*
  133.  * Maximum/Minimum functions
  134.  */
  135. #define max(a, b)        ((a) > (b) ? (a) : (b))
  136. #define min(a, b)        ((a) < (b) ? (a) : (b))
  137. /*
  138.  * Convert from voxel number along X/Y/Z to corresponding coordinate.
  139.  */
  140. #define voxel2x(g,x)        ((x) * g->voxsize[0]+ g->bounds[0][0])
  141. #define voxel2y(g,y)        ((y) * g->voxsize[1] + g->bounds[0][1])
  142. #define voxel2z(g,z)        ((z) * g->voxsize[2] + g->bounds[0][2])
  143. /*
  144.  * And vice-versa.
  145.  */
  146. #define x2voxel(g,x)        (((x) - g->bounds[0][0]) / g->voxsize[0])
  147. #define y2voxel(g,y)        (((y) - g->bounds[0][1]) / g->voxsize[1])
  148. #define z2voxel(g,z)        (((z) - g->bounds[0][2]) / g->voxsize[2])
  149. /*
  150.  * Is the point "p" outisde of the bounding box "b"?
  151.  */
  152. #define OutOfBounds(p,b) ((p)->x < b[0][0] || (p)->x > b[1][0] ||\
  153.               (p)->y < b[0][1] || (p)->y > b[1][1] ||\
  154.               (p)->z < b[0][2] || (p)->z > b[1][2])
  155.  
  156. #ifndef DUMB_CPP
  157.  
  158. #define vecsub(a,b,r)    (r)->x= (a).x-(b).x;(r)->y= (a).y-(b).y;(r)->z= (a).z-(b).z
  159. #define vecadd(a,b,r)    (r)->x= (a).x+(b).x;(r)->y= (a).y+(b).y;(r)->z= (a).z+(b).z
  160. #define scalar_prod(s,a,r)    (r)->x= s*(a).x;(r)->y= s*(a).y;(r)->z= s*(a).z
  161. #define veccomb(s1,v1,s2,v2,r)    (r)->x = s1*(v1).x + s2*(v2).x; \
  162.                  (r)->y = s1*(v1).y + s2*(v2).y; \
  163.                  (r)->z = s1*(v1).z + s2*(v2).z;
  164. #define addscaledvec(v1,s,v2,r)    (r)->x = (v1).x + s*(v2).x; \
  165.                  (r)->y = (v1).y + s*(v2).y; \
  166.                  (r)->z = (v1).z + s*(v2).z;
  167. #endif
  168.