Jump to content
  • Advertisement

Archived

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

PartialDisk with height, how?

This topic is 5596 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

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.

Share this post


Link to post
Share on other sites
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.0f
void 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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!