[osg-users] KdTree support now checked in
jean-sebastien.guay at cm-labs.com
Sun Jul 13 12:11:53 PDT 2008
> So my first question is about how I should try to cache the intersect
> visitors? Should I keep one around for each large ship (node passed in
> to the getIntersections() function), or should I just make a single one
> that is used over and over?
There's really no way I can answer this. You will have to try a few
different possibilities, use a profiler and see if the bottleneck changes.
I have no idea what you do with your intersection tests. Do you need to
do one test per frame per ship? Ten? As many as possible? In my case, my
app needed to do shadow tests from the surface of every object, so I
really needed to do as many intersections per second as possible. I
profiled my app, and saw that creating a new Intersector and
IntersectionVisitor each time was taking up significant time. So I used
static instances that were reused, and that made the whole process faster.
If all you want to do is check intersections a few times per frame, you
may not need to do that, because in your case the creation of the
objects won't be significant. You have to profile and see.
> Next, how often should I call reset()? Once for each big ship, or once
> for each intersection check? I do not see any setStart()/setEnd()
> functions. Please forgive my ognorance, but where are they and what do
> they do?
If you re-use an Intersector or an InversectionVisitor, you need to call
reset() on both before you do a new intersection test. This clears the
results of the previous test.
osgUtil::LineSegmentIntersector::setStart() and setEnd() just change the
start and end points of the line segment being used for the intersection
test, without having to create a new LineSegmentIntersector. I submitted
the change to add those methods around OSG 2.1.x time-frame, so if
you're using 2.0 you won't have them, but if you're using 2.2+ you will.
> Finally, I am doing a few checks before I try the line segments to see
> if they are even close to the node I am checking. Is this worth the
> check or does the intersectVisitor do that all for me anyway?
The IntersectionVisitor checks with the graph nodes' bounding volumes
before going into the geometry itself, so you can probably just let it
do its work. Generally, traversing the graph and checking bounding
volumes is pretty fast (except if you have a very large number of nodes
or if your graph is poorly built), it's doing the actual tests against
geometry (line segment to triangle intersection test) that's slow
(except with the new kd-tree... :-) ).
Hope this helps,
Jean-Sebastien Guay jean-sebastien.guay at cm-labs.com
More information about the osg-users