Results 1 to 10 of 11

Thread: searching for Curves and Surfaces in the space

Hybrid View

  1. #1

    searching for Curves and Surfaces in the space

    suppose someone tell you to plot this equation
    Pow(x,4) + Pow(y,4) + Pow(z,4) - Pow(x*x + y*y + z*z,2) + 3 * (x*x + y*y + z*z) = 0
    and you don't have any clue how to solve it first such as saying:
    z = f(x,y) , so how to plot it ?
    there is a plan: is to search the points in space one by one in which this equation is approximately true such as:
    If k <= 0.1 And k >= -0.1 Then ...
    k is the value of the equation.
    change it to:
    If k <= 0.5 And k >= -0.5 Then
    and you get a thicker surface curve with more points.

    now if we tried the above equation but replacing Pow to '^' (uncomment line 178 ) then the time is twice than if use Pow. this is not important issue since we can use the speedier version.
    try equation in line 175:
    k = Sin(x*y)+Sin(y*z)+Sin(z*x)
    it is ineresting
    in line 217 : TBGL_PointSize 2 : make it 1 or 3 as necessary
    change the range in line 162 as the plotting needed
    this is an experimental mathematics
    i have used the Entity System to position and rotate and look at using Entity system examples by Petr ,2009
    also using Oxygen module to speed the calculations
    you may wait from 6 to 30 seconds for every graphics since we check every point in the space within the range.
    Click image for larger version. 

Name:	surface.JPG 
Views:	7 
Size:	26.6 KB 
ID:	9743Click image for larger version. 

