Volumes Of Fun

Page 1 of 3

Author:  paycheck [ Tue Nov 16, 2010 4:12 pm ]
Post subject:  Picking

My goal for today is to implement picking into my program. I haven't done a ton of research yet, but was wondering what various users here are using to get the job done efficiently.

Also, while I've heard that it is much easier to do only local (closest 10x10 blocks or something) style picking, I would very much like to be able to implement picking that can pick at any distance, even if the feature is rarely or never used (someday I might need it, and I assume there has to be some way of doing it).

Author:  Metanoia [ Tue Nov 16, 2010 6:07 pm ]
Post subject:  Re: Picking

The way I am planning on doing it is like it follows:

1.-Do nothing until the user clicks.
2.-After the user clicks, render the scene using colors to encode a cube's id.
3.-Check what is the color which is under the position where the user clicked.
4.-Render again the scene using the usual method (textures, lights, and the like).
4.-Swap buffers.

This being said, I am using pure OpenGL. If you are using Ogre maybe it would be easier to perform a ray trace? I dont know, I am not familiar with Ogre :?

Author:  paycheck [ Tue Nov 16, 2010 6:48 pm ]
Post subject:  Re: Picking

is it an invisible render? aka the cost of a click is 1 frame? I guess even then, that sounds like a lot more horsepower then I'd like, because it seems like I would need 2 sets of my world in memory 1x for normal texturing, and 1x for picking(where every color would be an XXXXYYYYZZZZ index... still, definitly makes sense, and would be very precise.

EDIT: about ogre, I don't really know how much ogre is buying me other then a base off of which to build on. Since I'm using polyvox and manual objects, I'm pretty much negating my ability to use ogre picking... maybe if I use an ogre octree to hold my chuncks, and then do my own ray through whichever chunck ogre selects then I could get the right block? I really don't know, and it doesn't sound like it would be super accurate if I'm firing my own ray... like would edges select the wrong cubes and stuff? I really just don't know. Also, is there a way to render the world to buffer but not actually to screen? I wouldn't want the colorcoded cubes to ever show up on screen. Also, if you can think of a not 2x memory way to do that, I would almost certainly go that route.

Author:  Metanoia [ Tue Nov 16, 2010 7:08 pm ]
Post subject:  Re: Picking

Yeah, it is an invisible render, the color-coded image is never shown to the user, it gets overriden with the textured image. ;)

If what you want to do is just picking a cube close to the player (as it is done in Minecraft), you can do it in a more straightforward way: you just check which direction the player is facing, and do a easy ray check using the data stored on your Volume object. When you find something different to air, stop and store that position :D

If you want full-blown picking, yeah, you will need more memory, but you can free it after the picking, which anyway is just done after the user clicks.

Author:  David Williams [ Tue Nov 16, 2010 9:20 pm ]
Post subject:  Re: Picking

For the problem of picking in general there are various options. Metanoia's solution has the advantage of being very precise, but the downside is that you have to render the extra frame. Don't worry about the memory though - you should be able to use the same geometry but just switch the shaders.

On the other hand you might want a more general solution which you can use for intersecting bullets with geometry, or testing visibility between two points. Ogre does offer some functioanlity here, I think it is called a 'ray scene query'. Let me know if you can't find it. It just tests for intersections between a ray and the objects bounding box.

For PolyVox in particular, you should probably looking testing against the underlying volume rather than the extracted surface. Create a ray though you scene, and move along the ray while looking in the Volume to see if anything exists at that location. You might have to do a few hunderd checks but it should be pretty fast.

You can also use some combination of the above.

Author:  paycheck [ Tue Nov 16, 2010 10:04 pm ]
Post subject:  Re: Picking

for the general ray solution, how do I make it pixel perfect? Is pixel perfect only possible by doing the extra render? Also, how do I do it by just changing shaders... wouldn't I need to specify which color each cube is somewhere (by location) it seems that that very process, making each cube have it's own color would have to be defined as an extra color for every cube (or another 24bits per voxel.

EDIT: NM I take it back, clearly I could just color it based on world coordinates, and then check based on where the camera is and that would give a super easy way to figure out which block it is... I think this is what I'll do! Thanks

Author:  beyzend [ Tue Nov 16, 2010 10:15 pm ]
Post subject:  Re: Picking

Oh yeah, you can do color picking, forgot about that. I was thinking more of the ray method.

Author:  Metanoia [ Tue Nov 16, 2010 10:31 pm ]
Post subject:  Re: Picking

I'm glad I could help! :D

If you get it working, I would love to hear how it's working for you, specially performance-wise.

Author:  paycheck [ Tue Nov 16, 2010 10:38 pm ]
Post subject:  Re: Picking

well, if you know how to check the color in the buffer, I should be able to do it tonight, I have class in 20 minutes

Author:  David Williams [ Tue Nov 16, 2010 11:41 pm ]
Post subject:  Re: Picking

If you want to do the selection by colour then have a look here:

http://wiki.python-ogre.org/index.php/C ... ion_Buffer

For a large volume you may run out of colours though ;-)

Page 1 of 3 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group