Results 1 to 9 of 9

Thread: World Matrix Rotation

  1. #1

    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.

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,138
    Rep Power
    733
    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 - 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
    Last edited by Petr Schreiber; 10-11-2010 at 23:00.
    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

  3. #3
    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).

  4. #4
    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?o...tegory&catid=5

    There are full of samples.

    Have fun studying.
    Michael

  5. #5

    Thanks!

    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.

  6. #6
    Member sblank's Avatar
    Join Date
    Feb 2010
    Location
    Wayne City, Illinois
    Posts
    80
    Rep Power
    23
    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

    Quote Originally Posted by Dylan View Post
    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.

  7. #7
    Member sblank's Avatar
    Join Date
    Feb 2010
    Location
    Wayne City, Illinois
    Posts
    80
    Rep Power
    23

    Simple rotate script

    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

    Quote Originally Posted by Dylan View Post
    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.
    Attached Files Attached Files

  8. #8
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,138
    Rep Power
    733
    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
    Attached Files Attached Files
    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

  9. #9
    Member sblank's Avatar
    Join Date
    Feb 2010
    Location
    Wayne City, Illinois
    Posts
    80
    Rep Power
    23
    Thanks Petr...

    There is nothing like learning from the TBGL author... nicely done!

    Stan

    Quote Originally Posted by Petr Schreiber View Post
    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

Similar Threads

  1. End of the World [Again]
    By JosephE in forum General
    Replies: 17
    Last Post: 26-05-2011, 07:58
  2. Rotation problem
    By zak in forum TBGL General
    Replies: 4
    Last Post: 19-01-2009, 18:43

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •