PDA

View Full Version : Playing with Lesson #6 Primitives and lighting



kryton9
09-02-2007, 07:25
Lesson #6 is now working on my computer. Finally get to see it, neat.

Did a very slight mod to it. Just move your mouse in a nice circular motion so the diameter is almost the size of the window vertical.

'
' Lesson #6 from thinBASIC TBGL tutorials
' "Primitives and lighting"
'
' by Petr Schreiber
'
' Downloaded from http://psch.thinbasic.com/
'

Uses "TBGL"
uses "UI"

%WM_LBUTTONDOWN = &H201 ' Codes for window messages
%WM_RBUTTONDOWN = &H204

dim hWnd as dword
Dim Msg, wParam, lParam, x, y, hFont as dword


Dim LightX, LightY, LightIntensity as single
LightIntensity = 200

hWnd = tbgl_CreateWindow("Lesson #6 :: Interactive light - press ESC to quit")
tbgl_ShowWindow

' We will use simple Courier font
hFont = Font_Create("Courier New", 10)
tbgl_BuildFont hFont

' One light source will be in whole scene
tbgl_UseLightSource %GL_LIGHT0, 1

GetAsyncKeyState(%VK_ESCAPE) ' Resets ESC key status before checking

while IsWindow(hWnd)

tbgl_ClearFrame

' We will declare the position and intensity of light first, and then we will draw rest of the scene
tbgl_SetupLightSource %GL_LIGHT0, LightX, LightY, -9, 255, 255, 255, LightIntensity

if GetAsyncKeyState(%VK_ESCAPE) THEN exit while

Msg = getMessage(hWnd, wParam, lParam)

' '---Now test the message
if Msg = %WM_MOUSEMOVE then
' Unprecise but usable remaping of mouse cursor position
dialog get client hWnd to x, y
LightX = (lowrd(lParam)-x/2)/60
LightY = (y/2-hiwrd(lParam))/60

elseif Msg = %WM_LBUTTONDOWN then
LightIntensity += 20
if LightIntensity > 255 then LightIntensity = 255

elseif Msg = %WM_RBUTTONDOWN then
LightIntensity -= 20
if LightIntensity < 0 then LightIntensity = 0

end if

' I want to use lighting ! ...
tbgl_UseLighting 1

' Simple scene
tbgl_PushMatrix

tbgl_Translate 0,0,-10
tbgl_Rotate LightX*30,1,0,0

tbgl_Color 0,128,0
tbgl_Torus 0.5, 2

tbgl_Color 128,0,0
tbgl_Translate 0,LightY,0
tbgl_Sphere 0.5

tbgl_PopMatrix

' ... but not for the text
tbgl_UseLighting 0

' Let's print some info
tbgl_Color 255,200,0
tbgl_PrintFont "Move your mouse over screen", -0.19, 0.35, -1
tbgl_PrintFont "... and watch the light.", -0.19, 0.33, -1
tbgl_PrintFont "Change intensity using Left and Right clicks", -0.45, -0.31, -1
tbgl_PrintFont "Intesnity:"+STR$(LightIntensity), -0.45, -0.29, -1
tbgl_DrawFrame

wend

tbgl_KillFont
tbgl_DestroyWindow

Petr Schreiber
09-02-2007, 11:36
Hi,

very nice modification! With next TBGL you will be able to save some lines of code, but it is still not ready - especially documentation. The idea of controling the ball with up/down mouse movement is very nice ;)


Bye,
Petr

kryton9
09-02-2007, 18:38
Just fun to have mouse interactivity with the models and signs of things to come. Glad to see that lesson working, very nice example you made Petr!!