Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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  
  Picking Techniques  (Read 2238 times)
0 Members and 1 Guest are viewing this topic.
Offline jmguillemette
« Posted 2013-11-25 04:36:01 »

I'm really interested to know what is the "best" approach and then what are people actually using in real world projects (as they may not be the same) for picking

I have been looking at different ways to implement picking in my game engine.

Based on my research so far i have found the following techniques:

1) Color Picking.
This basically involves quietly re-drawing your entire scene but using a different color for every artifact. Then use the GL pixel at approach to determine the color at X,Y. This color will only match one of your objects.. (assuming you managed to keep them all unique colors)

A decent approach but it eats up noticeable FPS cycles.

 2) True ray casting
Calculate the normal and plane for each model and then determine the closest intersecting point.

Ok this sounds nice an generic .. but the math on this still escapes me.. Especially for my models that have lots of angles and faces.. So unless im missing a trick on this approach it sounds good but hard to implement.


3) Camera depth picking
I tripped over this one.. as it didnt seem like a popular approach but i found the strategy to be interesting. Using Opengl change the perspective to "zoom" really tightly into where the mouse is. Next call glRenderMode(GL11.GL_Render) and you get the count of artifacts draw to the screen. The closest one is your winner.


4) GL pick list
You assign a name to each model and then ask OpenGl to tell you what you clicked on.. which sounds great! only this feature appears to be dead in current releases..


So what are people actually using??

For my purposes im most interested in 3D applications

thanks!
j.
 
[edited] - corrected typo.. grr typos..
[edited +1] - added type 4 OpenGL Pick List

-=Like a post.. give the author a medal!=-
Offline Danny02
« Reply #1 - Posted 2013-11-25 09:31:29 »

The thing is ray casting gets trivial when you include collision detection into your game, something probably every game has. Most of the time your physics-engine will handle this for you.
Offline jmguillemette
« Reply #2 - Posted 2013-11-25 12:46:33 »

Interesting. I do have a physics engine currently in my game and I already have raycasting working with it. But this implementation is limited to models that the physics engine knows about.

If i had a raycasting technique that worked more generically then it would cover models outside the physics engine also.

Based on your comments i may be overkilling my solution then?


-=Like a post.. give the author a medal!=-
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline StrideColossus
« Reply #3 - Posted 2013-11-25 12:59:36 »

Option #2 is definitely the way to go I believe: give each object in your scene a bounding volume (axis-aligned box or sphere are simplest), determining ray-volume intersection is relatively trivial, and there are plenty of tutorials out there on this approach.

One of the advantages of this is that you can re-use the same functionality for picking, collision detection (as Danny02 mentions) and frustum culling if you need them.

For the others options:

#1 and #3 are a bit clunky IMHO and I doubt are used in any 'real' projects or games.

#4 just plain sucks Wink

- stride
Offline jmguillemette
« Reply #4 - Posted 2013-11-25 14:41:52 »

Thanks for the input stride.

Unfortunately I find lots of posts saying doing 2) is the best approach. Some say its  really hard. Some say its super easy. And I have yet to find one that actually gets into the details of how this is done in laymen terms.
Most that claim to do so have links to "examples" which at this point all seem to be broken links. (very frustrating)
Even searching the Game Mechanics section of this forum has lead to little more than confusion (and more broken links) on my part.

The concept is simple enough. Simplify the collision detection by making a box or sphere around your model to act as a boundary. (this is a theoretical entity and never drawn to the screen) then test if a line from unproject mouse click x,y,0 to unprojected x,y,max_ray_distance intersects the the bounding shape.

Now add in rotation and transformation and things seem to be more complex.. (not to mention im still not clear on the equation to support the simple case)

So I guess I'm really looking for a real world example of "option 2) ray tracing".  Anyone go one?


-=Like a post.. give the author a medal!=-
Offline StrideColossus
« Reply #5 - Posted 2013-11-25 14:49:12 »

Agreed that searching is mighty frustrating, the quality of some of the 'guides' out there is questionable (when they still exist!) so I bookmark any good ones I find.  Will dig out some links when I'm back on my own machine at home and maybe some code if appropriate.

EDIT: Actually just remembered a good one, I based my implementation on this tutorial, explains the maths if you need it and provides some pretty pictures Smiley

