Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (549)
Games in Android Showcase (139)
games submitted by our members
Games in WIP (593)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How to get object picking system work?  (Read 2650 times)
0 Members and 1 Guest are viewing this topic.
Offline zhoupc

Junior Newbie

Java games rock!

« Posted 2004-12-30 05:05:46 »

I'm a beginer to xin3d.Recently I'm doing a xith3d project,I need the object picking function.I wonder how to get pick ray working?any sample source or advice? thanks a lot!
Offline ewills

Junior Devvie

Java skeletal animation systems rock!

« Reply #1 - Posted 2005-01-02 00:18:56 »

If you have the latest Xith from CVS, you can use Canvas3D.createPickRay(int x, int y, Point3f o, Vector3f d) to get a pick ray.

You could also use View.pick(Canvas3D c, int x, int y, int w, int h) for OpenGL-style picking (this method, however, is computationally slow).
Offline zhoupc

Junior Newbie

Java games rock!

« Reply #2 - Posted 2005-01-02 00:49:10 »

;)Thanks ewills!!You help me a lot,but I wonder when the pickray is created,how to konw which object is selected? thanks.(sorry,I'm a beginner)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ewills

Junior Devvie

Java skeletal animation systems rock!

« Reply #3 - Posted 2005-01-02 15:42:25 »

The most straightforward method is to first create a pick ray and then test for intersections with the world-space bounds of each scene graph object.

Use Node.getVWorldBounds() to get an object's world-space BoundingSphere and BoundingSphere.intersect(Point3f o, Vector3f d) to test for intersections.

You should probably keep track of all intersections and then return the one closest to the viewer.

Using View.pick(Canvas3D c, int x, int y, int w, int h) allows you to bypass all of this, but is again less computationally efficient.
Offline DonCrudelis

Junior Devvie

« Reply #4 - Posted 2005-01-02 16:51:50 »

BoundingSphere.intersect(Point, Vector) :
Does this method calculate collisions with a ray or a segment?
Offline ewills

Junior Devvie

Java skeletal animation systems rock!

« Reply #5 - Posted 2005-01-02 21:20:30 »

Good question!   Smiley  The code (in spatial.bounds.Sphere) appears to intersect the sphere with a ray.
Offline zhoupc

Junior Newbie

Java games rock!

« Reply #6 - Posted 2005-01-06 02:25:10 »

Now I use View.pick(Canvas3D c, int x, int y, int w, int h)  can return which node and which texture I clicked.How to know which model or object it is?

the following is my click code
 if (pick_sync!=null) {
              synchronized (pick_sync) {
                if (pick) {
                  PickRenderResult[] results = view.pick(view.getCanvas3D(0), pick_x,
                      pick_y, 3, 3);
                  if (results == null) {
                  else {
                    for (int i = 0; i < results.length; i++) {
                      if (!mib.pick)
                      Node[] nodes = results[i].getNodes();
                      for (int j = 0; j < nodes.length; j++) {
                        System.out.println(" You click nodes " + j);
                        if (nodes[j] != null) {
                          Node parent = nodes[j].getParent();
                          while (true) {
                            if (parent == null)
                            if (parent instanceof FaceGroup)
                            parent = parent.getParent();
                          if (parent!=null) {
                          mib.pick = false;
                    mib.pick = false;
Offline kevglass

« JGO Spiffy Duke »

Medals: 232
Projects: 24
Exp: 18 years

Coder, Trainee Pixel Artist, Game Reviewer

« Reply #7 - Posted 2005-01-06 05:22:07 »

Make yourself a mapping table from Node -> Object when you're creating your objects/models in the first place.


Offline zhoupc

Junior Newbie

Java games rock!

« Reply #8 - Posted 2005-01-10 22:13:19 »

Thanks!But when I click in the scene,it always return "Node 0",why this happen?where should I define the Mapping table?In the Java code or in the GTKRadient?   Thanks a lot!
Offline z.e.r.o

Junior Devvie

Java games rock!

« Reply #9 - Posted 2005-01-26 04:45:50 »

My 2 cents are that you are testing the root node of the scenegraph too, and it ALWAYS intersects the ray, unless you panned the view far away all the objects in the scene. In Xith3D nodes in an higher hierarchical level have bounds built to include all their own children.
I will leave the root node out of the loop and all should be fine.

To get picking working you should place all the pickable objects on a branch (it's what I do), so you can test only what you need, otherwise, if you have lots of things on screen is difficult to maintain good performance.

Matteo Anelli
.brain -
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline hawkwind

Junior Devvie

Java games rock!

« Reply #10 - Posted 2005-01-26 17:35:14 »

Here Here...a separate pick hierarchy is the only way to go.

 Minimizing the pickables speeds things up.  It easier to have a "set all object pickable" walker class to go down the pick tree and insure all shapes and group are really pickable.  
Some loaders insert one or more BG when returning an obj...gotta make sure the entire tree is pickable
Offline cascade

Junior Devvie

Java games rock!

« Reply #11 - Posted 2005-02-09 11:00:58 »

I'm just doing some picking/event handling stuff. Picking itself is only the beginning of the story ...

first comes picking ... then a hierarchy with possibly multiple layers for a HUD, the static and dynamic scene objects, the terrain, ... then selection and input mapping to selected objects ... drag and drop handling in 3D

a common framework for this would be nice !

Offline DonCrudelis

Junior Devvie

« Reply #12 - Posted 2005-02-11 14:30:47 »

How to get the picking system faster?
Like it is now, 250 ms is fast Tongue.
I have a big terrain, but want to pick both the terrain and some units moving around on it, I want it to be calculated
< 5 ms like other games..
Offline ewills

Junior Devvie

Java skeletal animation systems rock!

« Reply #13 - Posted 2005-02-11 16:49:44 »

OpenGL pick mode is really slow (View.pick()).  You can do much better by creating a pick ray (Canvas3D.createPickRay()) and then testing for collisions with objects in the environment.

My picker performs the following operations:
1. Collect all objects whose bounding spheres intersect the ray.
2. Of those objects, determine the ray-geometry intersection closest to the viewer.

This method is super-fast!

Offline cascade

Junior Devvie

Java games rock!

« Reply #14 - Posted 2005-02-14 05:07:34 »

I have  a special problem for which I need picking:

Laserrange finder simulation for mobile robots. A Laserrangefinder (2D) has a laser and a rotating mirror that fans out the laser beam and allows for example 180/360/720 distance readings in a horizontal 180 degree plane. This must work at 4 - 8 Hz frequencies. If possible I want to get a 3D laser range finder to work but this will cause much more computation.

I do it the following way:

for all pickable objects I keep a plane buffer (triangles) for their geometry (e.g. converting quad geometry to triangles).

I keep basically two groups of objects: static and dynamic.

the static objects like terrain or immobile structures for example are indexed using a 2d grid for optimization (each triangleplane is indexed in the grid). So for pick ray computation I compute the projection of the pickray in the grid and just need to check the triangles which are possibly ahead of the pick ray (my terrain has multiple thousand triangles) making this very fast.

the dynamic objects are organized in different layers and are not stored in the grid (this would require to compute the object to grid coverage after each movement). For example I have one layer for the HUD/GUI objects and one or more layers for the other scene objects.

a pick event (e.g. mouse button event) traverses this hierarchy to find the object being picked (closest to pick-origin but produces a TreeMap with all intersected objects).

objects itself have an event handler (per object/shape/ or each plane) that receives the pick event and further info can be computed (local intersection position, Vworld intersection position). For example a local 2d coordinate system mapped to a quad. This is the way I am just implementing a UI and maps (radar screen etc).

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.


Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Archive (21 views)
2015-01-29 04:26:08

theagentd (21 views)
2015-01-28 15:33:52

GamerIDGoesHere (29 views)
2015-01-27 01:23:23

GamerIDGoesHere (31 views)
2015-01-27 01:22:15

CopyableCougar4 (38 views)
2015-01-27 00:34:41

CopyableCougar4 (23 views)
2015-01-26 04:47:56

Olo (17 views)
2015-01-25 21:26:00

Olo (23 views)
2015-01-25 18:44:22

Robo11 (39 views)
2015-01-25 06:14:26

basil_ (33 views)
2015-01-17 22:29:32
2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!