Results 1 to 7 of 7

Thread: Cylinder from Quads

  1. #1

    Cylinder from Quads

    This Programme will display a Cylinder on your Screen and Rotate it.

    [code=thinbasic]

    ' Cylinder in thinBASIC using TBGL...
    '

    uses "TBGL" ' thinBASIC OpenGL Library
    uses "MATH" ' Used for Trigonometry

    ' Create, Show Our Window and Reset Status of all Keys...
    '

    Dim hWnd As dword = tbgl_createwindow("Cylinder - Press 'Esc' to Quit")
    tbgl_showwindow

    tbgl_getasynckeystate(-1)

    ' Dimension and Initialize any Variables...
    '

    dim Xrot, Yrot, Zrot as single ' X,Y and Z Rotation Variables
    dim CylinderRadius, CylinderHeight as integer ' Radius and Height of Cylinder
    dim CylinderShade as single ' Level of Brightness
    dim i as integer ' Polygon Drawing Loop Variable

    ' Main Programme Loop
    '

    while tbgl_iswindow(hWnd)

    tbgl_clearframe ' Clear Screen
    tbgl_resetmatrix ' Clear the Current Matrix
    tbgl_camera 0, 0, 1, 0, 0, 0 ' Set Camera Position
    tbgl_translate 0.0, 0.0, -5.0 ' Move Object into Screen by 5.0

    tbgl_Rotate Xrot, 1.0, 0.0, 0.0 ' Rotation around the X-Axis
    tbgl_Rotate Yrot, 0.0, 1.0, 0.0 ' Rotation around the Y-Axis
    tbgl_Rotate Zrot, 0.0, 0.0, 1.0 ' Rotation around the Z-Axis

    CylinderRadius = 1
    CylinderHeight = 4

    tbgl_color 128, 128, 128 ' Cylinder Top, Grey.

    tbgl_beginpoly %gl_polygon

    for i = 0 to 36

    tbgl_vertex CylinderRadius * cos(degtorad(i*10)), (CylinderHeight / 2) * -1, CylinderRadius * Sin(degtorad(i*10))

    next

    tbgl_endpoly

    tbgl_color 255, 255, 255 ' Set Colour to White

    tbgl_beginpoly %gl_quad_strip

    ' Draw Actual Cylinder in 10 Degree Steps...
    '

    for i = 0 to 36

    ' Shade Surface of Cylinder...
    '

    CylinderShade = abs(13.25 * (18-i))
    tbgl_color CylinderShade, CylinderShade, CylinderShade

    ' Draw Top Vertex...
    '

    tbgl_vertex CylinderRadius * Cos(degtorad(i*10)), (CylinderHeight / 2) * -1, CylinderRadius * Sin(degtorad(i*10))

    ' Draw Bottom Vertex...
    '

    tbgl_vertex CylinderRadius * cos(degtorad(i*10)), (CylinderHeight / 2), CylinderRadius * Sin(degtorad(i*10))

    next

    tbgl_endpoly

    ' Draw Bottom of Cylinder...
    '

    tbgl_color 128, 128, 128
    tbgl_beginpoly %gl_polygon

    for i = 0 to 36

    tbgl_vertex CylinderRadius * cos(degtorad((36-i))*10), CylinderHeight / 2, CylinderRadius * Sin(degtorad((36-i)*10))

    next

    tbgl_endpoly

    tbgl_drawframe ' Swap the Drawing Buffers

    Xrot = Xrot + 0.1 ' X axis rotation
    Yrot = Yrot + 0.2 ' Y axis rotation
    Zrot = Zrot + 0.05 ' Z axis rotation

    if tbgl_getwindowkeystate(hWnd, %vk_escape) then exit while

    wend

    tbgl_destroywindow ' Closes OpenGL Window

    [/code]
    Attached Images Attached Images
    Operating System: Windows 10 Home 64-bit
    CPU: Intel Celeron N4000 CPU @ 1.10GHz
    Memory: 4.00GB RAM
    Graphics: Intel UHD Graphics 600

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

    Re: Cylinder from Quads

    Hi Matthew,

    Good to see you after time
    I was nervous brother-in-OpenGL left the forums ;D

    Nice demo!

    Bye,
    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

    Re: Cylinder from Quads

    Thanks for sharing Matthew.

  4. #4

    Re: Cylinder from Quads

    @Mike - Thank's Mike.

    Quote Originally Posted by Psch
    Good to see you after time
    I was nervous brother-in-OpenGL left the forums ;D
    I visit the thinBASIC Forum everyday but I don't bother posting if I haven't written a Programme.
    Operating System: Windows 10 Home 64-bit
    CPU: Intel Celeron N4000 CPU @ 1.10GHz
    Memory: 4.00GB RAM
    Graphics: Intel UHD Graphics 600

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

    Re: Cylinder from Quads

    [code=thinbasic]
    tbgl_camera 0, 0, 1, 0, 0, 0 ' Set Camera Position
    tbgl_resetmatrix ' Clear the Current Matrix
    [/code]

    Shouldnt that be.

    [code=thinbasic]
    tbgl_resetmatrix ' Clear the Current Matrix
    tbgl_camera 0, 0, 1, 0, 0, 0 ' Set Camera Position
    [/code]

    You reset the matrix then do your translations, rotation and camera stuff.
    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

  6. #6

    Re: Cylinder from Quads

    ^^
    Yeah, when I first started using thinBASIC I used to make that mistake. :P

    Source Updated.
    Operating System: Windows 10 Home 64-bit
    CPU: Intel Celeron N4000 CPU @ 1.10GHz
    Memory: 4.00GB RAM
    Graphics: Intel UHD Graphics 600

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

    Re: Cylinder from Quads

    And to make it even more complicated ,

    just:
    [code=thinbasic]
    tbgl_ClearFrame
    tbgl_Camera 0,0,1,0,0,0
    [/code]

    is enough! TBGL_ClearFrame handles the matrix reset automatically.
    But this is just mini problem, I still like the sample


    Thanks,
    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: 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
  •