It is currently Tue Feb 18, 2020 1:21 am


All times are UTC




Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Picking
PostPosted: Tue Nov 16, 2010 4:12 pm 

Joined: Wed Nov 10, 2010 7:15 pm
Posts: 43
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).


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Picking
PostPosted: Tue Nov 16, 2010 6:07 pm 

Joined: Thu Nov 11, 2010 9:03 pm
Posts: 8
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 :?


Last edited by Metanoia on Tue Nov 16, 2010 10:32 pm, edited 1 time in total.

Top
Offline Profile  
Reply with quote  
 Post subject: Re: Picking
PostPosted: Tue Nov 16, 2010 6:48 pm 

Joined: Wed Nov 10, 2010 7:15 pm
Posts: 43
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.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Picking
PostPosted: Tue Nov 16, 2010 7:08 pm 

Joined: Thu Nov 11, 2010 9:03 pm
Posts: 8
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.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Picking
PostPosted: Tue Nov 16, 2010 9:20 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
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.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Picking
PostPosted: Tue Nov 16, 2010 10:04 pm 

Joined: Wed Nov 10, 2010 7:15 pm
Posts: 43
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


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Picking
PostPosted: Tue Nov 16, 2010 10:15 pm 

Joined: Sat Sep 18, 2010 9:45 pm
Posts: 189
Oh yeah, you can do color picking, forgot about that. I was thinking more of the ray method.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Picking
PostPosted: Tue Nov 16, 2010 10:31 pm 

Joined: Thu Nov 11, 2010 9:03 pm
Posts: 8
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.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Picking
PostPosted: Tue Nov 16, 2010 10:38 pm 

Joined: Wed Nov 10, 2010 7:15 pm
Posts: 43
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


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Picking
PostPosted: Tue Nov 16, 2010 11:41 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
If you want to do the selection by colour then have a look here:

http://www.ogre3d.org/forums/viewtopic.php?f=2&t=60138
http://wiki.python-ogre.org/index.php/C ... ion_Buffer

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


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net