Skip to main content
gamedev.net
🔒 Locked

Empty Sphere

Started by mbanghart Jul 16, 2008 at 8:55 AM 3 replies 2.3k views
Original Post
mbanghart
mbanghart
How do I create a sphere that is not filled (I want to draw other things inside the sphere? Thanks
haegarr
haegarr
Well, mathematically a filled sphere is given by
(x-x0)2 + (y-y0)2 + (z-z0)2 - R2 <= 0
while a hollow sphere is given by
(x-x0)2 + (y-y0)2 + (z-z0)2 - R2 == 0

But I assume that is not the answer you are expecting. The problem is, however, that I don't know _what_ you're expecting... What is the context, and how do you construct a solid sphere opposed to the hollow sphere? OpenGL, as any other rendering API, deals with surfaces only (the 2nd formula above).

A sphere is a 2-manifold, and hence rendering a sphere with an opaque material doesn't depend on its solidness. It becomes different only when you make a hole into the surface. (And, of course, its physical behaviour is different whether it is solid of hollow.)

If you want to see objects inside the sphere, you have to use transparency. From a physical point of view you need to simulate refraction, but that isn't easy. However, the refraction really depends on whether the sphere is hollow or not.
Lord_Evil
Lord_Evil
Maybe he means drawing a transparent sphere. Then it could be as follows:

1. draw the back faces of the sphere, i.e. inner side (if the sphere is wound CCW then changing front faces temporarily to GL_CW would do the job).
2. draw the the objects inside the sphere
3. draw the front faces of the sphere, i.e. outer side

For steps 1 and 3, blending has to be enabled.
Step 2 can be done before step 1 if the objects aren't transparent. Doing so would save some overdraw (hidden pixels of the inner side not drawn).
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
V-man
V-man
GL deals with points, lines, triangles. That's all.
If you are going to render a filled sphere or any other polygonal surface for that matter, I'm guessing you mean
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

and to make it unfilled

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
haegarr
haegarr
Quote:
Original post by Lord_Evil
Maybe he means drawing a transparent sphere. Then it could be as follows:

1. draw the back faces of the sphere, i.e. inner side (if the sphere is wound CCW then changing front faces temporarily to GL_CW would do the job).
2. draw the the objects inside the sphere
3. draw the front faces of the sphere, i.e. outer side

For steps 1 and 3, blending has to be enabled.
Step 2 can be done before step 1 if the objects aren't transparent. Doing so would save some overdraw (hidden pixels of the inner side not drawn).

Ah, yes, "filled" in the sense of z-buffer values disallowing depth test passing ... good point.

Just for completion: Rendering transparent objects with z-buffer enabled requires the objects to be rendered in the order from back to front. In the given case the surface of the sphere has to be divided up into 2 shells, one behind and one in front of the contained objects. Lord_Evil's suggestion does that by rendering the sphere twice.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.