[ODE] visibility detemination?
Kevin Reid
ode at q12.org
Mon Feb 17 07:31:01 2003
> Anyone using ODE for their culling code in addition to their physics code?
Here's my code.
Given variables rx, ry, near, and far, which define the view frustum (rx
and ry being half the width and height), and fOrigin and fRot, which are
the viewpoint's position and rotation matrix (as from dGeomGetRotation
etc.), this sets up a box geom to enclose the view frustum:
{
const dReal left = -rx, right = rx, bottom = -ry, top = ry;
const dReal pdiv = far / near;
const dVector3 bbox = {
(right - left) * pdiv,
(top - bottom) * pdiv,
far - near
};
const dVector3 bboxCenterOffset = {
(right + left) / 2,
(top + bottom) / 2,
-bbox[2] / 2 + near
};
dVector3 bboxCenterInWorld;
int i;
dMultiply2(bboxCenterInWorld, bboxCenterOffset, fRot, 1, 3, 3);
for (i = 0; i < 3; i++)
bboxCenterInWorld[i] = fOrigin[i] + bboxCenterInWorld[i];
dGeomSetPosition(viewVolumeTester, bboxCenterInWorld[0],
bboxCenterInWorld[1], bboxCenterInWorld[2]);
dGeomBoxSetLengths(viewVolumeTester, bbox[0], bbox[1], bbox[2]);
dGeomSetRotation(viewVolumeTester, fRot);
}
To render objects inside this volume, I use:
dSpaceCollide2(viewVolumeTester, odeSpace, viewVolumeTester,
myRenderSolidIntersectCallback);
static void myRenderSolidIntersectCallback(void *tester, dGeomID g1,
dGeomID g2) {
if (g2 == tester) {
dGeomID temp = g1;
g1 = g2;
g2 = temp;
}
/* render g2 */
}
Note that the code does not use dCollide, so it may draw objects whose
AABBs intersect the view bounding box's but do not actually need to be
drawn. Depending on the cost of exact checking vs. unnecessary drawing
it may be better to use dCollide.
It would be nice if:
- ODE had a frustum geom class.
- hash spaces supported dSpaceCollide2, even inefficiently.
--
Kevin Reid