View Full Version : Finding out if an object is obscured
05-24-2004, 01:05 PM
I'm currently working on a game (Windows, MSVC++, OpenGL) that features a ball that sometimes is obscured by a wall. Is there a way to check whether or not the ball is currently being obscured by a closer surface, partially or fully?
05-24-2004, 11:15 PM
OpenGL itself does not have any support for this, and there are many different ways to implement it, I suggest you do a search on goggle, search for "collision detection" and OpenGL or 3D or something like that and you should find lots of information.
One simple way is to calculate a bounding box around each of your objects (just get min/max x,y and z values), transform the bounding boxes with your objects.
Then it is pretty simple to make a collision detection algorithm to check when two bounding boxes overlap each other, this is of course far away from perfect, and only works good if you objects have a shape close to a box, but you once you have a hit you may do some kind of refined check to see if the objects actually do tuch each other and things like that.
As I said, there are many different ways to do it, I even think there are a few libraries available that does implement some more fancy collision detections, but I don't remember any names at the moment.
05-25-2004, 12:13 AM
Originally posted by mikael_aronsson:
OpenGL itself does not have any support for thisit does, though only as extension that should probably be used with care. drawing all the walls first, then drawing the ball as occlusion query. of course, if the goal is to not waste time on drawing the ball if its occluded this would be kind of pointless (exceptions would be horribly complex fragment programms/shaders).
the result is the number of visible pixels. using it efficiently for occlusion culling is of course a whole other subject and the best use i could think of in game terms might be rendering a "cheap" version of the scene from the pov of a character to tell how much cover an enemy has (for a turned based strategy game that shouldnt hurt.. but of course basing a fundamental part of gameplay on graphic card features might NOT be the best of ideas ,-) )
05-25-2004, 11:02 AM
People who tried the game have complained that they lose track of the ball when it's obscured, so I was planning on using the data to tell when to place a small dot on the screen indictating where the ball is.
05-28-2004, 05:27 AM
Occlusion queries are a core feature in OpenGL 1.5.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.