Advertisement Jump to content


This topic is now archived and is closed to further replies.


generating an ellipsoid in openGL

This topic is 5893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am working on a model editor for my game, and it would greatly simplify the whole thing if i could have the parts of the model start out as an ellipsoid (right now they start out as a block, which requires massive amounts of editing before it looks like a body part). unfortunately, i cannot seem to generate an ellipsoid properly (in fact, the closest i get is a big mess). does anyone know where i can find c/c++ code (or even psuedo-code) that will generate an ellipsoid out of triangles? i searched with google, but to no avail. i don''t even care if it is messy; i only need to generate a few ellipsoids, and i can save them as a template or something. thanks!

Share this post

Link to post
Share on other sites
Played around a bit, and came up with this little function.
Might not be the best, but it does seem to work.

I believe the parametric equ. of an ellisoid are

x : cos(t) * cos(s)
y : cos(t) * sin(s)
z : sin(t)

-Pi/2 <= t <= Pi/2
-Pi <= s <= Pi

The function I created is as follows:

void DrawEllipsoid(unsigned int uiStacks, unsigned int uiSlices, float fA, float fB, float fC)
float tStep = (Pi) / (float)uiSlices;
float sStep = (Pi) / (float)uiStacks;
for(float t = -Pi/2; t <= (Pi/2)+.0001; t += tStep)
for(float s = -Pi; s <= Pi+.0001; s += sStep)
glVertex3f(fA * cos(t) * cos(s), fB * cos(t) * sin(s), fC * sin(t));
glVertex3f(fA * cos(t+tStep) * cos(s), fB * cos(t+tStep) * sin(s), fC * sin(t+tStep));

This will draw an ellipsoid centered at the origin, and having the "radius" around X, Y, and Z given by fA, fB, and fC respectively.

Enjoy, and post any improvements you may have.

*EDIT* Note that it renders it in wireframe, removing the glPolygonMode call will render solid triangles.

[edited by - terminate on December 5, 2002 8:11:00 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!