--- ray/src/ot/o_instance.c 1989/10/13 20:08:08 1.2 +++ ray/src/ot/o_instance.c 2003/03/11 17:08:55 2.3 @@ -1,21 +1,20 @@ -/* Copyright (c) 1988 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: o_instance.c,v 2.3 2003/03/11 17:08:55 greg 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,21 @@ static char SCCSid[] = "$SunId$ LBL"; */ -o_instance(o, cu) /* determine if cubes intersect */ -OBJREC *o; +static int +o_cube(cu1, fxf, cu) /* 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, GET_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,35 +63,35 @@ CUBE *cu; if (i & 1<cusize; } - multp3(v2, v1, in->b.xfm); + multp3(v2, v1, fxf->b.xfm); if (j = plocate(v2, cumin, cumax)) vout++; vloc &= j; } if (vout == 0) /* all inside */ - return(2); + return(O_IN); if (vout < 8) /* some inside */ - return(1); + return(O_HIT); if (vloc) /* all to one side */ - return(0); + return(O_MISS); /* octree vertices in cube? */ for (j = 0; j < 3; j++) cumax[j] = (cumin[j] = cu->cuorg[j]) + cu->cusize; 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->f.xfm); + multp3(vert[i], v1, fxf->f.xfm); if (j = plocate(vert[i], cumin, cumax)) vloc &= j; else - return(1); /* vertex inside */ + return(O_HIT); /* vertex inside */ } if (vloc) /* all to one side */ - return(0); + return(O_MISS); /* check edges */ for (i = 0; i < 4; i++) for (j = 0; j < 3; j++) { @@ -102,8 +99,34 @@ CUBE *cu; VCOPY(v1, vert[vstart[i]]); VCOPY(v2, vert[vstart[i] ^ 1<obj->scube, &ins->x, cu)); +} + + +int +o_mesh(o, cu) /* 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)); }