Results 1 to 7 of 7

Thread: my little track ai :)

  1. #1
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    my little track ai :)

    ...I have changed this track ai from tbgl sample scripts in some interesting ways

    ... because it's a good example to learn about more this exciting stuff
    and what a wonder I have understood nearly everything... (must laugh)

    ciao, Lionheart and good night

    ps: to change the direction of the entity objects it's not impossible simple to use TBGL_EntitySetDirection (this command doesn't exist), but it would be a very nice one
    or
    'local direction as double = TBGL_EntityGetDirection(%sScene, entity, hoverData.nextWayPoint)
    my edit: deleted this first script, have updated a new version below
    Attached Images Attached Images
    you can't always get what you want, but if you try sometimes you might find, you get what you need

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

    Re: my little track ai :)

    Hi Frank,

    nice mod. There is no need to EntitySetDirection , it is enough to supply waypoints in reverse order.
    Try the code above, F1 changes direction.

    [code=thinbasic]
    '
    ' Test of hovercraft AI
    ' Petr Schreiber, started on 09-26-2008
    ' Lionhearts example, 14. april 2009

    Uses "TBGL"
    randomize timer

    BEGIN CONST
    ' -- Scene IDs
    %sScene = 1

    ' -- Entity IDs
    %eCamera = 1
    %eLight
    %eLight1
    %eHovercraftPrecise
    %eHovercraftMedium
    %eHovercraftBrutus
    %eHovercraftBox
    %eHovercraftLazy
    %eWayPointStart
    END CONST
    GLOBAL FrameRate AS DOUBLE
    GLOBAL DirectionSwap AS LONG = %TRUE

    FUNCTION TBMAIN()
    LOCAL hWnd As DWORD

    ' -- Create and show window
    hWnd = TBGL_CreateWindowEx("Test for hovercraft elemental AI", 800, 600, 32, %TBGL_WS_WINDOWED or %TBGL_WS_MINIMIZEBOX or %TBGL_WS_CLOSEBOX)
    TBGL_ShowWindow

    ' -- Create scene
    TBGL_SceneCreate(%sScene)

    ' -- Create basic entities
    ' -- Create camera to look from 15, 15, 15 to 0, 0, 0
    TBGL_EntityCreateCamera(%sScene, %eCamera)
    TBGL_EntitySetPos(%sScene, %eCamera, 0, 0, 30)
    TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)

    ' -- Create point light
    TBGL_EntityCreateLight(%sScene, %eLight, %TBGL_Lighttype_Directional)
    TBGL_EntitySetPos(%sScene, %eLight, 15, 12, 5)

    TBGL_NewList 1
    TBGL_UseLighting %FALSE
    TBGL_BeginPoly %GL_TRIANGLES
    TBGL_Vertex -0.5, -1.5
    TBGL_Vertex 0.5, -1.5
    TBGL_Vertex 0.0, 1.5
    TBGL_ENDPOLY
    TBGL_UseLighting %TRUE
    TBGL_EndList

    TBGL_NewList %eLight1
    TBGL_UseLighting %FALSE
    TBGL_BeginPoly %GL_TRIANGLES
    TBGL_Vertex -0.5, -1.5
    TBGL_Vertex 0.5, -1.5
    TBGL_Vertex 0.0, 1.5
    TBGL_ENDPOLY
    TBGL_UseLighting %TRUE
    TBGL_EndList


    TBGL_NewList 2
    TBGL_UseLighting %FALSE
    TBGL_BeginPoly %GL_QUADS
    TBGL_Vertex -0.5, -1.5
    TBGL_Vertex 0.5, -1.5
    TBGL_Vertex 0.5, 1.5
    TBGL_Vertex -0.5, 1.5
    TBGL_ENDPOLY
    TBGL_UseLighting %TRUE
    TBGL_EndList

    ' -- Create something to look at
    TYPE tHoverCraft
    nextWayPoint AS LONG
    numWayPoint AS LONG
    tolerance AS double ' -- Tolerance to reach waypoint
    minSpeed AS double
    maxSpeed AS double
    steerFactor AS double
    DirectionSwap as double
    END TYPE
    dim HoverInfo as tHoverCraft

    TBGL_EntityCreateDLSlot(%sScene, %eHovercraftPrecise, 0, 1)
    TBGL_EntitySetColor(%sScene, %eHovercraftPrecise, 128, 255+sin(GetTickCount/1000)*128, 0)
    ' -- Assign data to it
    with HoverInfo
    .nextWayPoint = %eWayPointStart
    .numWayPoint = 13
    .tolerance = 1
    .minSpeed = 5
    .maxSpeed = 100
    .steerFactor = 3
    .DirectionSwap = 2
    END WITH

    TBGL_EntitySetUserData(%sScene, %eHovercraftPrecise, HoverInfo)


    TBGL_EntityCreateDLSlot(%sScene, %eHovercraftBox, 0, 2)
    TBGL_EntitySetColor(%sScene, %eHovercraftBox, 28, 255+sin(GetTickCount/1000)*128, 0)
    ' -- Assign data to it
    with HoverInfo
    .nextWayPoint = %eWayPointStart
    .numWayPoint = 13
    .tolerance = 2
    .minSpeed = 2
    .maxSpeed = 50
    .steerFactor = 2
    .DirectionSwap = 3
    END WITH

    TBGL_EntitySetUserData(%sScene, %eHovercraftBox, HoverInfo)


    TBGL_EntityCreateDLSlot(%sScene, %eHovercraftMedium, 0, 1)
    TBGL_EntitySetColor(%sScene, %eHovercraftMedium, 0, 255, 128+sin(GetTickCount/1000)*12
    ' -- Assign data to it
    with HoverInfo
    .nextWayPoint = %eWayPointStart
    .numWayPoint = 13
    .tolerance = 3
    .minSpeed = 2
    .maxSpeed = 15
    .steerFactor = 3
    .DirectionSwap = 4
    END WITH

    TBGL_EntitySetUserData(%sScene, %eHovercraftMedium, HoverInfo)


    TBGL_EntityCreateDLSlot(%sScene, %eHovercraftBrutus, 0, 1)
    TBGL_EntitySetColor(%sScene, %eHovercraftBrutus, 50, 55+sin(GetTickCount/1000)*128, 12
    ' -- Assign data to it
    with HoverInfo
    .nextWayPoint = %eWayPointStart
    .numWayPoint = 13
    .tolerance = 4
    .minSpeed = 3
    .maxSpeed = 6
    .steerFactor = 3
    .DirectionSwap = 2
    END WITH

    TBGL_EntitySetUserData(%sScene, %eHovercraftBrutus, HoverInfo)

    TBGL_EntityCreateDLSlot(%sScene, %eHovercraftLazy, 0, 1)
    TBGL_EntitySetColor(%sScene, %eHovercraftLazy, 255, 0, 12
    ' -- Assign data to it
    with HoverInfo
    .nextWayPoint = %eWayPointStart
    .numWayPoint = 13
    .tolerance = 5
    .minSpeed = 1
    .maxSpeed = 40
    .steerFactor = 2
    .DirectionSwap = 1
    END WITH

    TBGL_EntitySetUserData(%sScene, %eHovercraftLazy, HoverInfo)


    TBGL_EntityCreateDLSlot(%sScene, %eLight1, 0, 2)
    TBGL_EntitySetColor(%sScene, %eLight1, 255+sin(GetTickCount/1000)*127,10+sin(GetTickCount/1000+1)*127,140+sin(GetTickCount/1000+2)*127)
    ' -- Assign data to it
    with HoverInfo
    .nextWayPoint = %eWayPointStart
    .numWayPoint = 13
    .tolerance = 4
    .minSpeed = 2
    .maxSpeed = 80
    .steerFactor = 2
    .DirectionSwap = 2
    END WITH

    TBGL_EntitySetUserData(%sScene, %eLight1, HoverInfo)

    local i as long

    for i = %eWayPointStart to %eWayPointStart + 11
    TBGL_EntityCreateBox(%sScene, i, 0, 0.25, 0.45, 0.25)
    TBGL_EntitySetColor(%sScene, i, rnd(1, 255), 28, rnd(1,80))
    next

    ' -- Hardcoded waypoints
    TBGL_EntitySetPos(%sScene, %eWayPointStart+0, 0, 2, 0)
    TBGL_EntitySetPos(%sScene, %eWayPointStart+1, 4, 3, 0)
    TBGL_EntitySetPos(%sScene, %eWayPointStart+2, 10, 5, 0)
    TBGL_EntitySetPos(%sScene, %eWayPointStart+3, 10, 10, 0)
    TBGL_EntitySetPos(%sScene, %eWayPointStart+4, 8, 6, 0)
    TBGL_EntitySetPos(%sScene, %eWayPointStart+5, 5, 11, 0)
    TBGL_EntitySetPos(%sScene, %eWayPointStart+6, -6, 8, 0)
    TBGL_EntitySetPos(%sScene, %eWayPointStart+7, -10, 4, 0)
    TBGL_EntitySetPos(%sScene, %eWayPointStart+8, -6, -10, 0)
    TBGL_EntitySetPos(%sScene, %eWayPointStart+9, -2, -7, 0)
    TBGL_EntitySetPos(%sScene, %eWayPointStart+10, 5, -5, 0)
    TBGL_EntitySetPos(%sScene, %eWayPointStart+11, 4, -8, 0)
    TBGL_EntitySetPos(%sScene, %eWayPointStart+12, 2, -5, 0)

    ' -- Resets status of all keys
    TBGL_ResetKeyState()

    DIM Sheep AS LONG
    ' -- Main loop
    While TBGL_IsWindow(hWnd)
    FrameRate = TBGL_GetFrameRate
    Sheep += 1
    IF Sheep > 200 THEN
    Sheep = 0
    TBGL_SetWindowTitle(hWnd, "Hello lovely AI, use F1 to change direction, FPS: " + FrameRate)
    END IF

    TBGL_ClearFrame
    HoverCraft_AI(%eHovercraftPrecise)
    HoverCraft_AI(%eHovercraftMedium)
    HoverCraft_AI(%eHovercraftBrutus)
    HoverCraft_AI(%eHovercraftBox)
    HoverCraft_AI(%eHovercraftLazy)
    HoverCraft_AI(%eLight1)
    TBGL_SceneRender(%sScene)

    TBGL_DrawFrame

    ' -- ESCAPE key to exit application
    If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
    If TBGL_GetWindowKeyState(hWnd, %VK_Space) Then Exit While
    If TBGL_GetWindowKeyOnce(hWnd, %VK_F1) Then DirectionSwap = not DirectionSwap
    Wend

    TBGL_DestroyWindow
    END FUNCTION

    Sub HoverCraft_AI( entity AS LONG )
    local hoverData AS tHoverCraft ptr

    ' -- Retrieve data from entity
    hoverData = TBGL_EntityGetUserDataPointer(%sScene, entity)

    ' -- Get angle and distance to next waypoint
    LOCAL angle AS DOUBLE = TBGL_EntityGetAngleXY(%sScene, entity, hoverData.nextWayPoint, %TBGL_Y) ' -- The front part is on Y axis
    local distance as double = TBGL_EntityGetDistance(%sScene, entity, hoverData.nextWayPoint)

    ' -- Move according to parametrization
    TBGL_EntityTurn(%sScene, entity, 0, 0, (hoverData.steerFactor*angle)/FrameRate)
    TBGL_EntityTurn(%sScene, entity, 0, 0, 10*angle/FrameRate )
    TBGL_EntityTurn(%sScene, entity, 0, 0, min(hoverData.DirectionSwap*angle)/FrameRate )
    TBGL_EntityPush(%sScene, entity, 0, min(hoverData.minSpeed+distance, hoverData.maxSpeed)/FrameRate, 0)



    ' -- Check for next waypoints
    if DirectionSwap then
    IF distance < hoverData.tolerance then
    if hoverData.nextWayPoint < %eWayPointStart+hoverData.numWayPoint then
    incr hoverData.nextWayPoint
    else
    hoverData.nextWayPoint = %eWayPointStart
    END IF
    END IF
    else
    IF distance < hoverData.tolerance then
    if hoverData.nextWayPoint > %eWayPointStart then
    decr hoverData.nextWayPoint
    else
    hoverData.nextWayPoint = %eWayPointStart+hoverData.numWayPoint
    END IF
    END IF
    end if
    END SUB

    [/code]

    Petr
    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
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    Re: my little track ai :)

    hi petr, hi all

    uhps... thank you for the waypoints in reverse order ! not so bad , this idea I haven't had at night... was too tired... damned... good idea more for "F1" ...

    I have updated and improved the script again, I like it... cause it's a basically example for some kind of game ai, isn't it ??? One new door opens for me

    ok, have a nice day, I am freezing, raining... no sunshine over my head, springtime gone ?

    ciao, Lionheart with increasing skills about rnd(1,10) per cent

    qt: somebody else like this kind of tbgl example too ??? anybody out there having some new ideas to start a little new hunter/prey game???
    Attached Images Attached Images
    Attached Files Attached Files
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  4. #4
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: my little track ai :)

    That is fun to watch. You could make fish, make the way points invisible, random F1 to switch the fishes swim direction and then you would have an aquarium program.

    I guess if you wanted to do more, the waypoints could be hidden in Coral Reef for example so the fish would appear to be swimming amongst coral or even sea weeds, or how about a sunken pirate ship?
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  5. #5
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    Re: my little track ai :)

    hi kent

    good idea, but a lot of work, isn't it??? - puh! but such ideas are worth to follow... :P
    I have a link for you, when you are a friend of undersea-water screensaver... and knowledge about underwater world... I know this guy he has built this great aquarium issue... all was programmed in/with c++ language, not with thinbasic but the track ai skeleton from petr last autumn I like very mucho .

    may be a good startpoint for a underwater screensaver full of fearly, lovely delphins and evil sharks

    http://www.aridocean.com/info_aridocean_en.htm

    have a nice day, good week-end, ciao, Lionheart
    Attached Images Attached Images
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  6. #6
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: my little track ai :)

    Quote Originally Posted by Lionheart008
    hi kent

    good idea, but a lot of work, isn't it??? - puh! but such ideas are worth to follow... :P
    I have a link for you, when you are a friend of undersea-water screensaver... and knowledge about underwater world... I know this guy he has built this great aquarium issue... all was programmed in/with c++ language, not with thinbasic but the track ai skeleton from petr last autumn I like very mucho .

    may be a good startpoint for a underwater screensaver full of fearly, lovely delphins and evil sharks

    http://www.aridocean.com/info_aridocean_en.htm

    have a nice day, good week-end, ciao, Lionheart
    It will be worth waiting for the 2d module Mike and Petr are working on. I am sure it will make things a lot easier then.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10

    Re: my little track ai :)

    Quote Originally Posted by kent sarikaya
    It will be worth waiting for the 2d module Mike and Petr are working on. I am sure it will make things a lot easier then.
    It is not far, not far ...
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. my AI Track as exercise
    By Lionheart008 in forum TBGL General
    Replies: 5
    Last Post: 06-03-2010, 21:59

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
  •