PDA

View Full Version : 0.1.9.2 Hazard course ;]



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

kryton9
10-03-2007, 21:23
Petr, that is so fantastic. I couldn't believe my eyes while playing with it. Very very responsive and accurate, I can't wait to grasp how it is all working. I will concentrate on it after I finish my short little project. Thanks that is really power into the bag of magic!!

TBGL Mana up by 1000

Petr Schreiber
10-03-2007, 21:37
Hi Kent,

thanks a lot !

The calculation is as precise as your graphic card.
It is also kind of fast beast, because imagine I had to test ray intersection for each triangle of some big terrain... that would be slower with more triangles, now it is just "Hi Radeon, could you throw me coord from x,y ? Sure, I have it already in depth buffer" :)

I think it could be quite useful for kind of scenery editor, where you have terrain, and then you could plant trees exactly where you click.


Bye bye,
Petr

ErosOlmi
10-03-2007, 22:03
Hi Petr,

to continue your nice day, example GPF on my PC if executed at full screen 1680 x 1050. Works ok on a window.
GPF occur in atioglxx.dll
Only one out of 4 try it worked ok at full screen.

Ciao
Eros

kryton9
11-03-2007, 01:03
I am running on a nvidia card and full screen no problem. Could it be ati driver related?

kryton9
11-03-2007, 02:15
Ok after I installed the lates thinBasic update and then ran Petr's program I got the same error now.
I reinstalled his dll that he had and it still didn't work in fullscreen.

So something in the latest update is effecting it as far as I can tell. I will check other apps now in more detail.

kryton9
11-03-2007, 02:52
Topdown and Bot the latest programs we made beside's Petr's nice demo all worked. One of Mike's older tbdi tests crashed with the new update also. But the bot program that really uses the new stuff in the tbdi all seemed to work fine.

Petr's demo app, which worked is crashing wether in fullscreen or window. I also found out thinbasic is still running even when you get out of the crash. So I restart the computer to make sure it is all clean.

I am writing this not to complain, to hope that it aids in figuring out what is causing it.

Michael Hartlef
11-03-2007, 09:14
Same here, demo runs at window mode but crashes in full screen.

NVidia ForceWare 84.71.

Petr Schreiber
11-03-2007, 10:54
Hi guys,

I am going to get some rope :(

If I understand it correctly - you use the new, second version of TBGL 0.1.9.2 and it causes GPF even in scripts which does not use new TBGL functionalities ?

Thanks a lot for your information - I just realized I am able to replicate the problem on my PC too. It seems to be resolution dependant, investigation continues...

I am sorry if it caused any loss of your work or anything else, bug was not introduced intentionaly.


I will try to fix it today,
Petr

ErosOlmi
11-03-2007, 11:04
All previous scripts work fine in full screen.
It seems only this script with latest TBGL 0.1.9.2

Petr Schreiber
11-03-2007, 11:07
Hi,

it seems the problem is somewhere in tbgl_GetPixelInfo.
It does not GPF if I try to get %TBGL_PINFO_RGB, only XYZ is naughty...


Thanks,
Petr

Petr Schreiber
11-03-2007, 14:25
Happy end ?

I hope so ;D
Latest thinBASIC contains lates version of TBGL which is much more secure ( = no GPF ).
Reason was bad declaration in header file for OpenGL. Corrected and working ! :)


Bye,
Petr

ErosOlmi
11-03-2007, 14:34
Petr,

Another little observations on the attached example: if TBGL window is not upper most but partially covered by another one, it still get mouse movements and person positioning even if user is working with another application. Not urgent one but worth to consider for future.

those new features open many possibilities in games developing and 3D world simulations.
My mind needs some bound checking otherwise it will GPF :D

Ciao and thanks!
Eros

Petr Schreiber
11-03-2007, 14:44
Hi Eros,

you are right,
please see attached version which should behave more correctly.


Thanks,
Petr

ErosOlmi
11-03-2007, 14:49
Perfect. I will release right now.

Michael Hartlef
11-03-2007, 14:54
My mind needs some bound checking otherwise it will GPF :D


;D I can imagine what the dialog says....

Press Nose if you want a bugreport send to microsoft

Petr Schreiber
11-03-2007, 20:15
:D,

reporting tool detected you are not running genuine version of Nose,
please click here to get legal version of Nose at terrific prize with support for Aero-smell :]

If you have latest version of thinBASIC, you can try this ( patch over original sample):


'
' 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 tbgl_PointInside3D( x, y, z, %TBGL_OBJ_SPHERE, Spheres(i).x, Spheres(i).y, Spheres(i).z, Spheres(i).r) then
tbgl_PushMatrix
tbgl_UseLighting 0
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_UseLighting 1
tbgl_PopMatrix
exit for
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


What's new inside ? Eros suggested me very nice and easy way to do basic collisions, so I implemented them :)

Instead of:


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
' ...
end if


... you can use now just this:


if tbgl_PointInside3D( x, y, z, %TBGL_OBJ_SPHERE, Spheres(i).x, Spheres(i).y, Spheres(i).z, Spheres(i).r) then
' ...
end if


Supported collision primitives are also cube and cylinder.


Bye,
Petr

Michael Hartlef
11-03-2007, 21:50
Wow, great! This sunday is a very productive one. Good job mate.

kryton9
12-03-2007, 01:39
Glad it is all fixed while I slept, the world is nice!!

Petr, amazingly powerful command and in looking at it and your previous video clip I understand how it sort of works. Very clever.
You are saying the video card knows the z depth of the object as it is drawing it. So you just pass it the x and y and the card does the ray cast effect for you and tells you what is the object at that point. That is so insanely clever, I was smiling very wide when I see how you did it. That is really really smart!!!

Petr Schreiber
12-03-2007, 09:02
Hi,

thanks, I am very happy it is not GPFing and even ... working now :)
I hope it will be of use in editors and such a applications.

Yesterday was good day :)


Bye,
Petr

kryton9
12-03-2007, 22:02
I forgot to comment about the new collision system. WOW, we just use that command to see if a point is inside, sphere, cube and cylinder, that will be incredible.

I take it x,y,z is our point for our model that is moving, then the other parameters are checking for the object we run into. If this is my understanding, there is a recommendation that could improve speed.

If this is the way it works now, we would have to make our own checks for all the objects in the scene. This command will make it easier, but it could be a lot faster if the command did it.

So maybe another command where it would take our point(s) or bounding box and compare that with all the other objects in the scene. And return an array of hits, sorted by closest hit target to furthest or return just the closest object that collides. If you don't think it will make that much difference in performance, no need to do it as that new command is awesome and would be easy to code such a check.

Thanks for all the great new tools, so many I forget to mention about all of them.

Petr Schreiber
12-03-2007, 22:25
Hi kryton,

nice idea, but then it would be needed to "register" all objects like it is done in ODE.
But I will keep it in mind, seems quite reasonable to me. We must develop some killer app which will force me to implement such a statements :)


Bye,
Petr

kryton9
13-03-2007, 00:23
I am sure a killer app is coming after topdown.