PDA

View Full Version : Cone from TriangleFan



matthew
05-04-2007, 00:26
This Programme will draw a Cone on the Screen and Rotate it.




' Cone 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("Cone - 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 ConeRadius, ConeHeight as integer ' Radius and Height of Cone
dim ConeShade 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_camera 0, 0, 1, 0, 0, 0 ' Set Camera Position
tbgl_resetmatrix ' Clear the Current Matrix
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

ConeRadius = 1
ConeHeight = 4

tbgl_color 255, 255, 255 ' Set Colour to White

tbgl_beginpoly %gl_triangle_fan

tbgl_vertex 0.0, (ConeHeight / 2) * -1, 0.0

for i = 0 to 36

ConeShade = Abs (13.25 * (18-i))
tbgl_color ConeShade, ConeShade, ConeShade
tbgl_vertex ConeRadius * cos(degtorad(i*10)), (ConeHeight / 2), ConeRadius * Sin(degtorad(i*10))

next

tbgl_endpoly

tbgl_color 128, 128, 128 ' Set Colour to Grey

tbgl_beginpoly %gl_polygon

for i = 0 to 36

tbgl_vertex ConeRadius * cos(degtorad((36-i)*10)), (ConeHeight / 2), ConeRadius * 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

kryton9
05-04-2007, 05:46
Thanks for these samples Mathew. Nice to see how these so called primitive shaps come to life!!

Petr Schreiber
05-04-2007, 07:30
Hi,

thanks a lot!,
it reminds me of optimization I have still not done on tbgl cylinders with one radus equal to zero :)


Bye,
Petr

matthew
05-04-2007, 16:24
Thank's for the Comments you two. :)