Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Source code for partial cylinder.

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jul 2000
    Location
    Canada
    Posts
    173

    Source code for partial cylinder.

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

  2. #2
    Junior Member Newbie
    Join Date
    Apr 2001
    Location
    Aurora, CO, USA
    Posts
    7

    Re: Source code for partial cylinder.

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •