Click here to Skip to main content
11,576,354 members (62,888 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB OpenGL
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 3-Dec-09 9:59am
Death8U255
Edited 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 285
1 F-ES Sitecore 140
2 Abhinav S 115
3 Lucifier Rocks 105
4 OriginalGriff 105
0 OriginalGriff 705
1 Sergey Alexandrovich Kryukov 630
2 Abhinav S 438
3 F-ES Sitecore 410
4 Suvendu Shekhar Giri 365


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100