Hello Pablo,
Pablo Carneiro Elias wrote:
On Wed, Nov 18, 2009 at 11:01 PM, Carsten Neumann
<[email protected] <mailto:[email protected]>> wrote:
have you checked whether it actually gets to execute your
IntersectAction callback in both cases (can you isolate the problem to
be in the ia->getLine().intersect() call) or does it perhaps not even
get there (because tests against the bounding volumes fail higher up the
tree)?
I've checked and actually all callbacks gets executed and also all
getLine().intersect() calls get executed and return true. So, in all
cases, when a pick is performed over my custom geometry,
many triangles get hit (intersect() returns true), and the setHit() call
is performed. The setHit() checks whether the t parameter (which is
calculated by the intersect() method and represent the ray scale at
which the intersection occurred) is greater then zero, to grant that the
intersection occurred in front of the camera. The problem is that this
't' parameter is being calculated as < 0 by the intersect() method, even
with the geometry being visible.
hm, so the question has boiled down to: why is the distance negative?
I've just tried this with some models on linux and windows (r2175) and I
could not notice any irregularities. Also looking at the history of
files that seemed relevant (OSGIntersectAction, OSGLine, OSGMatrix,
OSGTransform) did not show anything that looked like it could be related.
So, even after many setHit() calls, the
didHit() returns false because no hit was actually set. This problem
happens now after we have upgraded to the latest osg version. I've
downgraded to the old version and the problem stopped happening.
Do you only see this with your own geometry type or does it also happen
with regular geometry? I've so far not been able to reproduce the
problem with regular geometry, which unfortunately makes it difficult to
find its cause - all the existing code I've looked at looks reasonable
and most of it has not changed in a long time.
Can you post more details/code about your custom geometry, otherwise I'm
not sure how to diagnose this further from here.
In any case, I'm attaching a patch that I've used to get some insight
into what is happening during the IntersectActions traversal, you
probably have something similar by now, but perhaps it is still useful
to you.
Cheers,
Carsten
Index: Source/System/NodeCores/Groups/Misc/OSGTransform.cpp
===================================================================
--- Source/System/NodeCores/Groups/Misc/OSGTransform.cpp (revision 2175)
+++ Source/System/NodeCores/Groups/Misc/OSGTransform.cpp (working copy)
@@ -49,10 +49,6 @@
#include "OSGRenderAction.h"
-#ifdef OSG_HAVE_ACTION //CHECK
-#include "OSGIntersectActor.h"
-#endif
-
#include "OSGTransform.h"
#include "OSGVolume.h"
@@ -165,13 +161,13 @@
m.invert();
- Pnt3f pos;
- Vec3f dir;
+ Pnt3r pos;
+ Vec3r dir;
m.multFull(ia->getLine().getPosition (), pos);
m.mult (ia->getLine().getDirection(), dir);
- Real32 length = dir.length();
+ Real length = dir.length();
if(length < Eps)
SWARNING << "Transform::intersectEnter: Near-zero scale!" << std::endl;
@@ -179,6 +175,8 @@
ia->setLine(Line(pos, dir), ia->getMaxDist());
ia->scale (length );
+ FINFO(("scaling s = [%f] -- 1/s = [%f]\n", length, 1.f/length));
+
return ActionBase::Continue;
}
@@ -187,73 +185,23 @@
IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
Matrix m = this->getMatrix();
- Pnt3f pos;
- Vec3f dir;
+ Pnt3r pos;
+ Vec3r dir;
m.multFull(ia->getLine().getPosition (), pos);
m.mult (ia->getLine().getDirection(), dir);
+ Real length = dir.length();
+
ia->setLine(Line(pos, dir), ia->getMaxDist());
- ia->scale(dir.length());
+ ia->scale (length );
+ FINFO(("scaling s = [%f] -- 1/s = [%f]\n", length, 1.f/length));
+
return ActionBase::Continue;
}
#endif
-#ifdef OSG_HAVE_ACTION //CHECK
-NewActionTypes::ResultE Transform::intersectActorEnter(
- ActorBase::FunctorArgumentType &funcArg)
-{
- IntersectActor *pIA = dynamic_cast<IntersectActor *>(
- funcArg.getActor());
- Matrix matrix = this->getMatrix();
- Line transLine;
- Pnt3f pos;
- Vec3f dir;
-
- matrix.invert();
-
- matrix.multFull(pIA->getRay().getPosition (), pos);
- matrix.mult (pIA->getRay().getDirection(), dir);
-
- transLine.setValue(pos, dir);
-
- pIA->beginEditState();
- {
- pIA->setRay (transLine );
- pIA->setScaleFactor(pIA->getScaleFactor() / dir.length());
- }
- pIA->endEditState ();
-
- pIA->setupChildrenPriorities();
-
- return NewActionTypes::Continue;
-}
-
-NewActionTypes::ResultE Transform::intersectActorLeave(
- ActorBase::FunctorArgumentType &funcArg)
-{
- IntersectActor *pIA = dynamic_cast<IntersectActor *>(
- funcArg.getActor());
- const Matrix &matrix = this->getMatrix();
- Pnt3f pos;
- Vec3f dir;
-
- matrix.multFull(pIA->getRay().getPosition (), pos);
- matrix.mult (pIA->getRay().getDirection(), dir);
-
- pIA->beginEditState();
- {
- pIA->setRay (Line(pos, dir) );
- pIA->setScaleFactor(pIA->getScaleFactor() / dir.length());
- }
- pIA->endEditState ();
-
- return NewActionTypes::Continue;
-}
-#endif
-
-
/*-------------------------------------------------------------------------*/
/* Init */
@@ -280,24 +228,6 @@
RenderAction::registerLeaveDefault(
Transform::getClassType(),
reinterpret_cast<Action::Callback>(&Transform::renderLeave));
-
-#ifdef OSG_HAVE_ACTION //CHECK
- IntersectActor::regClassEnter(
- osgTypedMethodFunctor2BaseCPtr<
- NewActionTypes::ResultE,
- TransformPtr ,
- NodeCorePtr ,
- ActorBase::FunctorArgumentType &>(&Transform::intersectActorEnter),
- getClassType());
-
- IntersectActor::regClassLeave(
- osgTypedMethodFunctor2BaseCPtr<
- NewActionTypes::ResultE,
- TransformPtr ,
- NodeCorePtr ,
- ActorBase::FunctorArgumentType &>(&Transform::intersectActorLeave),
- getClassType());
-#endif
}
}
Index: Source/System/NodeCores/Drawables/Geometry/Base/WS/OSGGeometry.cpp
===================================================================
--- Source/System/NodeCores/Drawables/Geometry/Base/WS/OSGGeometry.cpp (revision 2175)
+++ Source/System/NodeCores/Drawables/Geometry/Base/WS/OSGGeometry.cpp (working copy)
@@ -509,6 +509,8 @@
it.getPosition(1),
it.getPosition(2), t, &norm))
{
+ FINFO(("geo hit: t [%f] tri [%d]\n", t, it.getIndex()));
+
ia->setHit(t, ia->getActNode(), it.getIndex(), norm, -1);
}
}
Index: Source/System/Action/IntersectAction/OSGIntersectAction.cpp
===================================================================
--- Source/System/Action/IntersectAction/OSGIntersectAction.cpp (revision 2175)
+++ Source/System/Action/IntersectAction/OSGIntersectAction.cpp (working copy)
@@ -314,8 +314,15 @@
Int32 lineIndex)
{
if(t < 0 || t > _hitT || t > _maxdist)
+ {
+ FINFO(("rejecting hit: t [%f] _hitT [%f] _maxdist [%f]\n",
+ t, _hitT, _maxdist));
return;
+ }
+ FINFO(("accepting hit: t [%f] _hitT [%f] _maxdist [%f]\n",
+ t, _hitT, _maxdist));
+
_hitT = t;
_hitObject = obj;
_hitTriangle = triIndex;
Index: Examples/Simple/11picking.cpp
===================================================================
--- Examples/Simple/11picking.cpp (revision 2175)
+++ Examples/Simple/11picking.cpp (working copy)
@@ -184,6 +184,11 @@
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
+#ifdef WIN32
+ OSG::preloadSharedObject("OSGFileIO");
+ OSG::preloadSharedObject("OSGImageFileIO");
+#endif
+
// OSG init
OSG::osgInit(argc,argv);
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users