Welcome welcome 3D graphics adventurer,
your wishes already came true, and you even do not have to struggle with matrices!
In ThinBASIC, you can code in many ways. One of the approaches, specificaly designed for easy to maintain game code, is scene-entity system.
No need to worry about matrices, no need to fight goniometric functions. Just setup scene and use its members in unified way - camera, light or model...
Here is sample code, which allows you to tilt camera easily:
[code=thinbasic]
Uses "TBGL"
Begin Const
' -- Scene IDs
%sScene = 1
' -- Entity IDs
%eCamera = 1
%eLight
%eBox
End Const
Function TBMAIN()
Local hWnd As DWord
Local FrameRate As Double
' -- Create and show window
hWnd = TBGL_CREATEWINDOWEX("Use arrows to tilt camera - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_SHOWWINDOW
' -- Create scene
TBGL_SCENECREATE(%sScene)
' -- Create basic entities
' -- Create camera to look from 0, 1, 5 to 0, 1, 0
TBGL_ENTITYCREATECAMERA(%sScene, %eCamera)
TBGL_ENTITYSETPOS(%sScene, %eCamera, 0, 1, 5)
TBGL_ENTITYSETTARGETPOS(%sScene, %eCamera, 0, 1, 0)
' -- Create point light
TBGL_ENTITYCREATELIGHT(%sScene, %eLight)
TBGL_ENTITYSETPOS(%sScene, %eLight, 15, 10, 5)
' -- Create something to look at
TBGL_ENTITYCREATEBOX(%sScene, %eBox, 0, 1, 1, 1, 0, 255, 128, 0)
TBGL_ENTITYSETPOS(%sScene, %eBox, 0, 0, 0)
' -- Resets status of all keys
TBGL_RESETKEYSTATE()
' -- Main loop
While TBGL_ISWINDOW(hWnd)
FrameRate = TBGL_GETFRAMERATE
TBGL_CLEARFRAME
TBGL_SCENERENDER(%sScene)
TBGL_DRAWFRAME
' -- ESCAPE key to exit application
If TBGL_GETWINDOWKEYSTATE(hWnd, %VK_ESCAPE) Then Exit While
If TBGL_GETWINDOWKEYSTATE(hWnd, %VK_LEFT) Then
TBGL_ENTITYTURN(%sScene, %eCamera, 0, 45/FrameRate, 0)
ElseIf TBGL_GETWINDOWKEYSTATE(hWnd, %VK_RIGHT) Then
TBGL_ENTITYTURN(%sScene, %eCamera, 0,-45/FrameRate, 0)
End If
If TBGL_GETWINDOWKEYSTATE(hWnd, %VK_UP) Then
TBGL_ENTITYTURN(%sScene, %eCamera, -45/FrameRate, 0, 0)
ElseIf TBGL_GETWINDOWKEYSTATE(hWnd, %VK_DOWN) Then
TBGL_ENTITYTURN(%sScene, %eCamera, 45/FrameRate, 0, 0)
End If
Wend
TBGL_DESTROYWINDOW
End Function
[/code]
If you have a time to spare, have a look at SampleScripts/TBGL/TBGL_Demo6_MovingIn3D_UsingEntitySystem.tbasic.
It shows you basic "Wolfenstein 3D" like camera movement done by few lines of code.
You can push or turn camera as you wish.
Petr
P.S. If you need to, you can use TBGL_EntitySetXZAxis and other functions for direct manipulation of camera angles using 2 vectors (3rd auto calculated)... but I think you might like the Push/Turn approach from above, as it means less code.
Bookmarks