PDA

View Full Version : Source code for partial cylinder.



billy
03-28-2001, 04:21 AM
Hello,

I would like OpenGL to have a function for drawing partial cylinders, like it has for partial disks (gluPartialDisk).

I was wondering if someone could provide source code to do this with vertex normals to look smooth.

Thanks,

Billy.

lavalamp
04-02-2001, 03:27 PM
Here's one way: (excerpt from VB 6 code)
This is most certainly not the most efficient way to do this, but it will work

Select Case m_lType
Case 0 'pie chart ---------------------------------------------------
ReDim vData(UBound(gData, 1)) As Variant
For lCollapse = 0 To UBound(gData, 1)
vData(lCollapse) = gData(lCollapse, 0)
Next
ReDim dSlice(0) As Double
'
'go thru all the data values and collapse any less than 2%
'
For lCollapse = 0 To UBound(vData)
dTotal = dTotal + vData(lCollapse)
Next
dSmall = dTotal * 0.02
For lCollapse = 0 To UBound(vData)
If vData(lCollapse) < dSmall Then
dSlice(0) = dSlice(0) + ((vData(lCollapse) / dTotal))
Else
ReDim Preserve dSlice(UBound(dSlice) + 1) As Double
dSlice(UBound(dSlice)) = (vData(lCollapse) / dTotal)
End If
Next
quo = gluNewQuadric
gluQuadricDrawStyle quo, GLU_FILL
gluQuadricNormals quo, GLU_SMOOTH
dStart = 0#
glDeleteLists 1, UBound(gLists) + 1
ReDim gLists(lCollapse) As Variant
lListId = glGenLists(lCollapse + 1)
For lCollapse = 0 To UBound(dSlice)
glNewList lListId, GL_COMPILE
glEnable GL_CLIP_PLANE0
glEnable GL_CLIP_PLANE1
vColors(0) = gMatColors(0, lCollapse)
vColors(1) = gMatColors(1, lCollapse)
vColors(2) = gMatColors(2, lCollapse)
dEnd = dStart + (dSlice(lCollapse) * 360#)
peq0(0) = Cos(ToRad(dStart)): peq0(1) = 0 - Sin(ToRad(dStart)): peq0(2) = 0#: peq0(3) = 0#
peq1(0) = 0 - Cos(ToRad(dEnd)): peq1(1) = Sin(ToRad(dEnd)): peq1(2) = 0#: peq1(3) = 0#
glClipPlane GL_CLIP_PLANE0, peq0(0)
glClipPlane GL_CLIP_PLANE1, peq1(0)
glMaterialfv GL_FRONT_AND_BACK, GL_AMBIENT, vColors(0)
gluCylinder quo, 1#, 1, Zthick, 24, 24
glTranslatef 0#, 0#, Zthick
gluPartialDisk quo, 0#, 1#, 24, 24, dStart, dEnd - dStart
glTranslatef 0#, 0#, -Zthick
gluPartialDisk quo, 0#, 1#, 24, 24, dStart, dEnd - dStart
dStart = dEnd
glDisable GL_CLIP_PLANE0
glDisable GL_CLIP_PLANE1
glEndList
gLists(lCollapse) = lListId
lListId = lListId + 1
Next
gluDeleteQuadric quo
gZdepth = Zthick * 2#

If anyone has efficiency suggestions, I'm all ears http://www.opengl.org/discussion_boards/ubb/smile.gif