UPDATE:
I did not end implementing my own BoundCallback since I found another problem
in my code.
The parent node of the 'x' nodes are boundaries of different types, for example:
[root]
|
[boundary made of lines]
|
[3d boundary as a box]
/ | \
[x] [x] [x]
These boundaries are used to present the user with the boundaries of the area
occupied by the 'x' objects.
Originally, I disabled the boundaries (just had them as transforms with no
drawables) to isolate my 'x' problem (as described above).
But then when I went and added back the boundaries (with my fix of making sure
_firstTimeToInitEyePoint was false) I found that the boundary boxes now were
culled out of the scene!
So I continued debugging the calculation of bounding spheres and I found
another problem - this time in our code.
To implement the dimensions of the boundary boxes we added a new NodeCallback
on the boundary nodes. Each time an 'x' is added to the scene, we visited the
graph upwards and marked the boundaries as dirty.
Then in the next frame, the callback would calculate the dimensions of the
boundary by running an osg::ComputeBoundsVisitor on the sub-graph, and using
the bounding box returned by the visitor to set the scale matrix of the
boundary node.
When I was debugging I noticed we were scaling the boundary nodes to negative
numbers, which made the radius an infinite value, and screwed up the bounding
sphere calculation.
The problem is in the code of our boundary node callback:
Code:
// get the bounding box of all children contained in this boundingNode
osg::ComputeBoundsVisitor visitor;
boundingNode->accept(visitor);
osg::BoundingBox bb = visitor.getBoundingBox();
// scale and translate the boundingNode accordingly
osg::Matrixd translationTx = osg::Matrixd::translate(bb.center().x(),
bb.center().y(), ourCenterZ);
osg::Matrixd scaleTx = osg::Matrixd::scale( (bb.xMax() - bb.xMin()) *
scaleVector.x(), (bb.yMax() - bb.yMin()) * scaleVector.y(), ourZ);
In the last line of that code, it turned out the max value returned from the
bounding box was to the left of the min value.
This made us scale in a negative number. (one would assume the min of a
bounding box is always to the left of the max ...)
So I went and added fabs to the subtraction:
Code:
osg::Matrixd scaleTx = osg::Matrixd::scale( fabs(bb.xMax() - bb.xMin()) *
scaleVector.x(), fabs(bb.yMax() - bb.yMin()) * scaleVector.y(), ourZ);
and everything showed correctly - our bounding nodes and the 'x' objects.
The only problem left is when the camera is over our boundary objects, I get
these debug messages in the console:
> CullVisitor::apply(Geode&) detected NaN,
> depth=1.#QNAN, center=(0 0 0),
> matrix={
> -1.#IND -1.#IND -1.#IND -1.#IND
> -1.#IND -1.#IND -1.#IND -1.#IND
> 0 0 5 0
> 200 0 -2002.5 1
> }
which I am going to look into next.
Cheers!
Ron
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=48957#48957
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org