Name:	surface1.JPG 
Views:	9 
Size:	19.8 KB 
ID:	9744
    'Experimental Mathematics                             =
    '===============================================================================
    
    Uses "TBGL" , "Math" , "Oxygen"
    #Include Once "%APP_INCLUDEPATH%\thinbasic_gl.inc"
    #Include Once "%APP_INCLUDEPATH%\thinbasic_glu.inc" 
    
    BEGIN CONST
      ' -- Scene IDs
      %sScene  = 1
     
      ' -- Entity IDs 
      %eCamera = 1
      
      %eContour       
      %eLight
      %texOne
      %lMyPoints       
    End Const
    
    Type Point3D
      x As Single
      y As Single
      z As Single
      red As Single
      green As Single
      blue As Single
      tu As Single
      tv As Single
    End Type
       
    Global Nb As DWord = 2000000 '401880 '8120601
    Global x, y, z,zz As Single
    Global FrameRate As Long
    Global Vertex(Nb) As Point3D ' single
    Global total As Long 
    'Global ColorA(Nb)  As TBGL_TRGB      ' Byte
      
    
    FUNCTION TBMAIN()
      LOCAL hWnd As DWORD
      Global FrameRate As Double
      Global ang, earthX, earthZ, OrbitRadius As Single
      Global flag, mask As Long
      flag = 1 : mask = 1
      OrbitRadius = 2.5
      
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("press Space to toggle the camera position , press 'M' to set a mask , 'R' reset mask to default ", 800, 600, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
      TBGL_ShowWindow 
      
      ' -- Create scene
      TBGL_SceneCreate(%sScene)
    
      ' -- Create basic entities
      ' -- Create camera to look from 0, 8, 20 to 0, 0, 0 
      TBGL_EntityCreateCamera(%sScene, %eCamera)
        TBGL_EntitySetPos(%sScene, %eCamera, 0, 8, 20)
        TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)  
      ' -- Create point light  
      TBGL_EntityCreateLight(%sScene, %eLight)
      TBGL_EntitySetPos(%sScene, %eLight, 10, 20, 50)
      
      ' -- Create something to look at 
      '---Start time
      Dim T0  As Double = Timer
      CreatePointsList()
      Dim T1  As Double = Timer
      MsgBox(0, "Total time to create points List "  & Format$(T1 - T0, "#0.00") & " secs" & " ...   number of points = " & Str$(total))
      
      TBGL_EntityCreateDLSlot(%sScene, %eContour, 0, %lMyPoints) 
        
        TBGL_EntitySetColor(%sScene, %eContour, 255, 255, 255)
            
      ' -- Resets status of all keys 
      TBGL_ResetKeyState() 
      TBGL_EntitySetTexture(%sScene, %eContour, %texOne )
      'TBGL_LoadTexture APP_Path+"SampleScripts\TBGL\GBuffers\Textures\Bricks.bmp", %texOne, %TBGL_TEX_MIPMAP
      TBGL_LoadTexture APP_Path+"SampleScripts\UI\Dialogs\Images\frogduck.bmp", %texOne, %TBGL_TEX_MIPMAP        
      
      ' -- Main loop
      While TBGL_IsWindow(hWnd) 
        FrameRate = TBGL_GetFrameRate
        TBGL_SetWindowTitle( hWnd, "FPS = "+Str$(FrameRate)+"  press Space to toggle the camera position , press 'M' to set a mask , 'R' reset mask to default ")
        TBGL_ClearFrame 
        If TBGL_GetWindowKeyOnce( hWnd, %VK_SPACE) Then
        If flag = 1 Then
         TBGL_EntitySetPos(%sScene, %eCamera, 0, 25, 0.1)
         TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)
         
         flag * -1  
         Else 
         TBGL_EntitySetPos(%sScene, %eCamera, 0, 12, 20)
         TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0) 
         flag * -1  
        End If
        End If
        
        If TBGL_GetWindowKeyOnce( hWnd, %VK_M) Then 
          If mask = 1 Then
            TBGL_EntitySetColorMask(%sScene, %eCamera, %TBGL_RED  )
            mask * -1
            Else
            TBGL_EntitySetColorMask(%sScene, %eCamera, %TBGL_GREEN  )
            mask * -1
          End If
        End If
         
         If TBGL_GetWindowKeyOnce( hWnd, %VK_R) Then
           TBGL_EntitySetColorMask(%sScene, %eCamera, %TBGL_DEFAULT)
         End If
         
         TBGL_EntitySetRot(%sScene, %eContour, 0, GetTickCount/40, 0)
          
        TBGL_SceneRender(%sScene)
       
        TBGL_DrawFrame 
     
        ' -- ESCAPE key to exit application
        If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While 
      
      Wend 
    
      TBGL_DestroyWindow
    END FUNCTION
            
    
    '==================================
    Sub CreatePointsList() 
    
      String src = " 
      ' -- Re-declare types
        
      Type Point3D
      x As Single
      y As Single
      z As Single
      red As Single
      green As Single
      blue As Single
      tu As Single
      tv As Single
      End Type
      
      dim oVertex(2000000) At #Vertex As Point3D
      dim oTexA(2000000)At #TexA As Point3D
      
      dim N At #total As long
      'dim oColorA(2000000) At #ColorA As TBGL_TRGB
      Long a, b, c, Nb
      Single x, z, k, xMin, yMin, zMin, xMax, yMax, zMax, range, step1
        
      Long NbX
      Long NbZ
      Long NbY
      nbx = 300
      nby = 300
      nbz = 300
      
      'xMin = -2 : yMin = -2: zMin = -2 : xMax = 2: yMax = 2 : zMax = 2
      'xMin = -3 : yMin = -3: zMin = -3 : xMax = 3: yMax = 3 : zMax = 3
      xMin = -4 : yMin = -4: zMin = -4 : xMax = 4: yMax = 4 : zMax = 4
      'xMin = -5 : yMin = -5: zMin = -5 : xMax = 5: yMax = 5 : zMax = 5
    
      range = xMax - xMin
      step1 = range / NbX
      x = xMin: z = zMin : y = yMin
      N = 0  
      For c = 0 To NbY
         For b=0 To NbZ
        
        For a=0 To NbX
          
          'k = 320*(((x*x + (9*y*y)/4 +z*z -1)^3) - x*x*z*z*z - (9*y*y*z*z*z)/80)
          'k = Sin(x*y)+Sin(y*z)+Sin(z*x)
          'k = x^3+y^2+z^2
           k = Pow(x,4) + Pow(y,4) + Pow(z,4) - Pow(x*x + y*y + z*z,2) + 3 * (x*x + y*y + z*z)
          'k = x^4 + y^4 + z^4 - (x^2 + y^2 + z^2)^2 + 3 * (x^2 + y^2 + z^2)
          
                 
          If k <= 0.1 And k >= -0.1 Then 
          'If k <= 0.5 And k >= -0.5 Then 
            N = N+1
            oVertex(N).x = x
            oVertex(N).y = y 
            oVertex(N).z = z
            oVertex(N).tu = a/NbX
            oVertex(N).tv = b/Nbz
                 
          End If
          x  = x + step1
          
        Next a
        x = xMin
        z = z + step1
        
      Next b
      x = xMin
      z = zMin
      y = y + step1
    Next c
    'print str N 
     terminate    
      "        
       
      ' -- Pass the source
      'O2_Asmo src
      o2_basic src
      If Len(o2_error) Then
        MsgBox 0, o2_error : Stop
      End If              
      ' -- Execute
      o2_exec
      
      Long N       
      TBGL_NewList %lMyPoints
        TBGL_PointSize 2
        TBGL_UseLighting %FALSE
        
        TBGL_BeginPoly %GL_POINTS
         For N=1 To Nb
           glTexCoord2f(Vertex(N).tu, Vertex(N).tv)
           glVertex3f(Vertex(N).x,Vertex(N).y,Vertex(N).z)
         Next   
       
        TBGL_EndPoly
        TBGL_EndList
        TBGL_UseLighting %TRUE
    End Sub
    
    Last edited by primo; 12-10-2017 at 17:50.

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,171
    Blog Entries
    2
    Rep Power
    10
    Wow

    My math is so poor but my eyes remains always so fascinated looking at what math can do.
    Thanks so much
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,171
    Blog Entries
    2
    Rep Power
    10
    Sorry if I ask but it would be great to have arrow keys navigate inside the object moving in 3D

    Click image for larger version. 

