View Full Version : isEmpty function?
03-05-2012, 06:34 AM
is there any function in openGL like isEmpty in which we give a coordinate and it returns false if there is an object on that specific coordinate, or something equivalent?
thank you in advance
03-05-2012, 07:27 AM
03-05-2012, 07:50 AM
so, there is no way to check a certain coordinate, even indirectly?
03-05-2012, 09:19 AM
Of course there is = glReadPixels.
03-05-2012, 09:25 AM
Ok, so was thinking of a test if a 3D coordinate is inside of an object, V-man seems to have interpreted the question as if it's possible to check if a 2D screen coordinate is covered by something rendered (for which glReadPixels is a valid solution as long as the clear color does not occur on rendered images or you test the z-values).
So what exactly do you want to test?
03-05-2012, 11:48 AM
I want to test if a certain 3d coordinate is inside (or on the border) of an object
03-05-2012, 12:08 PM
OpenGL, in general, will not help you with that. All OpenGL does is render objects. Actually, it doesn't even do that; it renders triangles.
03-05-2012, 12:12 PM
so, if I have a matrix that represents a board, there's no way to check if a certain position is free or occupied? I ust know that beforehand and set the matrix myself?
03-05-2012, 12:22 PM
Yeah. So it's better to think of it transiently, once you've displayed information to openGL, you can't get it back, nor should you. When you plot something, you should already know where it is. Sometimes it makes shortcuts like the one you describe more difficult, but that would require it to retain the model in 3D AFTER representing it on the screen, which would be ludicrously ineffecient.
03-05-2012, 12:38 PM
ok, thank you very much for the help
03-05-2012, 12:39 PM
so, if I have a matrix that represents a board, there's no way to check if a certain position is free or occupied?
Why don't you know if a position is free or occupied? You drew something in that position, yes? Therefore, you must know if it is free or occupied.
03-06-2012, 03:51 AM
That is, if you are creating a board game, like chess, you need to keep track of free positions in your own data structures. It may very well be possible to get the result from OpenGL (read pixels, examine the depth buffer, use queries, etc), but it is not the recommended way to do it.
If you have a more complex scenario, with lots of piceses, then I would recommend that you use a quadtree or octree to detect collisions. This is also done outside of OpenGL.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.