Results 1 to 7 of 7

Thread: How to program the mouse functions

  1. #1
    Junior Member TBProgramer52's Avatar
    Join Date
    Mar 2010
    Location
    Saint George, Ut
    Posts
    24
    Rep Power
    17

    Thumbs up How to program the mouse functions

    This post is for everyone interested, I was wondering how to program the mouse function in all the demo that is installed along with the ThinBasic? Meant all the sample programs within ThinBasic. Just wondering though! To Petr, nice work on the demos you have created! I really enjoyed them alot!

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736
    Hi TBProgramer52,

    thanks for the kind words!

    I am not sure I understand your question fully - there are multiple levels of functionality for handling mouse input in ThinBASIC.

    When working with UI module:
    • Win_GetCursorPos allows retrieving position of mouse in window
    • You can catch %WM_MOUSEMOVE, %WM_LBUTTONDOWN, %WM_LBUTTONUP, %WM_RBUTTONDOWN, %WM_RBUTTONUP and other events allow detecting mouse activity

    When working with TBGL module, you can pick some alternative functions as well:
    • TBGL_MouseGetPosX, TBGL_MouseGetPosY allow retrieving mouse position
    • TBGL_MouseGetLButton, TBGL_MouseGetMButton, TBGL_MouseGetRButton return non zero value in case the apropriate mouse button is pressed
      (TBGL_GetWindowKeyOnce(hWnd, %VK_LBUTTON) and others can be used for similar purpose)
    • TBGL_MouseGetWheelDelta returns mousewheel delta
    • TBGL_GetPixelInfo(TBGL_MouseGetPosX, TBGL_MouseGetPosY, ... ) allows picking 3D coordinate or color from screen


    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

  3. #3
    Junior Member TBProgramer52's Avatar
    Join Date
    Mar 2010
    Location
    Saint George, Ut
    Posts
    24
    Rep Power
    17

    Talking To Petr, What I meant to say is ....

    Hello Petr,
    What I meant to say is to replace the keyboard functions with in the code, to actually transform from keyboard into a mouse format. To actually control the object with a mouse instead of keyboard (arrows keys). Understand now Petr. I'm sorry I didn't make myself clear on this subject. Or maybe demo on how to use the mouse within ThinBasic.

    from TBProgramer52



  4. #4
    Senior Member zak's Avatar
    Join Date
    Dec 2008
    Posts
    637
    Rep Power
    83
    here are some examples i have found about using the mouse
    some examples in the thinbasic distribution
    1-DragnDropDemo.tbasic in "C:\thinBasic\SampleScripts\UI\Canvas":
    you can move the circle by left mouse button or Right mouse button or the middle button.
    2-TBGL_2D_Sprites_CheckMouse.tbasic in "C:\thinBasic\SampleScripts\TBGL\Sprites":
    you can rotate the sprite to the right by clicking left mouse button, and to the right by right click
    3-TBGL_Demo19_MouseDemo.tbasic in "C:\thinBasic\SampleScripts\TBGL\Basic":
    you can move the balls with mouse.
    4- the following example "demo_of_0192.TBASIC" in the TBGL Bonus Pack Version: 1.6.0.10 downloaded from here http://www.thinbasic.com/index.php?o...tegory&catid=5 IN FOLDER "TBGL_BonusPack_1_6_0_10\GUIandText\Selection" :
    you can select a ball and place a toy over it.
    mouse_SELECT.JPG
    5- FunctionDesigner3D.tbasic‎ by Petr in this thread http://www.thinbasic.com/community/s...inally-from-C) you can rotate the figure by mouse in any direction.
    functionDes.JPG
    6- the next example (the original code by sblank ), move the mouse in any direction and the figure will move according to that.
    Attached Files Attached Files

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736
    Hello,

    here is one simple example on how to replace arrow keys movement with mouse movement:
    • left mouse button = forward
    • right mouse button = backward
    • moving mouse left/right = turning left/right


    '---Load needed modules
    Uses "TBGL"    
    
    Begin Const
      
      ' -- Scene IDs 
      %sScene = 1
      
      ' -- Entity IDs
      %eCamera = 1
      %eGrid  
      
    End Const
    
    Function TBMain()
      Dim hWnd As DWord
      
      '---Creates OpenGL window and returns handle
      hWnd = TBGL_CreateWindowEx("Moving using mouse - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED )
      '---Shows TBGL window
      TBGL_ShowWindow
      
      ' -- First we will create world as place to contain entities
      TBGL_SceneCreate(%sScene) 
      
      ' -- Our world will have two entities 
                                      
      ' .. Camera
      TBGL_EntityCreateCamera(%sScene, %eCamera)
      TBGL_EntitySetPos      (%sScene, %eCamera, 0.0, 1.7, 0.0 )
    
      ' .. Grid
      TBGL_EntityCreateDLSlot(%sScene, %eGrid, 0, CreateGridAsDList() )
      
      Dim FrameRate As Double
      Dim Sheeps As Long
      
      Dim mouseCenterX, mouseCenterY As Long                   
                           
      '---Resets key status before checking
      TBGL_ResetKeyState()
      
      '---Main script loop
      While TBGL_IsWindow(hWnd)
      
        '---Script will run on different PCs so we must assure
        '---constant speed of movement by scaling movements relative to frame rate
        FrameRate = TBGL_GetFrameRate 
        
        ' -- Center cursors and retrieve its position
        TBGL_CenterCursor
        mouseCenterX = TBGL_MouseGetPosX
        mouseCenterY = TBGL_MouseGetPosY    
        
        Sleep 10
        
        '---Prepares clear frame
        TBGL_ClearFrame
      
          TBGL_SceneRender(%sScene)
      
        TBGL_DrawFrame                    ' Swaps the buffers - displays rendered image
      
        ' -- If mouse pressed, push the camera
        If TBGL_MouseGetLButton Then TBGL_EntityPush(%sScene, %eCamera, 0, 0,  5/FrameRate)     ' 5 meters/second
        If TBGL_MouseGetRButton Then TBGL_EntityPush(%sScene, %eCamera, 0, 0, -5/FrameRate)
      
        ' -- If mouse is not in center anymore, turn
        TBGL_EntityTurn(%sScene, %eCamera, 0,  -5*(TBGL_MouseGetPosX - mouseCenterX)/FrameRate, 0)
      
        If TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE) Then Exit While
      
      Wend
      
      '---Closes OpenGL window
      TBGL_DestroyWindow  
    End Function
    
    Function CreateGridAsDList() As Long  ' Returns to which display list we save
      local i, j as long
      
      tbgl_NewList 1
        '---Let's build a grid
        TBGL_BeginPoly %GL_LINES          ' Starts polygon definition based on 2 vertex lines
          TBGL_Color 0,255,0              ' Defines color
    
          For i = -20 To 20
            For j = -20 To 20
              TBGL_Vertex -20, 0,   j     ' Adds vertex
              TBGL_Vertex  20, 0,   j     ' Adds vertex
    
              TBGL_Vertex  i,  0, -20     ' Adds vertex
              TBGL_Vertex  i,  0,  20     ' Adds vertex
    
            Next
          Next
    
        TBGL_EndPoly   
      tbgl_EndList 
      
      function = 1 
    End Function
    
    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
    Junior Member TBProgramer52's Avatar
    Join Date
    Mar 2010
    Location
    Saint George, Ut
    Posts
    24
    Rep Power
    17

    Talking Many thanks!!!

    Thanks Petr,

    Thank for sharing that code, it helps a lot! Now I can use this code in all the examples, that would help me to practice to code correctly.

    From,
    TBProgramer52
    (Richard L. West)


  7. #7
    Hi Richard,

    I tried something like ;.. (attached).

    The mouse coordinates always are screen coordinates and not related with any window or any other object.



    best Rob
    Attached Files Attached Files

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

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

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