Name:	Curves.jpg 
Views:	13 
Size:	124.2 KB 
ID:	9745
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  4. #4
    yes Eros , here is the navigation with the camera with arrows,
    up/down: go inside/outside
    left/right
    A/Z: up/down
    there is still the camera rotation with the Mouse+keys
    now i think the while/wend is better than For/Next since we can decide how much points we need, will look at later.
    in fact i like to Generate the Average 3D Face:
    http://www1.cs.columbia.edu/~jebara/...IS/node48.html
    there is a matrix , who have any idea will be great.
    'Experimental Mathematics                             =
    '===============================================================================
     
    Uses "TBGL" , "Math" , "Oxygen"
    #Include Once "%APP_INCLUDEPATH%\thinbasic_gl.inc"
    #Include Once "%APP_INCLUDEPATH%\thinbasic_glu.inc" 
     
    Begin Const
      ' -- Scene IDs
      %sScene  = 1
      
      ' -- Entity IDs 
      %eCamera = 1
       
      %eContour       
      %eLight
      %texOne
      %lMyPoints       
    End Const
     
    Type Point3D
      x As Single
      y As Single
      z As Single
      red As Single
      green As Single
      blue As Single
      tu As Single
      tv As Single
    End Type
        
    Global Nb As DWord = 2000000 '401880 '8120601
    Global x, y, z, xx, yy,zz As Single
    Global FrameRate As Long
    Global Vertex(Nb) As Point3D ' single
    Global total As Long
    'Global ColorA(Nb)  As TBGL_TRGB      ' Byte
       
     
    Function TBMain()
      Local hWnd As DWord
      Global FrameRate As Double
      Global ang, earthX, earthZ, OrbitRadius As Single
      Global flag, mask As Long
      flag = 1 : mask = 1
      OrbitRadius = 2.5
       
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("press Space to toggle the camera position , press 'M' to set a mask , 'R' reset mask to default ", 800, 600, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
      TBGL_ShowWindow
       
      ' -- Create scene
      TBGL_SceneCreate(%sScene)
     
      ' -- Create basic entities
      ' -- Create camera to look from 0, 8, 20 to 0, 0, 0 
      TBGL_EntityCreateCamera(%sScene, %eCamera)
        TBGL_EntitySetPos(%sScene, %eCamera, 0, 8, 20)
        TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)  
      ' -- Create point light  
      TBGL_EntityCreateLight(%sScene, %eLight)
      TBGL_EntitySetPos(%sScene, %eLight, 10, 20, 50)
       
      ' -- Create something to look at 
      '---Start time
      Dim T0  As Double = Timer
      CreatePointsList()
      Dim T1  As Double = Timer
      MsgBox(0, "Total time to create points List "  & Format$(T1 - T0, "#0.00") & " secs" & " ...   number of points = " & Str$(total))
       
      TBGL_EntityCreateDLSlot(%sScene, %eContour, 0, %lMyPoints) 
         
        TBGL_EntitySetColor(%sScene, %eContour, 255, 255, 255)
             
      ' -- Resets status of all keys 
      TBGL_ResetKeyState() 
      TBGL_EntitySetTexture(%sScene, %eContour, %texOne )
      'TBGL_LoadTexture APP_Path+"SampleScripts\TBGL\GBuffers\Textures\Bricks.bmp", %texOne, %TBGL_TEX_MIPMAP
      TBGL_LoadTexture APP_Path+"SampleScripts\UI\Dialogs\Images\frogduck.bmp", %texOne, %TBGL_TEX_MIPMAP        
       
      ' -- Main loop
      While TBGL_IsWindow(hWnd) 
        FrameRate = TBGL_GetFrameRate
        TBGL_SetWindowTitle( hWnd, "FPS = "+Str$(FrameRate)+"  press Space to toggle the camera position , press 'M' to set a mask , 'R' reset mask to default ")
        TBGL_ClearFrame
        If TBGL_GetWindowKeyOnce( hWnd, %VK_SPACE) Then
        If flag = 1 Then
         TBGL_EntitySetPos(%sScene, %eCamera, 0, 25, 0.1)
         TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)
          
         flag * -1  
         Else
         TBGL_EntitySetPos(%sScene, %eCamera, 0, 12, 20)
         TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0) 
         flag * -1  
        End If
        End If
         
        If TBGL_GetWindowKeyOnce( hWnd, %VK_M) Then
          If mask = 1 Then
            TBGL_EntitySetColorMask(%sScene, %eCamera, %TBGL_RED  )
            mask * -1
            Else
            TBGL_EntitySetColorMask(%sScene, %eCamera, %TBGL_GREEN  )
            mask * -1
          End If
        End If
          
         If TBGL_GetWindowKeyOnce( hWnd, %VK_R) Then
           TBGL_EntitySetColorMask(%sScene, %eCamera, %TBGL_DEFAULT)
         End If
         
         If TBGL_GetWindowKeyState( hWnd, %VK_UP ) Then
           TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz) 
           zz-0.1
           TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
           ElseIf TBGL_GetWindowKeyState( hWnd, %VK_DOWN ) Then
           TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz) 
           zz+0.1
           TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
           
           ElseIf TBGL_GetWindowKeyState( hWnd, %VK_Z ) Then
           TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz) 
           yy+0.1
           TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
           ElseIf TBGL_GetWindowKeyState( hWnd, %VK_A ) Then
           TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz) 
           yy-0.1
           TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
           
           ElseIf TBGL_GetWindowKeyState( hWnd, %VK_RIGHT ) Then
           TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz) 
           xx-0.1
           TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
           ElseIf TBGL_GetWindowKeyState( hWnd, %VK_LEFT ) Then
           TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz) 
           xx+0.1
           TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
           
         End If
                  
     
         TBGL_EntitySetRot(%sScene, %eContour, 0, GetTickCount/40, 0)
           
        TBGL_SceneRender(%sScene)
        
        TBGL_DrawFrame
      
        ' -- ESCAPE key to exit application
        If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
       
      Wend
     
      TBGL_DestroyWindow
    End Function
             
     
    '==================================
    Sub CreatePointsList() 
     
      String src = " 
      ' -- Re-declare types
         
      Type Point3D
      x As Single
      y As Single
      z As Single
      red As Single
      green As Single
      blue As Single
      tu As Single
      tv As Single
      End Type
       
      dim oVertex(2000000) At #Vertex As Point3D
         
      dim N At #total As long
      'dim oColorA(2000000) At #ColorA As TBGL_TRGB
      Long a, b, c, Nb
      Single x, z, k, xMin, yMin, zMin, xMax, yMax, zMax, range, step1
         
      Long NbX
      Long NbZ
      Long NbY
      nbx = 300
      nby = 300
      nbz = 300
       
      'xMin = -2 : yMin = -2: zMin = -2 : xMax = 2: yMax = 2 : zMax = 2
      'xMin = -3 : yMin = -3: zMin = -3 : xMax = 3: yMax = 3 : zMax = 3
      xMin = -4 : yMin = -4: zMin = -4 : xMax = 4: yMax = 4 : zMax = 4
      'xMin = -5 : yMin = -5: zMin = -5 : xMax = 5: yMax = 5 : zMax = 5
     
      range = xMax - xMin
      step1 = range / NbX
      x = xMin: z = zMin : y = yMin
      N = 0  
      For c = 0 To NbY
         For b=0 To NbZ
         
        For a=0 To NbX
           
          'k = 320*(((x*x + (9*y*y)/4 +z*z -1)^3) - x*x*z*z*z - (9*y*y*z*z*z)/80)
          k = Sin(x*y)+Sin(y*z)+Sin(z*x)
          'k = x^3+y^2+z^2
          'k = Pow(x,4) + Pow(y,4) + Pow(z,4) - Pow(x*x + y*y + z*z,2) + 3 * (x*x + y*y + z*z)
          'k = x^4 + y^4 + z^4 - (x^2 + y^2 + z^2)^2 + 3 * (x^2 + y^2 + z^2)
           
                  
          If k <= 0.1 And k >= -0.1 Then
          'If k <= 0.5 And k >= -0.5 Then 
            N = N+1
            oVertex(N).x = x
            oVertex(N).y = y 
            oVertex(N).z = z
            oVertex(N).tu = a/NbX
            oVertex(N).tv = b/Nbz
                  
          End If
          x  = x + step1
           
        Next a
        x = xMin
        z = z + step1
         
      Next b
      x = xMin
      z = zMin
      y = y + step1
    Next c
    'print str N 
     terminate    
      "        
        
      ' -- Pass the source
      'O2_Asmo src
      o2_basic src
      If Len(o2_error) Then
        MsgBox 0, o2_error : Stop
      End If             
      ' -- Execute
      o2_exec
       
      Long N       
      TBGL_NewList %lMyPoints
        TBGL_PointSize 2
        TBGL_UseLighting %FALSE
         
        TBGL_BeginPoly %GL_POINTS
         For N=1 To Nb
           glTexCoord2f(Vertex(N).tu, Vertex(N).tv)
           glVertex3f(Vertex(N).x,Vertex(N).y,Vertex(N).z)
         Next  
        
        TBGL_EndPoly
        TBGL_EndList
        TBGL_UseLighting %TRUE
    End Sub
    
    Last edited by primo; 13-10-2017 at 08:19.

  5. #5
    this demo using a thinbasic without calling Oxygen, it display the progress in the taskbar, the speed depends on several factors
    my neighbor said: you want my son to be lazy and not solving the equations by himself but by crawling like a rabbit sniffing if the equation correct here and there or not !! and he suspect that this is not a correct program and producing a fake shapes , but i show him an equation in a trusted site , the mathematica site, here: https://www.wolfram.com/mathematica/...ojections.html
    the first graphics show this equation:
    k = x^6 - 5* x^4* y* z + 3* x^4* y^2 + 10* x^2* y^3* z + 3* x^2* y^4 - y^5* z + y^6 + z^6 - 1
    it produce the same graphics as this program, just uncomment line 159 (note we have moved the +1 from right to left -1)
    interestingly thinbasic math '^' is speedier than Pow by two seconds (uncomment line 158 )
    don't forget to comment the unused equations


    Uses "TBGL" , "Math"
    #Include Once "%APP_INCLUDEPATH%\thinbasic_gl.inc"
    #Include Once "%APP_INCLUDEPATH%\thinbasic_glu.inc" 
    
    BEGIN CONST
      ' -- Scene IDs
      %sScene  = 1
     
      ' -- Entity IDs 
      %eCamera = 1
      
      %eContour       
     
      %quat
      %lMyPoints
      %texOne       
    END CONST 
    
    Global x, y, z, xx, yy,zz As Single
    Global FrameRate, total As Long
    
    
    FUNCTION TBMAIN()
      Global hWnd As DWord
      Global FrameRate As Double
      Global flag As Long
      flag = 1 
      
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("press Space to toggle the camera position , press 'M' to set a mask , 'R' reset mask to default ", 800, 600, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
      TBGL_ShowWindow 
    
      ' -- Create scene
      TBGL_SceneCreate(%sScene)
    
      ' -- Create basic entities
      ' -- Create camera to look from 0, 5, 15 to 0, 0, 0 
      TBGL_EntityCreateCamera(%sScene, %eCamera)
        TBGL_EntitySetPos(%sScene, %eCamera, 0, 5, 15)
        TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)  
     
      Dim T0  As Double = Timer
      ' -- Create something to look at
      CreatePointsList()
      Dim T1  As Double = Timer
      MsgBox(0, "Total time to create points List "  & Format$(T1 - T0, "#0.00") & " secs" & " ...   number of points = " & Str$(total))
      
      TBGL_EntityCreateDLSlot(%sScene, %eContour, 0, %lMyPoints) 
      
        TBGL_EntitySetColor(%sScene, %eContour, 255, 255, 255)
        TBGL_EntitySetPos(%sScene, %eContour, 0, 0, 0)
     
        
      ' -- Resets status of all keys 
      TBGL_ResetKeyState() 
      TBGL_EntitySetTexture(%sScene, %eContour, %texOne )
      TBGL_LoadTexture APP_Path+"SampleScripts\TBGL\GBuffers\Textures\Bricks.bmp", %texOne, %TBGL_TEX_MIPMAP
      'TBGL_LoadTexture APP_Path+"SampleScripts\UI\Dialogs\Images\frogduck.bmp", %texOne, %TBGL_TEX_MIPMAP        
      'TBGL_LoadTexture APP_SourcePath+"Marble-Wood.bmp", %texOne, %TBGL_TEX_MIPMAP
      
      'TBGL_PolygonLook %GL_LINE
      ' -- Main loop
      While TBGL_IsWindow(hWnd) 
        FrameRate = TBGL_GetFrameRate
        TBGL_SetWindowTitle( hWnd, "FPS = "+Str$(FrameRate)+"   use arrow keys and A/Z to navigate the scene")
        TBGL_ClearFrame 
        If TBGL_GetWindowKeyOnce( hWnd, %VK_SPACE) Then
        If flag = 1 Then
         TBGL_EntitySetPos(%sScene, %eCamera, 0, 25, 0.1)
         TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)
         flag * -1  
         Else 
         TBGL_EntitySetPos(%sScene, %eCamera, 0, 5, 15)
         TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0) 
         flag * -1  
        End If
        End If
        
        If TBGL_GetWindowKeyState( hWnd, %VK_UP ) Then
           TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz) 
           zz-0.2
           TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
           ElseIf TBGL_GetWindowKeyState( hWnd, %VK_DOWN ) Then
           TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz) 
           zz+0.2
           TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
            
           ElseIf TBGL_GetWindowKeyState( hWnd, %VK_Z ) Then
           TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz) 
           yy+0.2
           TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
           ElseIf TBGL_GetWindowKeyState( hWnd, %VK_A ) Then
           TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz) 
           yy-0.2
           TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
            
           ElseIf TBGL_GetWindowKeyState( hWnd, %VK_RIGHT ) Then
           TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz) 
           xx-0.2
           TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
           ElseIf TBGL_GetWindowKeyState( hWnd, %VK_LEFT ) Then
           TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz) 
           xx+0.2
           TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
            
         End If
         
        TBGL_EntitySetRot(%sScene, %eContour, 90, GetTickCount/40, 0) 
        TBGL_SceneRender(%sScene)
       
        TBGL_DrawFrame 
     
        ' -- ESCAPE key to exit application
        If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While 
      
      Wend 
    
      TBGL_DestroyWindow
    END FUNCTION
            
    ' -- Render procedure  
    
    '==================================
    Sub CreatePointsList() 
    Dim zz As Single 
    String plotted
    Long a, b, c, Nb
      Single x, z, k, xMin, yMin, zMin, xMax, yMax, zMax, range, step1
        
      Long NbX=150
      Long NbZ=150
      Long NbY=150
      
      'xMin = -2 : yMin = -2: zMin = -2 : xMax = 2: yMax = 2 : zMax = 2
      xMin = -3 : yMin = -3: zMin = -3 : xMax = 3: yMax = 3 : zMax = 3
      'xMin = -5 : yMin = -5: zMin = -5 : xMax = 5: yMax = 5 : zMax = 5
      'xMin = -1.5 : yMin = -1.5: zMin = -1.5 : xMax = 1.5: yMax = 1.5 : zMax = 1.5
    
      range = xMax - xMin
      step1 = range / NbX
      x = xMin: z = zMin : y = yMin
       
      TBGL_NewList %lMyPoints
        TBGL_PointSize 2
        TBGL_UseLighting %FALSE
        
        TBGL_BeginPoly %GL_POINTS
     For c = 0 To NbY
      For b=0 To NbZ
        
        For a=0 To NbX
          
          'k = 320*(((x*x + (9*y*y)/4 +z*z -1)^3) - x*x*z*z*z - (9*y*y*z*z*z)/80) 'Heart
          'k = Pow(x,4) + Pow(y,4) + Pow(z,4) - Pow(x*x + y*y + z*z,2) + 3 * (x*x + y*y + z*z)
          'k = Sin(x*y)+Sin(y*z)+Sin(z*x)
           k =  x^2 + y^2 - z^2 -1
          'k = -y +0.7/Log(x^2+z^2)+.6  'dome
          'k = Pow(x,6) - 5* Pow(x,4)* y* z + 3* Pow(x,4)* Pow(y,2) + 10* Pow(x,2)* Pow(y,3)* z + 3* Pow(x,2)* Pow(y,4) - Pow(y,5)* z + Pow(y,6) + Pow(z,6) - 1
          'k = x^6 - 5* x^4* y* z + 3* x^4* y^2 + 10* x^2* y^3* z + 3* x^2* y^4 - y^5* z + y^6 + z^6 - 1
          'k = 4* z^4 + 9*(x^2 + y^2 - 4*z^2)-1 'Eight Solid
          
          'If k <= 0.05 And k >= -0.05 Then
          'If k <= 0.01 And k >= -0.01 Then
          'If k <= 0.1 And k >= -0.1 Then
          If k <= 0.2 And k >= -0.2 Then
            total+1 
            glTexCoord2f(a/NbX, b/Nbz)
            'glColor3f(0,1,0)
            glVertex3f(x,y,z)
                  
          End If
          x + step1
          
        Next a
           
        x = xMin
        z + step1
        
      Next b
      plotted = Str$(Int((c/nby)*100) )+" % "+" ..... please wait "
      TBGL_SetWindowTitle( hWnd, plotted)
      x = xMin
      z = zMin
      y + step1
    Next c
        TBGL_EndPoly
        TBGL_EndList
       
    End Sub
    
    Last edited by primo; 14-10-2017 at 12:03.

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,171
    Blog Entries
    2
    Rep Power
    10
    Great

    This is my preferred.

    Click image for larger version. 

Name:	Curves_NoOxygen_Preferred.jpg 
Views:	10 
Size:	135.7 KB 
ID:	9746
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Similar Threads

  1. Space bar echoes ?
    By RobbeK in forum TBGL General
    Replies: 11
    Last Post: 13-10-2013, 21:37
  2. Space-Plates
    By Charles Pegge in forum Shout Box Area
    Replies: 10
    Last Post: 28-02-2012, 12:21
  3. New program... parametric surfaces
    By sblank in forum WCHS thinBasic gaming forum
    Replies: 11
    Last Post: 22-11-2010, 20:37
  4. Replies: 1
    Last Post: 19-10-2010, 17:55
  5. searching for a word :)
    By Lionheart008 in forum thinAir General
    Replies: 1
    Last Post: 12-05-2009, 02:22

Posting Permissions

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