randomthings
28-09-2009, 22:05
Hay there, is there any possible way that a built in GL camera can be rotated using a matrix?
I looked at the default TBGL camera and you can only specify the location and the looking point of the camera. No actual way to tilt it sideways.
It could be very useful for making better computer games.
Petr Schreiber
28-09-2009, 22:45
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:
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
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.
randomthings
07-10-2009, 18:53
Oh wow thank you.
I'll check it out when I get the free time.
Oh, and a lot more other questions to ask you. Is there a help file for TBGL that exists?
Because I was also looking for a way to add/delete object scenes on the fly if possible(when spawning bullets or other projectiles), along with creating scene objects by connecting the points to make an object as well. Also along with scene objects that are like sprites in a 3d scene, always facing the camera(for particle related purposes).
And one last thing about changing the running program icon from a cat's eye to something else. If that is TBGL related or not.
Anyways, I hope these are good questions.
Petr Schreiber
07-10-2009, 20:04
Hi,
of course TBGL has help file, you can find it in thinBASIC/Help/thinbasic_tbgl.chm or launch it from thinAir as Help/User help/TBGL or simply put cursor on any TBGL command and hit F1 key.
You can change the icon via TBGL_SetWindowIcon.
To make an entity face camera, you can use TBGL_EntitySetTarget for the billboard entity and specify target as camera.
Hope it helps!
randomthings
12-10-2009, 21:17
One more question. Is there such thing as a collision system between two mesh objects of different types? Whatever it's a M15, cube, sphere, and even a cylinder?
Or better yet, a collision between a point and a loaded M15 model(whatever it's rotated, or scaled), it would be helpful for a better game making.
I looked in the help file and it seems to only contain the basics collision system.
Petr Schreiber
12-10-2009, 21:22
Hi,
currentely the collisions are the job for the programmer. You can retrieve position and orientation of any object, and react in case two are too close using some approximation.
There is collision system in the works for TBGL, but it is not properly optimized to be released yet. It will support collision of spheres/oriented boxes in the first wave. Polygon to polygon collisions are computionally expensive, and most of games still use the bounding spheres/boxes today to keep the HW requirements low.