Results 1 to 2 of 2

Thread: Example: Section 8.1 (page 246), Follow the boucing ball

  1. #1
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    160

    Example: Section 8.1 (page 246), Follow the boucing ball

    [code=thinbasic]
    ' Example: Section 8.1 (page 246), Follow the boucing ball

    ' From Stan Blank's Book:
    ' "Python Programming in OpenGL
    ' "A Graphical Approach to Programming

    ' Converted by Michael Clease
    ' Last modified: February 27, 2010

    Uses "TBGL"

    ' Handle for our window
    Global hWnd As DWord
    Global Width As Long
    Global Height As Long
    Global anim As Long
    Global x,y As Double
    Global dx,dy As Double
    Global axrng As Double
    Dim Title As String Value "Follow the boucing ball - Press 'A' to start, 'S' to stop or 'Esc' to quit"
    '# Initial values of width And height
    width = 400
    height = 400
    '
    ' Create and show window
    hWnd = TBGL_CreateWindowEx(Title, Width, Height, 32, %TBGL_WS_WINDOWED )
    TBGL_ShowWindow

    Init()'Anim,x,y,dx,dy,axrng)
    ' Define "Callback" to be fired + that it should be fired each 40ms
    TBGL_BindPeriodicFunction(hWnd, "PlotFunc", 20)

    ' -- Once the command below is executed, further script execution
    ' -- is halted and only periodic calling of the bound function is performed
    TBGL_ProcessPeriodicFunction(hWnd)

    TBGL_DestroyWindow

    Sub Init() 'ByRef anim,ByRef x,ByRef y,ByRef dx,ByRef dy,axrng)
    '# initial position of the ball
    x = -0.67
    y = 0.34
    '# Direction "sign" of the ball's motion
    dx = 1
    dy = 1
    '# Window dimensions
    width = 500
    height = 500
    axrng = 1.0
    '# No animation To start
    anim = 0
    TBGL_Color(255,255,255)
    TBGL_BackColor(0,0,0)
    ' Resets status of all keys
    TBGL_ResetKeyState()
    End Sub

    Sub PlotFunc()
    ' -- Which window is calling?
    Local hWnd As DWord = TBGL_CallingWindow

    If Anim Then
    TBGL_ClearFrame
    TBGL_RenderMatrix2D(-axrng, -axrng, axrng, axrng)

    x += 0.005*dx
    y += 0.005*dy
    TBGL_PushMatrix
    TBGL_Translate(x,y,0)
    TBGL_Sphere(0.1)
    TBGL_PopMatrix
    If x >= (axrng - 0.1) Or x <= (-axrng + 0.1) Then dx = -1*dx
    If y >= (axrng - 0.1) Or y <= (-axrng + 0.1) Then dy = -1*dy

    TBGL_DrawFrame
    EndIf
    If TBGL_GetWindowKeyState(hWnd, %VK_A) Then Anim = 1
    If TBGL_GetWindowKeyState(hWnd, %VK_S) Then Anim = 0

    ' ESCAPE key to disable callback
    If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then
    TBGL_UnBindPeriodicFunction( hWnd )
    Exit Sub
    End If

    End Sub


    [/code]
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  2. #2
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,865
    Rep Power
    405

    Re: Example: Section 8.1 (page 246), Follow the boucing ball

    I was waiting for James Bond to walk into the white gun barrel. Nice! Thanks Michael.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

Similar Threads

  1. Example: Section 5.4 (page 41), Combined with Exercise 1 (page 44)
    By kryton9 in forum ThinBASIC programming in OpenGL/TBGL
    Replies: 2
    Last Post: 26-02-2010, 20:46

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
  •