--- ray/src/ot/o_instance.c 1991/01/05 09:41:26 1.7 +++ ray/src/ot/o_instance.c 2004/03/27 12:41:45 2.5 @@ -1,21 +1,20 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: o_instance.c,v 2.5 2004/03/27 12:41:45 schorsch Exp $"; #endif - /* - * o_instance.c - routines for creating octrees for other octrees. - * - * 11/11/88 + * o_instance.c - routines for creating octrees for other octrees */ #include "standard.h" #include "object.h" +#include "octree.h" + #include "instance.h" +#include "mesh.h" + #include "plocate.h" /* @@ -41,23 +40,25 @@ static char SCCSid[] = "$SunId$ LBL"; */ -o_instance(o, cu) /* determine if cubes intersect */ -OBJREC *o; -CUBE *cu; +static int o_cube(CUBE *cu1, FULLXF *fxf, CUBE *cu); + + +static int +o_cube( /* determine if cubes intersect */ + CUBE *cu1, + FULLXF *fxf, + CUBE *cu +) { static int vstart[4] = {0, 3, 5, 6}; FVECT cumin, cumax; FVECT vert[8]; FVECT v1, v2; - register INSTANCE *in; int vloc, vout; register int i, j; - /* get octree arguments */ - in = getinstance(o, IO_BOUNDS); /* check if cube vertex in octree */ for (j = 0; j < 3; j++) - cumax[j] = (cumin[j] = in->obj->scube.cuorg[j]) + - in->obj->scube.cusize; + cumax[j] = (cumin[j] = cu1->cuorg[j]) + cu1->cusize; vloc = ABOVE | BELOW; vout = 0; for (i = 0; i < 8; i++) { @@ -66,8 +67,8 @@ CUBE *cu; if (i & 1<cusize; } - multp3(v2, v1, in->x.b.xfm); - if (j = plocate(v2, cumin, cumax)) + multp3(v2, v1, fxf->b.xfm); + if ( (j = plocate(v2, cumin, cumax)) ) vout++; vloc &= j; } @@ -83,12 +84,12 @@ CUBE *cu; vloc = ABOVE | BELOW; for (i = 0; i < 8; i++) { for (j = 0; j < 3; j++) { - v1[j] = in->obj->scube.cuorg[j]; + v1[j] = cu1->cuorg[j]; if (i & 1<obj->scube.cusize; + v1[j] += cu1->cusize; } - multp3(vert[i], v1, in->x.f.xfm); - if (j = plocate(vert[i], cumin, cumax)) + multp3(vert[i], v1, fxf->f.xfm); + if ( (j = plocate(vert[i], cumin, cumax)) ) vloc &= j; else return(O_HIT); /* vertex inside */ @@ -106,4 +107,34 @@ CUBE *cu; } return(O_MISS); /* no intersection */ +} + + +/* XXX o_instance() is extern, but not declared in any header file */ +int +o_instance( /* determine if instance intersects */ + OBJREC *o, + CUBE *cu +) +{ + INSTANCE *ins; + /* get octree bounds */ + ins = getinstance(o, IO_BOUNDS); + /* call o_cube to do the work */ + return(o_cube(&ins->obj->scube, &ins->x, cu)); +} + + +/* XXX o_mesh() is extern, but not declared in any header file */ +int +o_mesh( /* determine if mesh intersects */ + OBJREC *o, + CUBE *cu +) +{ + MESHINST *mip; + /* get mesh bounds */ + mip = getmeshinst(o, IO_BOUNDS); + /* call o_cube to do the work */ + return(o_cube(&mip->msh->mcube, &mip->x, cu)); }