Results 1 to 6 of 6

Thread: Rotating the camera using the matrix.

  1. #1

    Rotating the camera using the matrix.

    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.

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736

    Re: Rotating the camera using the matrix.

    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.




    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

    Re: Rotating the camera using the matrix.

    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.

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736

    Re: Rotating the camera using the matrix.

    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!
    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

  5. #5

    Re: Rotating the camera using the matrix.

    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.

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736

    Re: Rotating the camera using the matrix.

    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.
    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

Similar Threads

  1. TBGL - Rotating objects - TBGL_Rotate
    By dcromley in forum TBGL General
    Replies: 9
    Last Post: 04-06-2016, 09:10

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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