View Full Version : World Matrix Rotation
Hey, I'm in Dr. Stan Blank's computer science class and I'm not sure how rotate the camera around the origin using the arrow keys for control. Any help would be appreciated. Thanks.
Petr Schreiber
10-11-2010, 22:47
Hi Dylan and welcome to the forums!
There are multiple approaches to do what you need:
Low level approach: use TBGL_Camera with custom rotation vectors calculated using SIN, COS
Middle level approach: use TBGL_Translate and TBGL_Rotate commands to modify the viewing position
High level approach: use entity system with Camera entity, which you can turn and push in intuitive way
For examples, I would like to ask you to navigate to your ThinBASIC installation directory, then to SampleScripts and then finally to TBGL folder.
There you should be able to locate file TBGL_Demo06_MovingIn3D.tBasic, which shows the low level approach, and finally the TBGL_Demo06_MovingIn3D_UsingEntitySystem.tBasic, which shows the less math intensive high level approach using entity system.
I would like to add that TBGL help file can be launched separately from Help menu, or by pressing F1 key on any of the TBGL keywords. It contains information on all TBGL keywords and it should help you in discovering the TBGL structure.
Petr
P.S. I recommend downloading the latest ThinBASIC 1.8.6.0 (http://www.thinbasic.com/community/showthread.php?10672-thinBasic-Beta-1.8.6.0) - it is betaversion, yet it provides the latest additions to TBGL, language in general and the IDE is fine tuned comparing to ThinBASIC 1.8.0.0 stable
I knew you could do it with the trig, but I figured there was a built in command for it. Thanks for the help, and hopefully soon my questions will actually amount to something besides the basics (no pun intended).
Michael Hartlef
10-11-2010, 23:58
Hi Dylan,
welcome from my side too. Don't worry about asking if your question are simple or advanced. We are here to help each other. ThinBasic is huge and so someone can get lost inside the samples section.
For more infos you can also look at Petr's website at http://psch.thinbasic.com .
There are also 2 bonus paks for TBGL which you can download here:
http://www.thinbasic.com/index.php?option=com_jdownloads&Itemid=95&task=viewcategory&catid=5
There are full of samples.
Have fun studying.
Michael
Thanks. Dr. Blank showed me the bonus packs today and from what I saw of them, there is a lot of cool things you can do with thinBasic. Can't wait to see what all it can do.
P.S. How do you limit the fps? My computer makes some of the samples run way too fast. I think pong was running at between 600 and 1000 fps.
Hi Dylan,
From Petr's TBGL help file:
' For optimal performance use approach called "dynamic V-Sync",
' featured for example in "Gears Of War" game title
DIM maxFrameRate AS LONG = TBGL_GetVSyncMaxFrameRate()
WHILE TBGL_IsWindow( hWnd ) ' -- Rendering loop start
FrameRate = TBGL_GetFramerate ' -- Retrieve FPS
' -- Condition, if FPS should be more than max, turn VSync on, else off
TBGL_UseVSync IIF( FrameRate < maxFrameRate , 0, 1 )
' ... rendering here ...
WEND ' -- Rendering loop end
This code snippet might help a bit... Petr can correct me if I'm incorrect here! Vertical sync should help match the framerate to the monitor refresh rate... which may help slow down some of the "wild" graphics on your computer?
DrB
Thanks. Dr. Blank showed me the bonus packs today and from what I saw of them, there is a lot of cool things you can do with thinBasic. Can't wait to see what all it can do.
P.S. How do you limit the fps? My computer makes some of the samples run way too fast. I think pong was running at between 600 and 1000 fps.
Dylan,
Here is a simple camera rotate script using ideas and code from Petr, some sample scripts, and Petr's tutorial. When the flag variable = -1, the camera (you) rotate or fly around the origin. When flag = 1, the object rotates (using the arrow keys in both cases).
You can add your cube code rather than the simple triangle.
DrB
Hey, I'm in Dr. Stan Blank's computer science class and I'm not sure how rotate the camera around the origin using the arrow keys for control. Any help would be appreciated. Thanks.
Petr Schreiber
11-11-2010, 11:14
Hi Dylan,
I am happy you liked bonus packs!
The suggestion Stan gives is very good, but sometimes people force VSync ON/OFF in the drivers and you can't do anything about it.
Well - of course you can do, and that is use periodic function, as shows the code posted by Stan.
I slightly modified it to add 2 features:
frame rate independent moves
elimination of need for global variable for window handle
I present the modified script in 2 versions - "Classic" low level, and "Entity" high level.
You might notice the high level approach results in more code for simple code, but it will pay off in more complex scenes.
Petr
Thanks Petr...
There is nothing like learning from the TBGL author... nicely done!
Stan
Hi Dylan,
I am happy you liked bonus packs!
The suggestion Stan gives is very good, but sometimes people force VSync ON/OFF in the drivers and you can't do anything about it.
Well - of course you can do, and that is use periodic function, as shows the code posted by Stan.
I slightly modified it to add 2 features:
frame rate independent moves
elimination of need for global variable for window handle
I present the modified script in 2 versions - "Classic" low level, and "Entity" high level.
You might notice the high level approach results in more code for simple code, but it will pay off in more complex scenes.
Petr