From: Paolo Farinelli (paolo++at++sgi.com)
Date: 05/19/2003 15:25:45
Hi Rick,
I have just tried a simple test to check the behavior of pfuTravCalcBBox,
and it appears to be working fine (ie not like you observed).
My simple test consisted in modifying texture.C (from /usr/share/Performer/
pguide/libpf/C++) in the following way:
1. add #include <Performer/pfutil.h>
2. comment out the line: root->addChild(dcs2);
3. just after scene->getBound(&bsphere), add the following:
pfBox bbox;
pfuTravCalcBBox(scene, &bbox);
pfNotify( PFNFY_ALWAYS, PFNFY_PRINT,
"scene's bbox: min= %.3f %.3f %.3F max= %.3f %.3f %.3f\n",
bbox.min[0], bbox.min[1], bbox.min[2],
bbox.max[0], bbox.max[1], bbox.max[2] );
Basically, I am only adding one of the two textured polygons to the
scene, and then I am computing its bounding box. The output that gets
printed out is:
scene's bbox: min= -3.000 0.100 -0.500 max= -1.00 0.100 1.500
In this situation, clearly the returned bbox does not include (0,0,0).
You can also look at the code for pfuTravCalcBBox, which is in
/usr/share/Performer/src/lib/libpfutil/trav.c.
The relevant function is called cbPreBbox. Here, you will notice that
for each gset:
1.the bbox is obtained through pfGetGSetBBox,
2. gset's bbox is then transformed by the appropriate matrix
3. overall bbox is extended through pfBoxExtendByBox.
This seems to be the correct thing to do. Note that calling pfGetGSetBBox
should cause the recomputation of the gset's bounding box, if needed.
You may want to modify this function so that the actual vertex arrays
are traversed.. you could transform each vertex instead of transforming
the axis-aligned bounding boxes.. this would be slower but would generate
tighter bounding boxes around your transformed geometry.
In order to have access to the vertices of a pfGeoSet, you will need to
call:
void* alist;
ushort* ilist;
gset->getAttrLists(PFGS_COORD3, &alist, &ilist);
Notice that if ilist is not NULL, you are looking at an indexed gset, so
the i-th vertex position is stored in alist[ ilist[i] ], otherwise gset
is not
indexed, and ith vertex is stored in alist[i].
The number of vertices you will need to test depends on the primitive
type, and on the number of primitives stored in gset.. These can be obtained
through pfGeoSet::getPrimType and pfGeoSet::getNumPrims.
Note also that when dealing with triangle strips or fans, or with polygons,
the number of vertices associated with each primitive may be different.
The length of each primitive can be queried with pfGeoSet::getPrimLength;
The relationship between primitive length and the number of associated
vertices depends on the primitive type.
Please take a look at man pfGeoSet for more info. Let me know if you
need further assistance or if you figure out what is going wrong in your
current application.
Hope this helps.
Regards,
Paolo
Bard Jr., Richard D. wrote:
>I'm using pfdLoadFile to load several .obj and .pfb files, then I'm trying
>to position the channel's view so that the 1st object is visible. I have
>copied -n- pasted the code from trackball.c and it works fine - IF the
>geometry in the object is near (0,0,0). Unfortunately, the people who
>modelled these objects in the .obj and .pfb files placed the geometry out
>around .... well, it's way out there. pfuTravCalcBBox includes (0,0,0) in
>the bounding box - even if the geometry is a 1x1x1 cube which has vertices
>located at (1000, 1000, 1000), etc.
>
>I'm thinking of doing a "roll-your-own" bounding box function that traverses
>the list of vertices in the pfGeoSet and finds the (min, max) vertices - but
>how do you obtain the list of the vertices in the pfGeoSet?
>
>Any ideas?
>
>Thanks -
>
>Rick Bard
>KSC - Boeing
>
-- Paolo Farinelli paolo++at++sgi.com Member of Technical Staff, OpenGL Performer 1-650-933-1808 Silicon Graphics 1600 Amphitheatre Pkwy, Mountain View, CA 94043
This archive was generated by hypermail 2b29 : Mon May 19 2003 - 15:26:12 PDT