16 #define TACHYON_INTERNAL 1 24 int box_bbox(
void * obj, vector * min, vector * max) {
35 (
void (*)(
const void *,
const void *,
const void *,
void *))(
box_normal),
43 b=(
box *) malloc(
sizeof(
box));
44 memset(b, 0,
sizeof(
box));
54 flt a, tx1, tx2, ty1, ty2, tz1, tz2;
61 if ((ry->o.x < bx->
min.x) || (ry->o.x > bx->
max.x))
return;
64 tx1 = (bx->
min.x - ry->o.x) / ry->d.x;
65 tx2 = (bx->
max.x - ry->o.x) / ry->d.x;
66 if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; }
67 if (tx1 > tnear) tnear=tx1;
68 if (tx2 < tfar) tfar=tx2;
70 if (tnear > tfar)
return;
71 if (tfar < 0.0)
return;
74 if ((ry->o.y < bx->
min.y) || (ry->o.y > bx->
max.y))
return;
77 ty1 = (bx->
min.y - ry->o.y) / ry->d.y;
78 ty2 = (bx->
max.y - ry->o.y) / ry->d.y;
79 if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; }
80 if (ty1 > tnear) tnear=ty1;
81 if (ty2 < tfar) tfar=ty2;
83 if (tnear > tfar)
return;
84 if (tfar < 0.0)
return;
87 if ((ry->o.z < bx->
min.z) || (ry->o.z > bx->
max.z))
return;
90 tz1 = (bx->
min.z - ry->o.z) / ry->d.z;
91 tz2 = (bx->
max.z - ry->o.z) / ry->d.z;
92 if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; }
93 if (tz1 > tnear) tnear=tz1;
94 if (tz2 < tfar) tfar=tz2;
96 if (tnear > tfar)
return;
97 if (tfar < 0.0)
return;
99 ry->add_intersection(tnear, (
const object *) bx, ry);
100 ry->add_intersection(tfar, (
object *) bx, ry);
103 void box_normal(
const box * bx,
const vector * pnt,
const ray * incident, vector * N) {
107 c.x=(bx->
max.x + bx->
min.x) / 2.0;
108 c.y=(bx->
max.y + bx->
min.y) / 2.0;
109 c.z=(bx->
max.z + bx->
min.z) / 2.0;
111 VSub((vector *) pnt, &c, N);
126 N->x=0.0; N->y=0.0; N->z=0.0;
130 if (t==a.x) N->x=b.x;
132 if (t==a.y) N->y=b.y;
134 if (t==a.z) N->z=b.z;
139 if (
VDot(N, &(incident->d)) > 0.0) {
static object_methods box_methods
RT_OBJECT_HEAD vector min
minimum vertex coordinate
box * newbox(void *tex, vector min, vector max)
void box_intersect(const box *bx, ray *ry)
void VSub(apivector *a, apivector *b, apivector *c)
flt VDot(apivector *a, apivector *b)
vector max
maximum vertex coordinate
double flt
generic floating point number, using double
Tachyon cross-platform timers, special math function wrappers, and RNGs.
int box_bbox(void *obj, vector *min, vector *max)
Tachyon public API function prototypes and declarations used to drive the ray tracing engine...
void box_normal(const box *bx, const vector *pnt, const ray *incident, vector *N)
axis-aligned box definition