matthew
04-04-2007, 17:46
This Programme will display a Cylinder on your Screen and Rotate it. :)
' 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
' 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