Results 1 to 4 of 4

Thread: Spiky Dumples

  1. #1

    Spiky Dumples

    while searching an old 3d models i have found a strange *.obj model it looks like a spherical dumples with spikes. also it reminds me of the virus-19 but with two heads, don't scare please
    spiky.JPG
    i have converted it to *.M15 thinbasic model using TBGL_OBJ2M15 utility
    i have used Petr code in this thread http://www.thinbasic.com/community/s...otation-issues
    i have added only the coloring of vertices and adjusted the camera
    the code below needs the spikey.m15 model attached below together with the spikey.obj
    Uses "TBGL"
     
    Function TBMain()
      DWord hWnd = TBGL_CreateWindowEx("something spiky -  ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED)      
      TBGL_ShowWindow    
       
      'String modelFile = "simple_house.m15" 
      String modelFile = "spiky.m15"
      TBGL_m15LoadModel ModelFile, "", 1, 1, %TBGL_NORMAL_PRECISE
       
      Dim light As TBGL_TVECTOR3D           
      TBGL_UseLighting TRUE
      TBGL_UseLightSource %GL_LIGHT0, TRUE
      TBGL_SetupLightSource %GL_LIGHT0, light.x, light.y, light.z, 32, 32, 32, 255
       
      Dim center As TBGL_TVECTOR3D
      center = GetModelCenter(1) 
      'msgbox 0, str$(center)
      TBGL_ResetKeyState()  
      While TBGL_IsWindow(hWnd)     
         
        TBGL_ClearFrame            
             
          'TBGL_Camera 0, 20, 60,
           '           0,  0,  0
          TBGL_Camera 0, 0, 1.5,
                      0,  0,  0                
           
          TBGL_PushMatrix                                                   
            TBGL_Rotate GetTickCount/10, 0, 1, 0            ' -- Turn model
            TBGL_Translate -center.x, -center.y, -center.z  ' -- Center the rotation
       
            TBGL_m15DrawModel 1
          TBGL_PopMatrix
           
        TBGL_DrawFrame             
         
        If TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE ) Then Exit While
         
      Wend 
       
      TBGL_DestroyWindow
    End Function
     
    Function GetModelCenter( modelId As Long ) As String ' -- Hack to return TYPEs
     
      Long i, vtx
      Single x,y,z
      vtx = TBGL_m15GetModelVertexcount(modelId)
       
      Single minx, miny, minz =  99999   
      Single maxx, maxy, maxz = -99999
      Dim center As TBGL_TVECTOR3D
       
      For i = 1 To vtx
        TBGL_m15GetVertexXYZ(modelId, i, x, y, z)
        TBGL_m15SetVertexRGB( 1, i, 240,237,132)
        maxx = Max(x, maxx)
        minx = Min(x, minx)
         
        maxy = Max(y, maxy)
        miny = Min(y, miny)
       
        maxz = Max(z, maxz)
        minz = Min(z, minz)    
      Next
       
      center.x = minx + (maxx - minx) / 2.0
      center.y = miny + (maxy - miny) / 2.0
      center.z = minz + (maxz - minz) / 2.0 
       
      Return center
     
    End Function
    
    Attached Files Attached Files

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

    thank you very much for sharing such a day-to-day context related demo

    Maybe its my PC, maybe you can see it too, but the rotation feels a bit choppy, even at 60FPS.

    I workarounded it like this:
      single frameRate
      single angle        ' -- Storage for angle
      
      While TBGL_IsWindow(hWnd)     
    
    
        framerate = tbgl_getFrameRate ' -- Must be called each frame
        
        angle += 45/framerate         ' -- Accumulates angle
        angle = mod(angle, 360)       ' -- ...but never reaches overflow
          
        TBGL_ClearFrame
              
          TBGL_Camera 0, 0, 1.5,
                      0,  0,  0
            
          TBGL_PushMatrix
            TBGL_Rotate angle, 0, 1, 0            ' -- Turn model
    

    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
    Thanks Petr, in fact the rotation seems smooth for me in the first code. can't recognize the difference between the 2 versions, but it is may be because my poor vision especially in the right eye so my 3D visualization is not as should be.
    also the Graphics card have some rule. i have a good old desktop graphics card: Nvidia GeForce GT 640
    The framerate for the 2 versions is 60
    Last edited by primo; 27-03-2020 at 08:24.

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    I am happy to hear that!

    On some of my home PCs GetTickCount gets choppy, for some okay. It is a mystery for me for some time.

    It is not GPU related, as I have solid 60 FPS with VSync and 2000 FPS without VSync.


    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

Members who have read this thread: 1

Posting Permissions

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