home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume5 / tracer / find.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-03  |  1.9 KB  |  98 lines

  1. #include <math.h>
  2. #include "rtd.h"
  3. #include "extern.h"
  4. #include "macros.h"
  5.  
  6.  
  7. double  findo (m, s) /* finds where a ray inside the ball exits. */
  8. struct mat *m;
  9. struct sphere  *s;
  10. {
  11. /* foops id the rotated position vector. */
  12.     struct vector   foops;
  13.     double  t;
  14.     MTV (foops, (*m), s -> cent);
  15. /* see if it hits the ball (it better)*/
  16.     t = s -> rad * s -> rad - foops.y * foops.y - foops.z * foops.z;
  17.     if (t > 0)
  18.     t = foops.x + sqrt (t);
  19.     else
  20.     t = 0;
  21. /* return how far along the ray you were when you hit */
  22.     return (t);
  23. }
  24.  
  25. double  find (m, s)/* finds whether a ray hits a ball*/
  26. struct mat *m;
  27. struct sphere  *s;
  28. {
  29.     struct vector   foops;
  30.     double  t;
  31.     MTV (foops, (*m), s -> cent);
  32.     t = s -> rad * s -> rad - foops.y * foops.y - foops.z * foops.z;
  33.     if (t > 0)
  34.     t = foops.x - sqrt (t);
  35.     else
  36.     t = 0;
  37.     return (t);
  38. }
  39.  
  40. double  finds (m, s)/* finds if a ball is between a point and a 
  41.             lightsource. Returns how obscuring the ball is */
  42. struct mat *m;
  43. struct sphere  *s;
  44. {
  45.     struct vector   foops;
  46.     double  t;
  47.     MTV (foops, (*m), s -> cent);
  48.     t = s -> rad - sqrt (foops.y * foops.y + foops.z * foops.z);
  49.     if (t > 0)
  50.     t = t / foops.x;
  51.     else
  52.     t = 0;
  53.     return (t);
  54. }
  55.  
  56.  
  57.  
  58.  
  59. double  shadow (p)/* finds if a point is in a shadow, or if it is on edge */
  60. struct vector  *p;
  61. {
  62.     struct mat  trans;
  63.     struct sphere   ss;
  64.     struct vector   d;
  65.     int     c,
  66.             i;
  67.     double  l,
  68.             k,
  69.             x,
  70.             y,
  71.             z,
  72.             finds ();
  73.     l = 0.0;
  74.     c = -1;
  75.     SV (d, ls.cent, (*p));
  76.     d.l = LEN (d);
  77.     d.xzl = XZL (d);
  78.     mt (&(d), &trans);
  79.  
  80.     for (i = 0; i < nob; i++) {
  81.     ss.rad = bl[i] -> s.rad;
  82.     SV (ss.cent, bl[i] -> s.cent, (*p));
  83.     if ((k = finds (&trans, &ss)) > l) {
  84.         c = i;
  85.         l = k;
  86.     }
  87.     }
  88.     if (c == -1)
  89.     k = 200.0;
  90.     else {
  91.     k = 1.0 - l / ((ls.rad) / (d.l));
  92.     if (k < 0.0)
  93.         k = 0.0;
  94.     k *= 200.0;
  95.     }
  96.     return (k);
  97. }
  98.