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).
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.
You only run this code if you're selecting, if you're just rendering you're using
Code:
glFrustum (-0.1,0.1,-0.1,0.1,0.3,25.0);
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.
Registriert: Sa Mai 04, 2002 19:48 Beiträge: 3830 Wohnort: Tespe (nahe Hamburg)
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.
_________________ "Light travels faster than sound. This is why some people appear bright, before you can hear them speak..."
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!
To answer the question posed by Phobeus, as best as I can anyway... I believe that I can't use colour picking for my requirements as I intend these spinning squares to have texures and represent Album covers - I limited the program that I posted on this forum to just be coloured squares so that I would not confuse the issue of anyone helping with textures etc.. If I can get everything working as expected, what I am looking for is a new way of HMusicCentre users being able to pick Albums by certain Artists - via some eye-candy selection screen where an Artist has a 'tower' of Albums and users can click on the one they want to play... i.e. just like below...
As for the comment by LarsMiddendorf, I'm sorry - but I didn't understand it - maybe I will later.
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.
Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast
Du darfst keine neuen Themen in diesem Forum erstellen. Du darfst keine Antworten zu Themen in diesem Forum erstellen. Du darfst deine Beiträge in diesem Forum nicht ändern. Du darfst deine Beiträge in diesem Forum nicht löschen. Du darfst keine Dateianhänge in diesem Forum erstellen.