Intersection with Java3D pickfast API

2010-02-25 23:12:09.0 - [Permalink]   [1 Comments]

It took me awhile to figure out how to use the new Java3D pickfast API with setShapeRay. It was straightforward when I had figured out the need for setting the mode and flag of PickTool. But until I had figured that out the shapeRay was not working at all. Here is some example code:

// Test intersection from y=1.5 with a small vector pointing downwards the y-axis
final Point3d startPoint = new Point3d(0f, 1.5f, 0f);
final Vector3d direction = new Vector3d(0, -0.05, 0);
final PickTool myPicker = new PickTool(scene);
myPicker.setMode(PickInfo.PICK_GEOMETRY);
myPicker.setFlags(PickInfo.CLOSEST_INTERSECTION_POINT);
myPicker.setShapeRay(startPoint, direction);
final PickInfo closest = myPicker.pickClosest();

System.out.println("getClosestDistance: " + closest.getClosestDistance());
System.out.println("getClosestIntersectionPoint: " + closest.getClosestIntersectionPoint());

Kommentarer

2010-05-06 08:55:21.0

Actually, this code doesn't work. The method PickInfo.getClosestIntersectionPoint() seems to return null. Instead you have to extract the IntersectionInfo array and call getIntersectionInfo() on the first element of the array. Like so:
final Point3d intersectionPoint = closest.getIntersectionInfos()[0].getIntersectionPoint();

defdac

Add new Comment

Månadsväljare

[2013-4]  [2013-3]  [2012-5]  [2012-3]  [2012-1]  [2011-12]  [2011-8]  [2011-5]  [2011-4]  [2011-3]  [2011-2]  [2011-1]  [2010-12]  [2010-11]  [2010-10]  [2010-9]  [2010-8]  [2010-7]  [2010-6]  [2010-5]  [2010-4]  [2010-3]  [2010-2]  [2010-1]  [2009-12]  [2009-11]  [2009-10]  [2009-9]  [2009-8]  [2009-7]  [2009-6]  [2009-5]  [2009-4]  [2009-3]  [2009-2]  [2009-1]  [2008-12]  [2008-11]  [2008-10]  [2008-9]  [2008-8]  [2008-7]  [2008-6]  [2008-5]  [2008-4]  [2008-3]  [2008-2]  [2008-1]  [2007-12]  [2007-11]  [2007-10]  [2007-9]  [2007-8]  [2007-7]  [2007-6]  [2007-5]  [2007-4]  [2007-3]  [2007-2]  [2007-1]  [2006-12]  [2006-11]  [2006-10]  [2006-9]  [2006-8]  [2006-7]  [2006-6]  [2006-5]  [2006-4]  [2006-3]  [2006-2]  [2006-1]  [2005-12]  [2005-11]  [2005-10]  [2005-9]  [2005-8]  [2005-7]  [2005-6]  [2005-5]  [2005-4]  [2005-3]  [2005-2]  [2005-1]  [2004-12]  [2004-11]  [2004-10]  [2004-9]  [2004-8]  [2004-7]  [2004-6]  [2004-5]  [2004-4]  [2004-3]  [2004-2]  [2004-1]  [2003-12]  [2003-11]  [2003-10]  [2003-9