PartialDisk with height, how?

Started by
0 comments, last by bcheshire 21 years, 3 months ago
Hi, I''ve got to write a program which displays a 3D Pie chart, i was thinking about using lots of partial disks to make up the pie but they are flat. How can i extrude them in someway so they have a height??? Thanks, Brendan.
Advertisement
I was bored so I wrote a function to generate partial disks with height.

This probally is not the best way to do it, but it does work.


    #define SLICE_STEP Pi/36.0fvoid DrawSlice(float fStart, float fEnd, float fHeight, float fRadius){	if(fEnd > 2 * Pi)	{		fEnd = 2*Pi;	}	float fRads = fEnd - fStart;		//Draw bottom	glBegin(GL_TRIANGLE_FAN);	//Center	glVertex3f(0.0f, 0.0f, 0.0f);	//Pi/36 = 1 step per 5 degrees	for(float f = fStart; f <= fEnd; f+= SLICE_STEP)	{		glVertex3f(fRadius * cosf(f), 0.0f, fRadius * sinf(f));	}	glEnd();	//Draw top	glBegin(GL_TRIANGLE_FAN);	//Center	glVertex3f(0.0f, fHeight, 0.0f);	//Pi/36 = 1 step per 5 degrees	for(f = fStart; f <= fEnd; f+= SLICE_STEP)	{		glVertex3f(fRadius * cosf(f), fHeight, fRadius * sinf(f));	}	glEnd();		//Draw sides	glBegin(GL_TRIANGLE_STRIP);	//Pie inner edge	glVertex3f(0.0f, 0.0f, 0.0f);	glVertex3f(0.0f, fHeight, 0.0f);	glVertex3f(fRadius * cosf(fStart), 0.0f, fRadius * sinf(fStart));	glVertex3f(fRadius * cosf(fStart), fHeight, fRadius * sinf(fStart));	//Curved edge	for(f = fStart; f <= fEnd; f+=SLICE_STEP)	{		glVertex3f(fRadius * cosf(f), 0.0f, fRadius * sinf(f));		glVertex3f(fRadius * cosf(f), fHeight, fRadius * sinf(f));	}//other side		glVertex3f(0.0f, 0.0f, 0.0f);	glVertex3f(0.0f, fHeight, 0.0f);		glEnd();}    


It takes a start and an end point (in radians), a height for the slice, and a radius. The center of the pie is always at 0,0,0.

SLICE_STEP is the size (in radians) of each step, the smaller the value, the more precise your slice is.

It draws the top and bottom as triangle fans, then draws the sides as a triangle strip.

Hope it helps, if you need more help, my e-mail is listed below.
-Evan

*EDIT* Here is a picture of a sample pie, drawn twice, once for solid, once for wireframe.



--------------------------

Those who dance are considered insane by those who cannot hear the music.

Focus On: 3-D Models


Evan Pipho (evan@codershq.com)


[edited by - terminate on January 23, 2003 8:39:44 PM]
Those who dance are considered insane by those who cannot hear the music.

This topic is closed to new replies.

Advertisement