DGL https://delphigl.com/forum/ |
|
Question on picking... https://delphigl.com/forum/viewtopic.php?f=19&t=6320 |
Seite 1 von 1 |
Autor: | dpm_dpmartin [ So Jan 28, 2007 01:13 ] |
Betreff des Beitrags: | Question on picking... |
Hello, My question is as simple as "Why can't I seem to pick the red rotating squares in my program?" which will become more apparent as I provide more detail. I am setting myself up to do some good things with OpenGL but I need my users to be able to interface with the scene - so I looked into some tutorials on picking and have made good progress, only one thing confuses me. I have several spinning squares stacked on top of each other - I have two columns of these - I can successfully pick any square but the bottom square on each column - try as I might, I can't pick the bottom square (in both cases, the red square) and I haven't got a clue why. Here's what my OpenGL program window looks like, my annotations are trying to illustrate my problem: ![]() My code is relatively simple... the picking stuff is more or less lifted from some Internet tutorials - with some slight modications made by me - although I'm not sure how I could have broken it though. Any help would be greatly appreciated... I can provide the .pas, .dfm and .dpr in a .zip if anyone has the heart to see see what's really happening (3K only). Code:
![]() |
Autor: | i0n0s [ So Jan 28, 2007 01:49 ] |
Betreff des Beitrags: | |
At that point, the only "fault" I could find, is that you're not using dglOpenGL.pas ![]() But that is just for comfort and won't resolve that problem. The only differnce I can see between your program and our selection sample in the wiki is the way you're taking the picked object: Code:
Code:
but that is not a reason why you're are not able to hit glName(1); |
Autor: | dpm_dpmartin [ So Jan 28, 2007 02:54 ] |
Betreff des Beitrags: | Been digging a little more... |
OK, Maybe this will help highlight the problem... the issue is not that I can't pick glName(1) - it seems I can - but that it was the green square, as opposed to the red one at the bottom. At first I thought it was like the red squares hadn't been assigned a name at all, but then I started picking all over the place on the screen... and I got the following surprising results: ![]() ...and now I'm starting to think there is something fundamentally wrong with my coordinates somewhere - in fact, it seems pretty obvious that this is true. I'll keep on looking at this, but if anyone can spot it straight away or have a run of the program (which can be found here http://www.hmusiccentre.org.uk/HMCImages/Picking.zip if wanted) and alter the code to fix it it would be really helpful. |
Autor: | i0n0s [ So Jan 28, 2007 12:02 ] |
Betreff des Beitrags: | |
Ok, I found the problem at line 197: But first another fault I found: Code:
You don't need to subtract 27 from Y, the titlebar has been subtracted before. So, the real problem: Code:
You only run this code if you're selecting, if you're just rendering you're using Code:
instead. If you're replacing gluPerspective with glFrustum it works nearly correct. Now you can select the red square, but you will select it too if the green square is in front of it. To resolve this you have to use the code I postet on post ago. |
Autor: | Phobeus [ So Jan 28, 2007 13:03 ] |
Betreff des Beitrags: | |
Don't want to interrupt, but did you thought about implementing some sort of color picking? After working with different methods, I think it is pretty easy to implement. If the user clicks, you are rendering the scene a second time offscreen. Every object is getting a unique color value and (of course) you have to disable everything that might influenece the color (texture, lighting, dithering etc. disable everything) Now you just need to read one pixel from the color buffer, trying to indentify it from some kind of color list. Because a modern graphic card should not having any troubles with one small offscreen rendering... especially because it's not needed every render pass, but only if the user clicks. If you having a true color envroiment you also have the Alpha channel additionally and should be able to handle lot's of objects, without any mathematic stuff. |
Autor: | LarsMiddendorf [ So Jan 28, 2007 16:14 ] |
Betreff des Beitrags: | |
You don't even need offscreen rendering. You can simply render the frame again with colors after SwapBuffers(), so they stay in the backbuffer. |
Autor: | dpm_dpmartin [ So Jan 28, 2007 17:49 ] |
Betreff des Beitrags: | |
OK - I've finally arrived at where I want to be and have two ways of identifying my picked objects now - the extremely simple way I started with (which works quite well, unless other objects get in the way of the one you want to pick) and the more complicated way which will cycle through multiple picked objects and ascertain which is closest to you - based on Depth - I got confused here for a while, as all my objects are on the same Z - but Depth must mean something else! The second method appears to work perfectly for my requirements, i.e. it will allow me to 'pick' the bottom square from the tower. Thanks for all of the hints and tips! 1) Simplest... Code:
Code:
![]() As for the comment by LarsMiddendorf, I'm sorry - but I didn't understand it - maybe I will later. |
Autor: | Phobeus [ So Jan 28, 2007 21:18 ] |
Betreff des Beitrags: | |
Have a look at: http://gpwiki.org/index.php/OpenGL_Selection_Using_Unique_Color_IDs |
Autor: | dpm_dpmartin [ Mo Jan 29, 2007 00:20 ] |
Betreff des Beitrags: | Very interesting... |
I have had a good read of that and it was really interesting. There'd be some work for me to do to translate the bits of C++ to Delphi though so, unless there's some incredible performance boost or the way I have implemented it is going to get really difficult when I have hundreds of items on the screen, I think I shall stick with the way that I have working, via Picking, illustrated above. |
Seite 1 von 1 | Alle Zeiten sind UTC + 1 Stunde |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |