AtomicGetBBox() to utils.c (and extern it in utils.h) to compute the coordinates of a bounding box given an atomic:
void AtomicGetBBox(RpAtomic *atom, RwBBox *box) { RpGeometry *geom = RpAtomicGetGeometry(atom); RwInt32 nVerts = RpGeometryGetNumVertices(geom); RpMorphTarget *morph = RpGeometryGetMorphTarget(geom, 0); RwV3d *verts = RpMorphTargetGetVertices(morph); RwUInt16 i; box->inf = *verts; box->sup = *verts; for (verts++, i = 1; i < nVerts; i++, verts++) { if (verts->x < box->inf.x) box->inf.x = verts->x; if (verts->y < box->inf.y) box->inf.y = verts->y; if (verts->z < box->inf.z) box->inf.z = verts->z; if (verts->x > box->sup.x) box->sup.x = verts->x; if (verts->y > box->sup.y) box->sup.y = verts->y; if (verts->z > box->sup.z) box->sup.z = verts->z; }
RwV3dScale(&box->sup, &box->sup, 1.09f); RwV3dScale(&box->inf, &box->inf, 1.09f); }
main.c add a new variable static RwBBox PickBox. If an atomic is returned from the pick test in the Idle() function, call AtomicGetBBox to compute and store the dimensions of the bounding box around the atomic. Compile the code.
Next we need to add code that will draw the bounding box when there is an atomic selected. To do this we will create a new function in main.c called HighlightRender(). This will be called from the Render() function in main.c to display the bounding box.
main.c. This code makes use of immediate mode to render a wireframe bounding box around the selected atomic. The lines are drawn in red.
static void HighlightRender(void) { RwMatrix *ltm = RwFrameGetLTM(RpAtomicGetFrame(PickedAtomic)); RwIm3DVertex vertices[8]; RwInt32 i; static RwImVertexIndex indices[24] = { 0, 1, 1, 3, 3, 2, 2, 0, 4, 5, 5, 7, 7, 6, 6, 4, 0, 4, 1, 5, 2, 6, 3, 7 }; for (i = 0; i < 8; i++)
{
RwIm3DVertexSetPos(vertices+i,
i&1 ? PickBox.sup.x : PickBox.inf.x,
i&2 ? PickBox.sup.y : PickBox.inf.y,
i&4 ? PickBox.sup.z : PickBox.inf.z);
RwIm3DVertexSetRGBA(vertices+i, 255, 0, 0, 255);
}
/* all vertices have opaque colors so we can use the rwIM3D_ALLOPAQUE * hint for RwIm3DTransform */ if (RwIm3DTransform(vertices, 8, ltm, rwIM3D_ALLOPAQUE)) { RwIm3DRenderIndexedPrimitive(rwPRIMTYPELINELIST, indices, 24); RwIm3DEnd(); }
}
/*************************************************************************/
static void
Render(void)
HighlightRender() function in main.c, in the function Render(). This code should only be called if there is a picked atomic:
if( MenuGetStatus() != HELPMODE ) { /* * Scene rendering here... */ RpWorldRender(World); DisplayOnScreenInfo(Camera); if (PickedAtomic) { HighlightRender(); } } MenuRender(Camera, NULL);

© 1993-2004 Criterion Software Limited. All rights reserved. Built Thu Feb 12 13:46:58 2004.
Send Feedback