I want that when I click on a specific point on the screen, a function call that return the point in 3d scene that I click.
For example, when I click on the top left of the screen, it should return x = 0, y = 1, z= 1; please help me create a method to do this.
edit:
Root = new BranchGroup();
setLayout(new BorderLayout());
add(canvas3D,BorderLayout.CENTER);
SimpleUniverse universe = new SimpleUniverse(canvas3D);
Shape();
universe.addBranchGraph(Root);
ViewingPlatform viewingPlatform = universe.getViewingPlatform();
OrbitBehavior behavior = new OrbitBehavior(canvas3D);
behavior.setSchedulingBounds(bounds);
viewingPlatform.setViewPlatformBehavior(behavior);
viewingPlatform.setNominalViewingTransform();
}
I'm using SimpleUniverse
in NetBeans.
I'm afraid the answer isn't straight forward. Depending on what is in your scene the mouse coordinates should change when you click on the screen. For instance if you have two objects so that the front one occludes the back one then you'd want to get the front objects coordinates. This is called
mouse picking
and there are several techniques for it. I found a few forums that explain how it's done and have code examples.Basically the idea is that you imagine there being a laser (or something else that casts a ray) between you the user and the screen. This thing then projects a ray through the point on the screen surface where the mouse was clicked "into" the screen. Anything that is on the rays path will then be picked and optionally the occlusion order of objects in the ray's path is resolved to give you the object closest to the "screen".
I am not familiar with J3D, but scraped the following code together from a few tutorials. It should get you started at least. The this you are looking for is this line
Point3D intercept = ...
at the bottom.http://www.java3d.org/selection.html