Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create a 3D spring (helix, Spiral, ...) with a specific length and number of turns. I have the code written to create a spring using a line_strip, but I want to extend it to be an actual 3d surface (look like a real spring on a car). I figure this can be done using a quad_strip, but not sure what the best way to create this is.

Has someone done this?

  Gl.glPushMatrix()
        Gl.glColor4f(0, 0.28, 0.48, Alpha)

        Dim length As Double = glVectorRotation(point1, point2, False)
    
        Dim coils As Integer = 5
        Dim segs As Integer = 100
        Dim Radius As Single = 2.5
        Dim pitch As Double = length / coils
        Gl.glBegin(Gl.GL_LINE_STRIP)
        For icoil As Integer = 0 To coils
            For iseg As Integer = 0 To segs
                Dim theta As Single = CSng((2 * PI) / segs * iseg)
                Dim z As Single = CSng((icoil + (iseg / segs)) * pitch)
                Dim x As Single = CSng(Radius * Cos(theta))
                Dim y As Single = CSng(Radius * Sin(theta))
                If z > length Then Exit For 'z = CSng(length)
                Gl.glVertex3d(x, y, z)
            Next
        Next
        Gl.glEnd()
GL.glPopMatrix()
Posted
Updated 10-Feb-10 5:32am
v4

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900