Skip to main content

Picking - general problem

4 replies [Last post]
clemente
Offline
Joined: 2008-10-16

Hi all,

I need to compute intersections between an arbitrary line/ray and objects in my scene graph. I try to utilize the picking mechanism to do so - but whatever I do, my picking results remain null.
Below, I post the method that creates one of the two cubes.

I wrote a pick() method that should pick at least the object located in the universes origin. You find this method below, too.
Unfortunately, this method always gives "null" as result of my picking.

I run pick() directly after creating the whole scene graph and visualizin it on screen.
Does anyone know, what I am doing wrong? Or if I am going the complete wrong direction?

Thanks a lot,
Clemente

My pick() method:
void pick() {
PickShape shape = new PickRay(new Point3d(10, 0, 0), new Vector3d(-0.1, 0, 0));
final Object[] result = this.universe.getLocale().pickAll(shape);
System.out.println("Result: " + result);
}

Following method creates one of the two cubes. The second one is created the same way.

public BranchGroup createCube() {
final BranchGroup root = new BranchGroup();
// Transformations...
final Transform3D rot1 = new Transform3D();
final Transform3D rot2 = new Transform3D();
rot1.rotX(Math.PI / 4.0d);
rot2.rotY(Math.PI / 5.0d);
rot1.mul(rot2);
rot1.setTranslation(new Vector3d(-0.4, 0, 0));
final TransformGroup objRot = new TransformGroup(rot1);
objRot.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
objRot.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRot.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objRot.setPickable(true);
objRot.addChild(new ColorCube(0.2));
root.addChild(objRot);
root.setPickable(true);
return root;
}

Message was edited by: clemente

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
leha23
Offline
Joined: 2008-09-05

Hi,
the pick() should work.I think the problem is that pick is called immediately after creating the scene and before the canvas is visible.
Try adding a button or something to your app and call the pick-method from the listener when canvas is visible.
Hth

adrianoaristarco
Offline
Joined: 2007-11-02

I see that this is a common question, this is the answer I received some time ago, maybe you find it useful:
http://forums.java.net/jive/thread.jspa?threadID=33792&tstart=0

Regards

clemente
Offline
Joined: 2008-10-16

Thanks a lot for your suggestions!

(Funny thing: I posted this message several hours ago - seems to be disppeared... Once agein:)

First dirty test - I ran pick() within an endless loop - showed me a not-null result after some hundreds of iterations.

So I have to determine if the scene graph is ready for picking. The thread adrianoaristarco linked to hits my problem fully. Unfortunately I see no solution there. The link in this thread is dead, but I believe it pointed to the example classes shipped with Java3D.
I took a look at them but found no glue. They do picking deep into some behavior classes what hides the "timing-problem" IMHO.

The only thing I see by now is a time-controlled delay. Surely no good solution... Do I miss anything? Or do you have any other idea?

Clemente

Omnipotent_Penny
Offline
Joined: 2012-04-08

Hi,

It may not be significant but I notice your pick ray direction is not a normal.

I have pick rays working quite well. My engine uses a behaviour that wakes up on frame and services any objects that wish to perform a pick. The reason I do this is to ensure that all picking is done in between the scene modifications and rendering.

good luck!