Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (517)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (578)
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 2580 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 Duke




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 Duke




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 Duke





« 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 Duke




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
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
 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)
                        break;
                      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)
                              break;
                            if (parent instanceof FaceGroup)
                              break;
                            parent = parent.getParent();
                          }
                          if (parent!=null) {
                            ((FaceGroup)parent).doClick();
                          }
                          mib.pick = false;
                        }
                      }
                    }
                    mib.pick = false;
                  }
                }
              }
            }
Offline kevglass

JGO Kernel


Medals: 191
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.

Kev

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 Duke




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 - http://www.dot-brain.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline hawkwind

Junior Duke




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 Duke




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 Duke





« 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 Duke




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 Duke




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).

Ca$
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.

DarkCart (17 views)
2014-10-31 21:44:48

DarkCart (22 views)
2014-10-31 21:43:57

TehJavaDev (40 views)
2014-10-27 03:28:38

TehJavaDev (31 views)
2014-10-27 03:27:51

DarkCart (44 views)
2014-10-26 19:37:11

Luminem (27 views)
2014-10-26 10:17:50

Luminem (30 views)
2014-10-26 10:14:04

theagentd (36 views)
2014-10-25 15:46:29

Longarmx (64 views)
2014-10-17 03:59:02

Norakomi (62 views)
2014-10-16 15:22:06
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

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!