http://antongerdelan.net/opengl/raycasting.html

Note this is just pure 3D, i.e. maths, as opposed to OpenGL.  It assumes you're using custom model-view-projection matrices rather than the 'old' style of getting GLUT or something to do it for you.
Offline jmguillemette
« Reply #6 - Posted 2013-11-25 16:06:39 »

Thanks for the link. I will study it and let you know how  i make out.

-=Like a post.. give the author a medal!=-
Offline Roquen
« Reply #7 - Posted 2013-11-25 16:13:35 »

Use a physic engine and call it a day.
Offline jmguillemette
« Reply #8 - Posted 2013-11-25 20:29:23 »

a physics engine seems like overkill, if all i want to do is build a pretty 3D menu ..

-=Like a post.. give the author a medal!=-
Offline Simn
« Reply #9 - Posted 2013-11-25 21:49:34 »

This is what I use in my engine: http://pastebin.com/6KQvTTj1

It should work if you split the components in your menu into triangles.

- Simn
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #10 - Posted 2013-11-26 01:45:56 »

This is what I use in my engine: http://pastebin.com/6KQvTTj1

It should work if you split the components in your menu into triangles.
So, this is 3D ray picking correct? You could implement this to work with face picking? If so, you just saved me from having to figure out a lot of math!

Offline Simn
« Reply #11 - Posted 2013-11-26 06:35:38 »

I don't see why it shouldn't work for you, so yes. Wink

This video demonstrates it in my engine.

- Simn
Offline jmguillemette
« Reply #12 - Posted 2013-11-26 06:47:01 »

Hi Simn,

You would you be willing to share your Vector3 class. Im trying to read through and understand all of the code and it looks like some of the math is in it.

"Vector3().computeNormal(v1, v2, v3);"

thanks
j.

-=Like a post.. give the author a medal!=-
Offline Simn
« Reply #13 - Posted 2013-11-26 07:20:41 »

Here you go: http://pastebin.com/aNfTxe9h Wink

- Simn
Offline Roquen
« Reply #14 - Posted 2013-11-26 09:48:09 »

It's always handy to sketch what you want to do rather than how you think you want to do it.  Chances are you don't need to be able to pick.
Offline jmguillemette
« Reply #15 - Posted 2013-11-26 10:13:40 »

Hi Roquen,

I appreciate the input.. 

My game is a 3D one. I have built the engine from scratch.
One of the features i need to support in my game is the user clicking on 3D objects and being able to determine what they clicked on and sometimes what part of a model they clicked on specifically.

For this raycasting / picking seemed to be the answer. If there is another technique you think would be simpler I would welcome the suggestion.

thanks
J.

-=Like a post.. give the author a medal!=-
Offline Roquen
« Reply #16 - Posted 2013-11-26 11:11:12 »

Ok...that's quite different from a 3D menu system.  Back to my original answer:  use a physic engine and call it a day.
Offline delt0r

JGO Knight


Medals: 27
Exp: 18 years


Computers can do that?


« Reply #17 - Posted 2013-11-26 14:33:42 »

If you dead against a physics engine, or like me didn't want to waste time with one for just picking. I found that ray tracing with bounding spheres worked awesome. I was picking things on objects too. I used a hierarchy  of such spheres for that. I would group them a bit with bounding spheres as well if there are lots of objects on the screen. Note that its very easy to check if a ray intersects a sphere. For odd shapes i use more than one sphere. 

Not sure about pixel perfect however. My models have quite a lot of triangles if up close.

I have no special talents. I am only passionately curious.--Albert Einstein
Offline jmguillemette
« Reply #18 - Posted 2013-12-05 20:06:39 »

Update

So i have some working code for ray picking with Pixel perfect accuracy !
ok perhaps that was overkill but its easy enough to scale back.

Right now i have test code and a test scene for testing the feature.

Would there be value in me sharing this with a code post and video for the community ?

j.

-=Like a post.. give the author a medal!=-
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #19 - Posted 2013-12-05 20:07:55 »

Oh definetly! Even if I don't use it(I'll look at it), I'm sure others would benefit from it greatly.

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.

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

Norakomi (29 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (57 views)
2014-10-14 00:39:48

TehJavaDev (56 views)
2014-10-14 00:35:47

TehJavaDev (47 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
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!