Petr, that is a really neat demo!
I studied it, but it still is not clear to me... but this is the kind of stuff I need to tap into for sure.
So this will get studied a lot the next few hours
THanks.
Hi Kent,
yes, you are right. Basic version with user data can be the following:
[code=thinbasic]
Uses "TBGL"
' -- Create and show window
Dim hWnd As Dword = TBGL_CreateWindowEx("UserData to hold info on object functions - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
' -- Create scene
%SCENE1 = 1
TBGL_SceneCreate(%SCENE1)
' -- Create basic entities
Begin Const
%etAI = 0
%etControled = 1
%eCamera = 1
%eLight
%eStart = 10
%eEnd = 20
end const
' -- Create camera to look from 15, 15, 15 to 0, 0, 0
TBGL_EntityCreateCamera(%SCENE1, %eCamera)
TBGL_EntitySetPos(%SCENE1, %eCamera, 50, 50, 50)
TBGL_EntitySetTargetPos(%SCENE1, %eCamera, 0, 0, 0)
' -- Create point light
TBGL_EntityCreateLight(%SCENE1, %eLight)
TBGL_EntitySetPos(%SCENE1, %eLight, 15, 10, 5)
' -- Create something to look at
type TEntBox
eType as long ' -- AI = 0, controled = 1
onLeft as asciiz * 256
onRight as asciiz * 256
onUp as asciiz * 256
onDown as asciiz * 256
end Type
' -- Variable to fill data
dim entBox as TentBox
dim i as long
' -- Random objects, some controllable by arrows, some with own AI
for i = %eStart to %eEnd
TBGL_EntityCreateBox(%SCENE1, i, 0, 1, 1, 1, 0, rnd(128,255), rnd(128,255), rnd(128,255))
TBGL_EntitySetPos(%SCENE1, i, rndf(-10,10), 0, rndf(-10,10))
entBox.eType = rnd(%etAI, %etControled)
entBox.onLeft = "entBox_GoLeft"
entBox.onRight = "entBox_GoRight"
entBox.onUp = "entBox_GoUp"
entBox.onDown = "entBox_GoDown"
TBGL_EntitySetUserData(%SCENE1, i, entBox)
next
DIM FrameRate AS DOUBLE
' -- Resets status of all keys
TBGL_GetAsyncKeyState(-1)
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
TBGL_ClearFrame
TBGL_SceneRender(%SCENE1)
Entities_Process()
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
Wend
TBGL_DestroyWindow
sub Entities_Process()
local i as long
local s as TentBox PTR
for i = %eStart to %eEnd
s = TBGL_EntityGetUserDataPointer(%SCENE1, i)
if s.eType = %etAI then
Controls_AI(i)
ELSEIF s.eType = %etControled then
Controls_Player(i)
end if
next
end sub
sub Controls_Player( entity as long )
local s as TentBox PTR
s = TBGL_EntityGetUserDataPointer(%SCENE1, entity)
if TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then
call ""+s.onLeft(entity)
elseif TBGL_GetWindowKeyState(hWnd, %VK_RIGHT) Then
call ""+s.onRight(entity)
endif
if TBGL_GetWindowKeyState(hWnd, %VK_UP) Then
call ""+s.onUp(entity)
elseif TBGL_GetWindowKeyState(hWnd, %VK_DOWN) Then
call ""+s.onDown(entity)
endif
end sub
sub Controls_AI( entity as long )
local s as TentBox PTR
s = TBGL_EntityGetUserDataPointer(%SCENE1, entity)
select case rnd(1, 3)
case 1
call ""+s.onLeft(entity)
case 2
call ""+s.onUp(entity)
case 3
call ""+s.onRight(entity)
end SELECT
end sub
sub entBox_GoLeft( entity as long )
tbgl_EntityTurn(%SCENE1, entity, 0, 180/FrameRate, 0)
end sub
sub entBox_GoRight( entity as long )
tbgl_EntityTurn(%SCENE1, entity, 0,-180/FrameRate, 0)
end sub
sub entBox_GoUp( entity as long )
tbgl_EntityPush(%SCENE1, entity, 0, 0, 10/FrameRate)
end sub
sub entBox_GoDown( entity as long )
tbgl_EntityPush(%SCENE1, entity, 0, 0,-10/FrameRate)
end sub
[/code]
I am very curious about Eros idea, he always comes with some surprise which would not occur to me. So I am sure he will come with some mini-revolution again. From his description it sounded almost like a OOP class, we will see what it will be once ready. But as Eros means it for tB 2.x+ then we will have to wait for a while
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Petr, that is a really neat demo!
I studied it, but it still is not clear to me... but this is the kind of stuff I need to tap into for sure.
So this will get studied a lot the next few hours
THanks.
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
Above two posts splitted in order to keep things organized.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Petr,
thanks to your example I've seen that CALL statement was not working with with UDT elements.
I've updated again thinBasic 1.6.0.8 with this aspect fixed.
Now you can use:
[code=thinbasic]sub Controls_AI( entity as long )
local s as TentBox PTR
s = TBGL_EntityGetUserDataPointer(%SCENE1, entity)
select case rnd(1, 3)
case 1
call s.onLeft(entity)
case 2
call s.onUp(entity)
case 3
call s.onRight(entity)
end SELECT
end sub[/code]
avoiding to use "" in front of the string expression.
Thanks
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Oh yes that is a really nice touch Eros. Easier to understand the code looking at it this way!
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
Bookmarks