• ### What is your GameDev Story?

#### Archived

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.

## 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 on other sites
Try a combination of scaling and a glut sphere...

##### 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;	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);	for(float t = -Pi/2; t <= (Pi/2)+.0001; t += tStep)	{		glBegin(GL_TRIANGLE_STRIP);		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));		}		glEnd();	}}

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.
-Evan

*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]

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
634151
• Total Posts
3015826
×