Thank you Daniel,
you saved my day.
My problem is a little biot different from yours, because i have not various
geometry in one
Shape3D node (because you are restricted to the same type of geometry then).
I have associated my "abstract objects" with the Shape3Ds i use, by using the
setUserData()
of the node. When i click into the scene i want my "abstract" objects back and
therefore had
to inquire the appropriate (closest) node, which i could not get from the
ResultSets getObject()
method.
The workaround i use and that originated from your contribution:
Point3d eyePoint = pickCanvas.getStartPosition();
pickCanvas.setShapeLocation( mouseEvent );
// :NOTE: unfortunately the pickClosest() method simply won't give
// me the closest node. the following is a work around for the line
// PickResult pickResult = pickCanvas.pickClosest();
PickResult[] pickResults = pickCanvas.pickAll();
if ( pickResults != null && pickResults.length > 0 ) {
double distance = -1;
int index = 0;
double d;
PickIntersection pickIntersection;
for ( int i = 0; i < pickResults.length; i++ ) {
// for some strange reason the pickIntersection can be null!!!
pickIntersection = pickResults[ i ].getClosestIntersection( eyePoint
);
if ( pickIntersection != null ) {
d = pickResults[ i ].getClosestIntersection( eyePoint
).getDistance();
if ( i == 0 || d < distance ) {
distance = d;
index = i;
}
}
}
System.out.println( this + ": picked result with index " +
index + "(" + pickResults.length + ")");
Node node = pickResults[ index ].getObject();
// strike!
It appears to me that the getClosest() and getAllSorted() methods work quite
well, but the
pickShape is not in the proper place (starting at the current viewport
position). But this
is not what sun tells us in the specification!!
Cheers,
Karsten
"Dvorak, Daniel J." wrote:
> I'm using multiple geometries in the same Shape3d, and was getting the same
> results you mention (farthest object always got picked). Others posted the
> solution to this problem on this list. Here's what I use:
>
> pickCanvas.setShapeLocation(currentEvent);
>
> // get the starting position of the pick
> Point3d eyePos = pickCanvas.getStartPosition();
>
> // the pickClosest returns a PickResult with the picks sorted by the
> distance
> // from the ViewPlatform to the intersection point.
> PickResult pickResult = pickCanvas.pickClosest();
>
> if (pickResult != null) {
> PickIntersection pi =
> pickResult.getClosestIntersection(eyePos);
>
> int index = pi.getGeometryArrayIndex();
>
> ......
>
> }
>
> Hope this helps
> Daniel Dvorak
>
> -----Original Message-----
> From: Karsten Fries [mailto:[EMAIL PROTECTED]]
> Sent: Monday, February 05, 2001 6:28 AM
> To: [EMAIL PROTECTED]
> Subject: [JAVA3D] Picking problems
>
> Hi all,
>
> i have a tiny problem with picking. Almost everything is fine. But i get a
> strange behavior using
> PickCanvas of the utilities calling its pickClosest() method. The
> intersections i get are still ok, but
>
> my interest lies in the picked node. And it appears to me that in all cases
> never the nearest objects
> node is retrived using getObject() or getNode( PickResult.SHAPE3D ) of the
> PickResult.
> even more confusing: in the majority of the cases i have the impression that
> the object with the
> greatest distance is picked.
>
> is this something known??? has someone a workaround or is this fixed in the
> newest beta??
>
> i'm currently using 1.2.1 beta 1
>
> Thanks for any comments on this,
> Karsten
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA3D-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA3D-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".