The forum could be offline for 30-60 minutes in the very near future for maintenance (said 3pm Pacific). I was behind on getting this notice. I do apologize.
See more
See less

gbPoints - 3D Graphics Laboratory

  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    Hi Tim!

    Ok, let me take a try at it. I'm out most of the morning but will see what I can do after lunch.


    • #22
      Hi Tim!

      You're stretching my memory here! It's been some time since I worked with STL.

      The STL format is to define a set of points, then to define triangles, using 3 points each. Then draw the triangles in 3D.

      So from your list of 16 points you also have to define the actual triangles, each triangle being defined by 3 points.

      I'll try to make an example to see it it meets your goal.


      • #23
        Hey Tim!
        Here's a simple example of using ONLY points to create a 3D image. It does not use Z to color the points nor does it connect points with lines, but you should be able to add those.

        I just wanted to give a stand alone example of a 3D plot of points, which is rotatable. If the example had a hundred points it would look more impressive, but even with just 4 points it should show the kind of results you want without having to deal with triangles, which are required for STL objects.

        'Compilable Example:
        #Compile Exe
        #Dim All
        #Include ""
        Type PointX : X As Single : Y As Single : Z As Single : End Type
        %IDC_Graphic = 500 : %IDC_Timer = 501
        Global hDlg As Dword, P() As PointX
        Function PBMain()
           Dialog New Pixels, 0, "3D Objects",,,200,200, %WS_SysMenu Or %WS_ClipChildren, To hDlg
           Control Add Graphic, hDlg, %IDC_Graphic, "", 10,10,180,180
           Graphic Attach hDlg, %IDC_Graphic, ReDraw
           Graphic Color %Black, %rgb_Wheat
           Dialog Show Modal hDlg Call DlgProc
        End Function
        CallBack Function DlgProc() As Long
           Select Case Cb.Msg
              Case %WM_InitDialog
                 SetTimer(hDlg, %IDC_Timer, 40, %NULL)    'sends %WM_Timer to dialog callback
              Case %WM_Timer
                 Graphic Clear : RotateXYZ : DrawObject : Graphic ReDraw
           End Select
        End Function
        Sub RotateXYZ
           Local i As Long, NewX As Single, NewY As Single, NewZ As Single, Angle As Single
           Angle = 0.05
           For i = 1 To UBound(P)
              NewY = P(i).Y * Cos(Angle) - P(i).Z * Sin(Angle)    'X rotation
              NewZ = P(i).Y * Sin(Angle) + P(i).Z * Cos(Angle)    'X rotation
              P(i).Y = NewY : P(i).Z = NewZ
              NewX = P(i).Z * Sin(Angle) + P(i).X * Cos(Angle)    'Y rotation
              NewZ = P(i).Z * Cos(Angle) - P(i).X * Sin(Angle)    'Y rotation
              P(i).X = NewX : P(i).Z = NewZ
              NewX = P(i).X * Cos(Angle) - P(i).Y * Sin(Angle)    'Z rotation
              NewY = P(i).X * Sin(Angle) + P(i).Y * Cos(Angle)    'Z rotation
              P(i).X = NewX : P(i).Y = NewY
           Next i
        End Sub
        Sub DrawObject()
           Local i As Long, x1,x2,y1,y2, OffsetY, OffsetX As Long
           OffsetX = 90 : OffsetY = 90
           For i = 1 To UBound(P)
              Graphic Ellipse (p(i).x-5+OffsetX,p(i).y-5+OffSetY)-(p(i).x+5+OffsetX,p(i).y+5+OffsetY),, %Red, %Red
           Next i
        End Sub
        Sub LoadObject
           ReDim P(4)
           P(1).x = -30 : P(1).y = -30  : P(1).z = -30
           P(2).x = 30  : P(2).y = -30  : P(2).z = -30
           P(3).x = 0   : P(3).y = -30  : P(3).z = 30
           P(4).x = 0   : P(4).y = 0    : P(4).z = 30
        End Sub
        'Date: 03-10-2012


        • #24
          Thank you Gary, not bad


          • #25

            I would go with OpenGL. If you stick with OpenGL 1.0 or 2.0 it is a flat API and much easier to work with. Drawing STL files using OpenGL is pretty straightforward. I added STL file format support (both ascii and binary) to EZGUI 5.0 using OpenGL and the performance is amazing.

            Click image for larger version

Name:	EZ3Dview.png
Views:	85
Size:	154.1 KB
ID:	787459
            It can load and display a STL file with 2 million polygons (triangles) in just a couple of seconds on a typical mass market PC (no need for bleeding edge PC).

            Converting STL files triangle list to something you can draw using OpenGL is not that difficult. Search the forums for some OpenGL examples.
            Attached Files
            Chris Boss
            Computer Workshop
            Developer of "EZGUI"


            • #26
              Howdy, Chris!

              Yep, there's no doubt that OpenGL is a more powerful tool. But for a simple task such as Tim is pursuing, the learning curve of OpenGL is excessive and unnecessary. The simple 3D point plotting routine I gave him ought to be adequate for his needs.

              However, Tim,
              If you think you might want a more feature-laden solution, certainly you should consider Chris' suggestion.


              • #27
                Hallo Garry, in case you want see the advanced version of your programm for Inspiration, check my new video here:
                --Theo Gottwald
                76706 Dettenheim * Germany * [email protected]
                Joses Forum * Theo's Link Site *