home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
015.lha
/
tracer_source
/
find.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-11-10
|
2KB
|
164 lines
#include <math.h>
#include "MyMath.h"
#include "rtd.h"
#include "extern.h"
#include "macros.h"
/* finds where a ray inside the ball exits. */
FFP findo (m, s)
struct mat *m;
register struct sphere *s;
{
/* foops id the rotated position vector. */
struct vector foops;
register FFP t;
MTV (foops, (*m), s -> cent);
/* see if it hits the ball (it better) */
t = SPSub(
SPMul(
foops.z,
foops.z
),
SPSub(
SPMul(
foops.y,
foops.y
),
SPMul(
s -> rad,
s -> rad
)
)
);
if( SPTst(t) > 0 )
t = SPAdd(foops.x, SPSqrt(t));
else
t = SPFlt(0);
/* return how far along the ray you were when you hit */
return (t);
}
/* finds whether a ray hits a ball*/
FFP find(m, s)
struct mat *m;
register struct sphere *s;
{
struct vector foops;
register FFP t;
MTV (foops, (*m), s -> cent);
t = SPSub(
SPMul(
foops.z,
foops.z
),
SPSub(
SPMul(
foops.y,
foops.y
),
SPMul(
s -> rad,
s -> rad
)
)
);
if( SPTst(t) > 0 )
t = SPSub(SPSqrt(t), foops.x);
else
t = SPFlt(0);
return (t);
}
/*
finds if a ball is between a point and a
lightsource. Returns how obscuring the ball is.
*/
FFP finds (m, s)
struct mat *m;
register struct sphere *s;
{
struct vector foops;
register FFP t;
MTV (foops, (*m), s -> cent);
t = SPSub(
SPSqrt (
SPAdd(
SPMul(foops.y, foops.y),
SPMul(foops.z, foops.z)
)
),
s -> rad
);
if (SPTst(t) > 0)
t = SPDiv(foops.x, t);
else
t = SPFlt(0);
return (t);
}
FFP shadow (p)/* finds if a point is in a shadow, or if it is on edge */
register struct vector *p;
{
struct mat trans;
struct sphere ss;
struct vector d;
int c,
i;
register FFP l,
k;
FFP finds ();
l = SPFlt(0);
c = -1;
SV (d, ls.cent, (*p));
d.l = LEN (d);
d.xzl = XZL (d);
mt (&(d), &trans);
for (i = 0; i < nob; i++) {
ss.rad = bl[i] -> s.rad;
SV (ss.cent, bl[i] -> s.cent, (*p));
if ( SPCmp( (k = finds (&trans, &ss)), l ) > 0 ) { /* ### */
c = i;
l = k;
}
}
if (c == -1)
k = SPFlt(200);
else {
k = SPSub(
SPDiv(
SPDiv(
(d.l),
(ls.rad)
),
l
),
SPFlt(1)
);
/*
k = 1.0 - l / ((ls.rad) / (d.l));
*/
if ( SPTst(k) < 0)
k = SPFlt(0);
k = SPMul(k, SPFlt(200));
}
return (k);
}