PDA

View Full Version : 3D image hiding



Reaper4774
10-21-2001, 01:02 PM
Hey, all. I'm kinda new to the whole 3d-imaging, and I think I'm missing out on something very basic. Here's the general problem.

As an assignment, I'm required to create a program that depicts a simple airplane circling around a 20-story building. Before I get yelled at, please believe that this IS the assignment, which was made up long before the horrible events that make all our bowels clench in rage. If you don't believe me, email me, and I'll give you the link to the assignment.

Anyways... rather than lay out all my existing code (200+ lines at this point), I'd rather give you the gist of my objects.

The plane consists of a cylinder created using "gluCylinder", with two wings and a tail-fin, all of them "glBegin -- glEnd" polygons. The building has an instance for a window, which is then incorporated into an instance for a story (16 windows per side), which is then turned into an instance for a building. The building is constructed entirely of "glBegin -- glEnd" polygons.

Overall, I can create an airplane aligned with the y-axis by calling on function, and a building alligned with the y-axis with another. The problem is their relation to each other;

I can depict the airplane circling around the building, but the depth perception is not working properly; at the point the airplane is SUPPOSED to be behind the building, it is still completely visable.

I'm sure there's an easy way to fix this... some function or callback I've left out. If you'll inform me as to what it is, I'll be very grateful.

Thanks,
Reaper4774

john
10-21-2001, 02:52 PM
Howdy,

glEnable(GL_DEPTH_TEST);

perhaps?

hope this helps,
cheers,
John

Reaper4774
10-21-2001, 05:53 PM
Thanks a lot, it did. But I did run into a problem that I solved, but I just thought I'd post to make sure no one makes the same mistake; remember in your display or idle callback to clear the GL_DEPTH_BUFFER_BIT, or nothing gets rendered.

Also, I'm not sure this is good programming practice, but I had to do it anyways, and I'd like to get an input on it; I noticed that after solving this problem, the windows on my building disappeared. I assume that since the windows and the building wall were in perfect line, the depth perception got confused and wiped out the windows. My solution was to move the windows away from the wall by a very small amount (0.001 to be exact). However, I think this is the quick-and-dirty method, and I'd like some input on better methods. Thanks for your time.

Reaper4774

Gavin
10-22-2001, 02:02 AM
Be careful of z fighting in such situations, say you are viewing in z fomr -1000 to 1000 small increments like what you have mentioned could give dodgy results due to rounding/float approximation. And bits of your window will be in front of the wall and bits wont.

Owlet
10-23-2001, 09:25 AM
Well, probably the most solid way of drawing windows ON the building would be to use a texture map. That should solve any depth issues, because the whole side of the building would essentially be one surface. Texture mapping is pretty complicated unto itself, and I'd be willing to bet it comes later in the class you're taking http://www.opengl.org/discussion_boards/ubb/smile.gif

Good Luck!
Owlet