Results 1 to 10 of 12

Thread: New program... parametric surfaces

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member sblank's Avatar
    Join Date
    Feb 2010
    Location
    Wayne City, Illinois
    Posts
    80
    Rep Power
    23

    New program... parametric surfaces

    Just a new program using some raw OpenGL and Petr's great example code. This program plots a crosscap using 3 parametric equations.

    My intention is to add trackball mouse interaction at some point.

    n0 is the x function
    n1 is the y function
    n2 is the z function

    Stan
    Attached Files Attached Files

  2. #2
    thanks for your example, it is enriching the available examples about using classic OpenGL in thinbasic.
    in this link:
    http://psch.thinbasic.com/old/tbgl_lesson6.html
    download the example "Lesson 6 source code", it is a zip file; and inside it there are 3 code files one of them are interesting; it is Lesson6_TBGL_LightWithMouse.tbasic : whenever you move the mouse pointer (without clicking) the light move toward it. i think it is what needed
    the most important functions in the example is TBGL_MouseGetPosX, and TBGL_MouseGetPosY
    there is also a less significant example (in the context of your example) called TBGL_Demo19_MouseDemo.tbasic it is in "C:\thinBasic\SampleScripts\TBGL\Basic"
    i will try these after recovering from the flu and cold.
    best regards

  3. #3
    this my rude version adding some mouse code to sblank version
    i hope i will not get zero/100 , may be 5 enough, especially i have a cold symptoms ( as if i am better without )
    the figure rotate as the mouse pointer move, but can't make it continue rotation like it is intended. and also resorting to
    While TBGL_IsWindow(hWnd) ... wend
    ' Empty GUI script created on 11-16-2010 20:15:22 by  (ThinAIR)
    Uses "TBGL"    
    #INCLUDE Once "%APP_INCLUDEPATH%\thinbasic_gl.inc"
    #INCLUDE Once "%APP_INCLUDEPATH%\thinbasic_glu.inc"
     
    Global angle As Double
    Global dx, dy, theta, Alpha, n0, n1, n2,a,b As Double
    Global wd, ht, i, th, ta As Long
    Global mouseX, mouseY As Single
    wd = 600
    ht = 600
     
    Global hWnd As DWord
    Global x, y As DWord
    Function TBMain()
      Local hWnd      As DWord
      Local FrameRate As Double
     
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("Parametric Plots - press ESC to quit", wd, ht, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
      TBGL_ShowWindow 
     
      ' -- Initialize lighting
      TBGL_UseLighting(%TRUE)
      TBGL_UseLightSource(%GL_LIGHT0, %TRUE)
      While TBGL_IsWindow(hWnd)
       TBGL_ResetKeyState()
       mouseX = TBGL_MouseGetPosX
       mouseY = TBGL_MouseGetPosY
       dx=mouseX: dy=mouseY 
       funRender()
       'dx += 10
       'dy += 10
       If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While    
      Wend
     TBGL_DestroyWindow 
     End Function 
    ' -- Do any calculations here
    Function funIdle( hWnd As DWord, frameRate As Double )
     
      dx += 10
      dy += 10
     
    End Function
    ' -- Handle input here
    Function funInput( hWnd As DWord, frameRate As Double )
      If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then 
        TBGL_UnBindPeriodicFunction(hWnd)
        Exit Function
      End If
    End Function
     
    Function drawtor() 
     glBegin(%GL_TRIANGLE_STRIP)
     For th = 0 To 360 Step 15
      For ta = 0 To 360 Step 15
       drawvert(th,ta)
       drawvert(th+12,ta)
     
      Next
     Next
     glEnd
    End Function
    Function drawvert (ByVal th As Integer, ByVal ta As Integer) 
     theta = th*0.01745
     Alpha = ta*0.01745  
     
      a = 1.5
      n0 = 0.5*a*Sin(alpha)*Sin(2*theta)
      n1 = a*Sin(2*alpha)*Sin(theta)*Sin(theta)
      n2 = a*Cos(2*alpha)*Sin(theta)*Sin(theta)
     
     glColor3f(n0,Sin(n1),Cos(n2))
     glVertex3f(n0,n1,n2)
    End Function 
     
    Function funRender()
      Dim hWnd As DWord = TBGL_CallingWindow
      Dim FrameRate As Double
     
      frameRate = TBGL_GetFrameRate    
     
      ' -- Process input
      funIdle( hWnd, FrameRate)
     
      ' -- Process calculations
      funInput( hWnd, FrameRate )
     
      FrameRate = TBGL_GetFrameRate
      TBGL_ClearFrame 
        TBGL_Camera(3, 3, 3, 0, 0, 0)
        TBGL_GetWindowClient( hWnd, x, y )      
     
        TBGL_Rotate(dx,0.0, 1.0, 0.0)
        TBGL_Rotate(dy, 1.0, 0.0, 0.0)
     
        TBGL_SetLightParameter(%GL_LIGHT0, %TBGL_LIGHT_POSITION, 100, 100, 100, 1)
     
        drawtor()
      TBGL_DrawFrame   
    End Function
    

  4. #4
    Member sblank's Avatar
    Join Date
    Feb 2010
    Location
    Wayne City, Illinois
    Posts
    80
    Rep Power
    23
    That's a great addition Zak... thanks!

    I'll give you an "A" for the example

    I can use your mouse code I think. What I want to do is develop a trackball movement with inertia... continuous rotation in the direction of the mouse pointer. I'll keep working on it.

    Thanks again... I appreciate the feedback and the example!

    Stan

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Very nice examples,

    thanks a lot for them


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #6
    Member sblank's Avatar
    Join Date
    Feb 2010
    Location
    Wayne City, Illinois
    Posts
    80
    Rep Power
    23
    Hi Petr!

    This is fun... thinBasic runs the graphic very smoothly (using your TBGL module, of course ). Once I get the mouse tracking working as I want, then I'll try to optimize a bit.

    Stan

    Quote Originally Posted by Petr Schreiber View Post
    Very nice examples,

    thanks a lot for them


    Petr

Similar Threads

  1. Example: Section 4.3 (page 28), My First OGL Program (second program)
    By kryton9 in forum ThinBASIC programming in OpenGL/TBGL
    Replies: 2
    Last Post: 26-02-2010, 06:01
  2. Invoking One .tbasic Program From Another .tbasic Program
    By gungadout in forum thinBasic General
    Replies: 46
    Last Post: 23-11-2009, 12:01

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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