Petr Schreiber
10-03-2007, 21:07
Hi all,
I have very buggy day today :P
Here you can find attached corrected TBGL module ( fixes error reported by Eros ).
This offer has one big disadvantage - to avoid GPF I had to temporary disable ability to resize TBGL window, please be patient, I am fixing it.
So what will you see after downloading files below ? I hope no GPF :-\ but little demonstration of cursor tracking.
Hope you will like it.
Here is code ( included in ZIP too ):
'
' First thinBASIC TBGL 0.1.9.2 script :)
'
Uses "TBGL"
Uses "UI"
' First hot news - get desktop size AND depth to byref parameters !
dim desktopX, desktopY, desktopDepth as long
tbgl_GetDesktopInfo desktopX, desktopY, desktopDepth
Dim hWnd As Dword
if msgbox( 0, "Your current desktop settings are:"+FORMAT$(desktopX)+"x"+FORMAT$(desktopY)+" with"+STR$(desktopDepth)+" bits of color information"+ _
$CRLF+"Do you want to go fullscreen with this settings?", %MB_YESNO or %MB_ICONQUESTION, "Question") = %IDYES then
' -- Fullscreen
hWnd = TBGL_CreateWindowEx("Introduction to TBGL 0.1.9.2", desktopX, desktopY, desktopDepth, 1)
' Caution :), this enables mouse cursor even for fullscreen mode
tbgl_ShowCursor 1
else
' -- Windowed
hWnd = TBGL_CreateWindowEx("Introduction to TBGL 0.1.9.2", 640, 480, desktopDepth, 0)
end if
TBGL_ShowWindow
tbgl_LoadBMPFont "Textures\tbgl_gamefont.bmp", 40 ' We will use bitmap font in 30 lines mode
tbgl_ClearFrame
tbgl_PrintBMP "Please wait...", 0, 0, %TBGL_ALIGN_CENTER_CENTER
tbgl_PrintBMP "Script is now loading models", 0, 1, %TBGL_ALIGN_CENTER_CENTER
tbgl_DrawFrame
tbgl_m15InitModelBuffers 1, 3000
%TERRAIN = 1
%GUY = 2
tbgl_m15LoadModel "Models\terrain0192.m15", "Textures\", 1, %TERRAIN, %TBGL_NORMAL_SMOOTH
tbgl_m15ClearModel 1
tbgl_m15LoadModel "Models\gameCharacter.m15", "Textures\", 1, %GUY, %TBGL_NORMAL_SMOOTH
tbgl_m15ClearModel 1
tbgl_UseLighting 1
tbgl_UseLightSource %GL_LIGHT0, 1
GetAsyncKeyState(-1) ' Resets ESC key status before checking
local i as long
type tSphere
x as single
y as single
z as single
r as single
end type
local SpheresNum as long = 4
local Spheres(SpheresNum) as tSphere
for i = 1 to SpheresNum
Spheres(i).x = rndf(10,-10)
Spheres(i).y = rndf(10,-10)
Spheres(i).z = rndf(10,-10)
Spheres(i).r = rndf(0.5,2.5)
next
local cX, cY as long
local x, y, z as single
local manX, manY, manZ as single = 200
local xRot as single
local yRot as single
local FrameRate as single
While IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
tbgl_ClearFrame
tbgl_Camera 15,15,15,0,0,0
tbgl_Rotate xRot, 1, 0, 0
tbgl_Rotate yRot, 0, 1, 0
tbgl_CallList %TERRAIN
for i = 1 to SpheresNum
tbgl_PushMatrix
tbgl_Translate Spheres(i).x, Spheres(i).y, Spheres(i).z
tbgl_Color 255,128,0
tbgl_Sphere Spheres(i).r
tbgl_PopMatrix
next
' This returns x,y,z coordinates under mouse to variables
tbgl_GetPixelInfo tbgl_MouseGetPosX,tbgl_MouseGetPosY, %TBGL_PINFO_xyz, x, y, z
for i = 1 to SpheresNum
if inside (x, Spheres(i).x - Spheres(i).r, Spheres(i).x + Spheres(i).r) and _
inside (y, Spheres(i).y - Spheres(i).r, Spheres(i).y + Spheres(i).r) and _
inside (z, Spheres(i).z - Spheres(i).r, Spheres(i).z + Spheres(i).r)then
tbgl_PushMatrix
tbgl_Translate Spheres(i).x, Spheres(i).y, Spheres(i).z
tbgl_PolygonLook %GL_LINE
tbgl_Box Spheres(i).r*2, Spheres(i).r*2, Spheres(i).r*2
tbgl_PolygonLook %GL_FILL
tbgl_PopMatrix
end if
next
if TBGL_MouseGetLButton then
manX = x
manY = y
manZ = z
end if
tbgl_PushMatrix
tbgl_translate manX, manY, manZ
tbgl_CallList %GUY
tbgl_PopMatrix
tbgl_resetMatrix
tbgl_UseLighting 0
tbgl_PrintBMP "X:"+Format$(x, "#.00"), 0, 0, %TBGL_ALIGN_LEFT_UP
tbgl_PrintBMP "Y:"+Format$(y, "#.00"), 0, 1, %TBGL_ALIGN_LEFT_UP
tbgl_PrintBMP "Z:"+Format$(z, "#.00"), 0, 2, %TBGL_ALIGN_LEFT_UP
tbgl_GetWindowClient hWnd, cX, cY
tbgl_PrintBMP "TBGL window is"+STR$(cX)+"x"+format$(cY), 0, -3, %TBGL_ALIGN_LEFT_Down
tbgl_PrintBMP "Use arrows to set some mad viewing angle", 0, -2, %TBGL_ALIGN_LEFT_Down
tbgl_PrintBMP "Click on objects to set guy position", 0, -1, %TBGL_ALIGN_LEFT_Down
tbgl_PrintBMP "Move mouse over spheres to see ~selection", 0, 0, %TBGL_ALIGN_LEFT_Down
tbgl_UseLighting 1
tbgl_DrawFrame
If GetWindowKeyState( hWnd, %VK_ESCAPE) Then Exit While
If GetWindowKeyState( hWnd, %VK_LEFT) Then yRot += 30/FrameRate
If GetWindowKeyState( hWnd, %VK_right) Then yRot -= 30/FrameRate
If GetWindowKeyState( hWnd, %VK_Up) Then xRot += 30/FrameRate
If GetWindowKeyState( hWnd, %VK_Down) Then xRot -= 30/FrameRate
Wend
TBGL_DestroyWindow
Bye,
Petr
I have very buggy day today :P
Here you can find attached corrected TBGL module ( fixes error reported by Eros ).
This offer has one big disadvantage - to avoid GPF I had to temporary disable ability to resize TBGL window, please be patient, I am fixing it.
So what will you see after downloading files below ? I hope no GPF :-\ but little demonstration of cursor tracking.
Hope you will like it.
Here is code ( included in ZIP too ):
'
' First thinBASIC TBGL 0.1.9.2 script :)
'
Uses "TBGL"
Uses "UI"
' First hot news - get desktop size AND depth to byref parameters !
dim desktopX, desktopY, desktopDepth as long
tbgl_GetDesktopInfo desktopX, desktopY, desktopDepth
Dim hWnd As Dword
if msgbox( 0, "Your current desktop settings are:"+FORMAT$(desktopX)+"x"+FORMAT$(desktopY)+" with"+STR$(desktopDepth)+" bits of color information"+ _
$CRLF+"Do you want to go fullscreen with this settings?", %MB_YESNO or %MB_ICONQUESTION, "Question") = %IDYES then
' -- Fullscreen
hWnd = TBGL_CreateWindowEx("Introduction to TBGL 0.1.9.2", desktopX, desktopY, desktopDepth, 1)
' Caution :), this enables mouse cursor even for fullscreen mode
tbgl_ShowCursor 1
else
' -- Windowed
hWnd = TBGL_CreateWindowEx("Introduction to TBGL 0.1.9.2", 640, 480, desktopDepth, 0)
end if
TBGL_ShowWindow
tbgl_LoadBMPFont "Textures\tbgl_gamefont.bmp", 40 ' We will use bitmap font in 30 lines mode
tbgl_ClearFrame
tbgl_PrintBMP "Please wait...", 0, 0, %TBGL_ALIGN_CENTER_CENTER
tbgl_PrintBMP "Script is now loading models", 0, 1, %TBGL_ALIGN_CENTER_CENTER
tbgl_DrawFrame
tbgl_m15InitModelBuffers 1, 3000
%TERRAIN = 1
%GUY = 2
tbgl_m15LoadModel "Models\terrain0192.m15", "Textures\", 1, %TERRAIN, %TBGL_NORMAL_SMOOTH
tbgl_m15ClearModel 1
tbgl_m15LoadModel "Models\gameCharacter.m15", "Textures\", 1, %GUY, %TBGL_NORMAL_SMOOTH
tbgl_m15ClearModel 1
tbgl_UseLighting 1
tbgl_UseLightSource %GL_LIGHT0, 1
GetAsyncKeyState(-1) ' Resets ESC key status before checking
local i as long
type tSphere
x as single
y as single
z as single
r as single
end type
local SpheresNum as long = 4
local Spheres(SpheresNum) as tSphere
for i = 1 to SpheresNum
Spheres(i).x = rndf(10,-10)
Spheres(i).y = rndf(10,-10)
Spheres(i).z = rndf(10,-10)
Spheres(i).r = rndf(0.5,2.5)
next
local cX, cY as long
local x, y, z as single
local manX, manY, manZ as single = 200
local xRot as single
local yRot as single
local FrameRate as single
While IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
tbgl_ClearFrame
tbgl_Camera 15,15,15,0,0,0
tbgl_Rotate xRot, 1, 0, 0
tbgl_Rotate yRot, 0, 1, 0
tbgl_CallList %TERRAIN
for i = 1 to SpheresNum
tbgl_PushMatrix
tbgl_Translate Spheres(i).x, Spheres(i).y, Spheres(i).z
tbgl_Color 255,128,0
tbgl_Sphere Spheres(i).r
tbgl_PopMatrix
next
' This returns x,y,z coordinates under mouse to variables
tbgl_GetPixelInfo tbgl_MouseGetPosX,tbgl_MouseGetPosY, %TBGL_PINFO_xyz, x, y, z
for i = 1 to SpheresNum
if inside (x, Spheres(i).x - Spheres(i).r, Spheres(i).x + Spheres(i).r) and _
inside (y, Spheres(i).y - Spheres(i).r, Spheres(i).y + Spheres(i).r) and _
inside (z, Spheres(i).z - Spheres(i).r, Spheres(i).z + Spheres(i).r)then
tbgl_PushMatrix
tbgl_Translate Spheres(i).x, Spheres(i).y, Spheres(i).z
tbgl_PolygonLook %GL_LINE
tbgl_Box Spheres(i).r*2, Spheres(i).r*2, Spheres(i).r*2
tbgl_PolygonLook %GL_FILL
tbgl_PopMatrix
end if
next
if TBGL_MouseGetLButton then
manX = x
manY = y
manZ = z
end if
tbgl_PushMatrix
tbgl_translate manX, manY, manZ
tbgl_CallList %GUY
tbgl_PopMatrix
tbgl_resetMatrix
tbgl_UseLighting 0
tbgl_PrintBMP "X:"+Format$(x, "#.00"), 0, 0, %TBGL_ALIGN_LEFT_UP
tbgl_PrintBMP "Y:"+Format$(y, "#.00"), 0, 1, %TBGL_ALIGN_LEFT_UP
tbgl_PrintBMP "Z:"+Format$(z, "#.00"), 0, 2, %TBGL_ALIGN_LEFT_UP
tbgl_GetWindowClient hWnd, cX, cY
tbgl_PrintBMP "TBGL window is"+STR$(cX)+"x"+format$(cY), 0, -3, %TBGL_ALIGN_LEFT_Down
tbgl_PrintBMP "Use arrows to set some mad viewing angle", 0, -2, %TBGL_ALIGN_LEFT_Down
tbgl_PrintBMP "Click on objects to set guy position", 0, -1, %TBGL_ALIGN_LEFT_Down
tbgl_PrintBMP "Move mouse over spheres to see ~selection", 0, 0, %TBGL_ALIGN_LEFT_Down
tbgl_UseLighting 1
tbgl_DrawFrame
If GetWindowKeyState( hWnd, %VK_ESCAPE) Then Exit While
If GetWindowKeyState( hWnd, %VK_LEFT) Then yRot += 30/FrameRate
If GetWindowKeyState( hWnd, %VK_right) Then yRot -= 30/FrameRate
If GetWindowKeyState( hWnd, %VK_Up) Then xRot += 30/FrameRate
If GetWindowKeyState( hWnd, %VK_Down) Then xRot -= 30/FrameRate
Wend
TBGL_DestroyWindow
Bye,
Petr