Lionheart008
06-03-2010, 01:33
http://community.thinbasic.com/index.php?topic=3279.msg24591;topicseen#new
thanks mainly here to eros, michael and petr for new thinbasic 1.8.0.0 update and tbgl section :) really good work!
thanks also for new overview (I think it's a good first start) to collect tbgl basics with various folders and themes with different knowledge for beginners, newbies or advanced users.
perhaps stan or denis (or another newbie with tbgl interests) can see how this tbgl "AI track" is working. I have modified the example from tbgl sample folder with a) second hovercraft object and b) other random behaviour and c) other waypoints and d) different speed. was just an exercise and I like this example! :)
'----------- test for AI hovercraft by lionheart :)
Uses "TBGL"
BEGIN CONST
' -- Scene IDs
%sScene = 1
' -- Entity IDs
%eCamera = 1
%eLight
%eHovercraft
%eHovercraft2
%eWayPointStart
%eWayPointStart2
END CONST
Randomize Timer
GLOBAL FrameRate AS DOUBLE
FUNCTION TBMAIN()
LOCAL hWnd As DWORD
' -- Create and show window
hWnd = TBGL_CreateWindowEx("frankos random Test for hovercraft elemental AI", 880, 620, 32, %TBGL_WS_WINDOWED 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_EntitySetPos(%sScene, %eLight, 15, 10, 5)
TBGL_NewList 1
TBGL_UseLighting %FALSE
TBGL_BeginPoly %GL_TRIANGLES
'TBGL_UseBlend %TRUE
TBGL_Vertex -0.08, -0.24
TBGL_Vertex 0.08, -0.24
TBGL_Vertex 0.00, 0.24
TBGL_EndPoly
'TBGL_UseBlend %FALSE
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
velocity As Double
END TYPE
dim HoverInfo as tHoverCraft
LOCAL x AS LONG
For x = %eHovercraft + 20 To %eHovercraft + 360
TBGL_EntityCreateDLSlot(%sScene, x, 0, 1)
TBGL_EntitySetColor(%sScene, x, Rnd(10,255), Rnd(10,255), Rnd(10,255))
' -- Assign data to it
with HoverInfo
.nextWayPoint = %eWayPointStart
.numWayPoint = 23
.tolerance = 0.9
.minSpeed = Rnd(60,190)*0.02
.maxSpeed = Rnd(400,450)*0.02
.steerFactor = Rnd(26,46)*0.02
.velocity = Rnd(360*(-0.1),360)
END WITH
TBGL_EntitySetUserData(%sScene, x, HoverInfo)
next
Local i As Long
For i = %eWayPointStart To %eWayPointStart + 23
TBGL_EntityCreateBox(%sScene, i, 0, 0.22, 0.22, 1)
TBGL_EntitySetColor(%sScene, i, 50, 180, 250)
Next
TBGL_NewList 2
TBGL_UseLighting %FALSE
TBGL_BeginPoly %GL_TRIANGLES
'TBGL_UseBlend %TRUE
TBGL_Vertex -0.18, -0.44
TBGL_Vertex 0.18, -0.44
TBGL_Vertex 0.00, 0.44
TBGL_EndPoly
'TBGL_UseBlend %FALSE
TBGL_UseLighting %TRUE
TBGL_EndList
Local y As Long
For y = %eHovercraft2 + 20 To %eHovercraft2 + 180
TBGL_EntityCreateDLSlot(%sScene, y, 0, 1)
TBGL_EntitySetColor(%sScene, y, Rnd(140,255), Rnd(100,255), Rnd(200,255))
' -- Assign data to it
With HoverInfo
.nextWayPoint = %eWayPointStart2
.numWayPoint = Rnd(4,14) '--->14
.tolerance = 0.68
.minSpeed = Rnd(20,80)*0.02
.maxSpeed = Rnd(200,250)*0.02
.steerFactor = Rnd(16,36)*0.04
.velocity = Rnd(160*(-0.1),360)
End With
TBGL_EntitySetUserData(%sScene, y, HoverInfo)
Next
' -- Hardcoded waypoints
TBGL_EntitySetPos(%sScene, %eWayPointStart+0, -2, 2, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+1, 0, 4, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+2, 4, 6, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+3, 6, 5, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+4, 10, 0, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+5, 13, 1, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+6, 14, 6, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+7, 12, 8, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+8, 8, 11, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+9, -6, 10, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+10, -12, 8, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+11, -13, 6, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+12, -10, 3, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+13, -7, 1, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+14, -8, -3, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+15, -10, -6, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+16, -8, -8, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+17, -1, -9, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+18, 11, -10, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+19, 12, -8, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+20, 9, -5, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+21, 3, -2, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+22, -6, -9, 0)
'------------------------------------------------------------
Local k As Long
For k = %eWayPointStart2 To %eWayPointStart2 + 23
TBGL_EntityCreateBox(%sScene, k, 0, 0.26, 0.26, 1)
TBGL_EntitySetColor(%sScene, k, 50, 50, 250)
Next
TBGL_EntitySetPos(%sScene, %eWayPointStart2+0, -4, 4, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+1, 2, 6, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+2, 6, 9, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+3, 8, 8, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+4, 11, 7, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+5, 14, 1, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+6, 18, 6, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+7, 11, 2, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+8, -9, 12, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+9, -6, 9, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+10, -12, 8, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+11, -14, 5, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+12, -11, 4, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+13, -8, 2, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+14, 8, -6, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+15, 10, -4, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+16, -6, -6, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+17, -2, -8, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+18, 6, -11, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+19, 4, -4, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+20, 12, -14, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+21, 4, -2, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+22, -7, -10, 0)
' -- Resets status of all keys
TBGL_ResetKeyState()
Local z, z1 As Long
Local v As Quad
v = 0.1+(Sin(24+GetTickCount/100*24))
'z1 = 0.01*Sin(0.01+Cos(GetTickCount/500)*100))
' -- Main loop
While TBGL_IsWindow(hWnd )
FrameRate = TBGL_GetFrameRate
TBGL_ClearFrame
' NOTE: Pointer offset from track-points
For z = %eHovercraft + 30 To %eHovercraft + 280
HoverCraft_AI(z)
Next
For z1 = %eHovercraft2 + 20 To %eHovercraft2 + 140
HoverCraft_AIX(z*v)
Next
'HoverCraft_AI(%eHovercraftMedium)
'HoverCraft_AI(%eHovercraftLazy)
TBGL_SceneRender(%sScene)
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
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*(Min(hoverData.minSpeed+(distance*6), hoverData.maxSpeed*2))*angle)/FrameRate)
TBGL_EntityPush(%sScene, entity, 0, Min(hoverData.minSpeed+(distance*6), hoverData.maxSpeed)/FrameRate, 0)
' -- Check for next waypoints
If distance < hoverData.tolerance Then
If hoverData.nextWayPoint < %eWayPointStart+hoverData.numWayPoint Then
Incr hoverData.nextWayPoint
else
hoverData.nextWayPoint = %eWayPointStart
END IF
END IF
END SUB
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub HoverCraft_AIX( entity2 As Long )
Local hoverData As tHoverCraft Ptr
Local v As Quad
v = 0.75+(Sin(12+GetTickCount/200*12))
' -- Retrieve data from entity
hoverData = TBGL_EntityGetUserDataPointer(%sScene, entity2)
' -- Get angle and distance to next waypoint
Local angle As Double = TBGL_EntityGetAngleXY(%sScene, entity2, hoverData.nextWayPoint, %TBGL_Y) ' -- The front part is on Y axis
Local distance As Double = TBGL_EntityGetDistance(%sScene, entity2, hoverData.nextWayPoint)
'Local velocity As Double = TBGL_EntityFindNearest(%sScene, entity2, hoverData.nextWayPoint,hoverData.nextWayPoint,Rnd(1,2),2)
Local angle2 As Double = TBGL_EntityGetAngleXY(%sScene, entity2, hoverData.nextWayPoint*Rnd(1,4), %TBGL_X) ' -- The front part is on Y axis
' -- Move according to parametrization
TBGL_EntityTurn(%sScene, entity2, 0, 0, (hoverData.steerFactor*(Min(hoverData.minSpeed+(distance*-0.18), hoverData.maxSpeed*6))*angle*v)/FrameRate)
TBGL_EntityPush(%sScene, entity2, 0, Min(hoverData.minSpeed*-0.01+(distance*7), hoverData.maxSpeed)/FrameRate, 0)
' -- Check for next waypoints
If distance < hoverData.tolerance Then
If hoverData.nextWayPoint < %eWayPointStart2+hoverData.numWayPoint Then
Incr hoverData.nextWayPoint
Else
hoverData.nextWayPoint = %eWayPointStart2
End If
End If
End Sub
one favour: can anybody test this example if it's running fine ? sometimes it's running without problems, next time I cannot start it, don't know why. may be my notebook is having a big cold ;) or it's myself ?
good night, frank
thanks mainly here to eros, michael and petr for new thinbasic 1.8.0.0 update and tbgl section :) really good work!
thanks also for new overview (I think it's a good first start) to collect tbgl basics with various folders and themes with different knowledge for beginners, newbies or advanced users.
perhaps stan or denis (or another newbie with tbgl interests) can see how this tbgl "AI track" is working. I have modified the example from tbgl sample folder with a) second hovercraft object and b) other random behaviour and c) other waypoints and d) different speed. was just an exercise and I like this example! :)
'----------- test for AI hovercraft by lionheart :)
Uses "TBGL"
BEGIN CONST
' -- Scene IDs
%sScene = 1
' -- Entity IDs
%eCamera = 1
%eLight
%eHovercraft
%eHovercraft2
%eWayPointStart
%eWayPointStart2
END CONST
Randomize Timer
GLOBAL FrameRate AS DOUBLE
FUNCTION TBMAIN()
LOCAL hWnd As DWORD
' -- Create and show window
hWnd = TBGL_CreateWindowEx("frankos random Test for hovercraft elemental AI", 880, 620, 32, %TBGL_WS_WINDOWED 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_EntitySetPos(%sScene, %eLight, 15, 10, 5)
TBGL_NewList 1
TBGL_UseLighting %FALSE
TBGL_BeginPoly %GL_TRIANGLES
'TBGL_UseBlend %TRUE
TBGL_Vertex -0.08, -0.24
TBGL_Vertex 0.08, -0.24
TBGL_Vertex 0.00, 0.24
TBGL_EndPoly
'TBGL_UseBlend %FALSE
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
velocity As Double
END TYPE
dim HoverInfo as tHoverCraft
LOCAL x AS LONG
For x = %eHovercraft + 20 To %eHovercraft + 360
TBGL_EntityCreateDLSlot(%sScene, x, 0, 1)
TBGL_EntitySetColor(%sScene, x, Rnd(10,255), Rnd(10,255), Rnd(10,255))
' -- Assign data to it
with HoverInfo
.nextWayPoint = %eWayPointStart
.numWayPoint = 23
.tolerance = 0.9
.minSpeed = Rnd(60,190)*0.02
.maxSpeed = Rnd(400,450)*0.02
.steerFactor = Rnd(26,46)*0.02
.velocity = Rnd(360*(-0.1),360)
END WITH
TBGL_EntitySetUserData(%sScene, x, HoverInfo)
next
Local i As Long
For i = %eWayPointStart To %eWayPointStart + 23
TBGL_EntityCreateBox(%sScene, i, 0, 0.22, 0.22, 1)
TBGL_EntitySetColor(%sScene, i, 50, 180, 250)
Next
TBGL_NewList 2
TBGL_UseLighting %FALSE
TBGL_BeginPoly %GL_TRIANGLES
'TBGL_UseBlend %TRUE
TBGL_Vertex -0.18, -0.44
TBGL_Vertex 0.18, -0.44
TBGL_Vertex 0.00, 0.44
TBGL_EndPoly
'TBGL_UseBlend %FALSE
TBGL_UseLighting %TRUE
TBGL_EndList
Local y As Long
For y = %eHovercraft2 + 20 To %eHovercraft2 + 180
TBGL_EntityCreateDLSlot(%sScene, y, 0, 1)
TBGL_EntitySetColor(%sScene, y, Rnd(140,255), Rnd(100,255), Rnd(200,255))
' -- Assign data to it
With HoverInfo
.nextWayPoint = %eWayPointStart2
.numWayPoint = Rnd(4,14) '--->14
.tolerance = 0.68
.minSpeed = Rnd(20,80)*0.02
.maxSpeed = Rnd(200,250)*0.02
.steerFactor = Rnd(16,36)*0.04
.velocity = Rnd(160*(-0.1),360)
End With
TBGL_EntitySetUserData(%sScene, y, HoverInfo)
Next
' -- Hardcoded waypoints
TBGL_EntitySetPos(%sScene, %eWayPointStart+0, -2, 2, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+1, 0, 4, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+2, 4, 6, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+3, 6, 5, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+4, 10, 0, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+5, 13, 1, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+6, 14, 6, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+7, 12, 8, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+8, 8, 11, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+9, -6, 10, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+10, -12, 8, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+11, -13, 6, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+12, -10, 3, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+13, -7, 1, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+14, -8, -3, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+15, -10, -6, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+16, -8, -8, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+17, -1, -9, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+18, 11, -10, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+19, 12, -8, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+20, 9, -5, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+21, 3, -2, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart+22, -6, -9, 0)
'------------------------------------------------------------
Local k As Long
For k = %eWayPointStart2 To %eWayPointStart2 + 23
TBGL_EntityCreateBox(%sScene, k, 0, 0.26, 0.26, 1)
TBGL_EntitySetColor(%sScene, k, 50, 50, 250)
Next
TBGL_EntitySetPos(%sScene, %eWayPointStart2+0, -4, 4, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+1, 2, 6, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+2, 6, 9, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+3, 8, 8, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+4, 11, 7, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+5, 14, 1, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+6, 18, 6, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+7, 11, 2, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+8, -9, 12, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+9, -6, 9, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+10, -12, 8, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+11, -14, 5, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+12, -11, 4, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+13, -8, 2, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+14, 8, -6, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+15, 10, -4, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+16, -6, -6, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+17, -2, -8, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+18, 6, -11, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+19, 4, -4, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+20, 12, -14, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+21, 4, -2, 0)
TBGL_EntitySetPos(%sScene, %eWayPointStart2+22, -7, -10, 0)
' -- Resets status of all keys
TBGL_ResetKeyState()
Local z, z1 As Long
Local v As Quad
v = 0.1+(Sin(24+GetTickCount/100*24))
'z1 = 0.01*Sin(0.01+Cos(GetTickCount/500)*100))
' -- Main loop
While TBGL_IsWindow(hWnd )
FrameRate = TBGL_GetFrameRate
TBGL_ClearFrame
' NOTE: Pointer offset from track-points
For z = %eHovercraft + 30 To %eHovercraft + 280
HoverCraft_AI(z)
Next
For z1 = %eHovercraft2 + 20 To %eHovercraft2 + 140
HoverCraft_AIX(z*v)
Next
'HoverCraft_AI(%eHovercraftMedium)
'HoverCraft_AI(%eHovercraftLazy)
TBGL_SceneRender(%sScene)
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
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*(Min(hoverData.minSpeed+(distance*6), hoverData.maxSpeed*2))*angle)/FrameRate)
TBGL_EntityPush(%sScene, entity, 0, Min(hoverData.minSpeed+(distance*6), hoverData.maxSpeed)/FrameRate, 0)
' -- Check for next waypoints
If distance < hoverData.tolerance Then
If hoverData.nextWayPoint < %eWayPointStart+hoverData.numWayPoint Then
Incr hoverData.nextWayPoint
else
hoverData.nextWayPoint = %eWayPointStart
END IF
END IF
END SUB
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub HoverCraft_AIX( entity2 As Long )
Local hoverData As tHoverCraft Ptr
Local v As Quad
v = 0.75+(Sin(12+GetTickCount/200*12))
' -- Retrieve data from entity
hoverData = TBGL_EntityGetUserDataPointer(%sScene, entity2)
' -- Get angle and distance to next waypoint
Local angle As Double = TBGL_EntityGetAngleXY(%sScene, entity2, hoverData.nextWayPoint, %TBGL_Y) ' -- The front part is on Y axis
Local distance As Double = TBGL_EntityGetDistance(%sScene, entity2, hoverData.nextWayPoint)
'Local velocity As Double = TBGL_EntityFindNearest(%sScene, entity2, hoverData.nextWayPoint,hoverData.nextWayPoint,Rnd(1,2),2)
Local angle2 As Double = TBGL_EntityGetAngleXY(%sScene, entity2, hoverData.nextWayPoint*Rnd(1,4), %TBGL_X) ' -- The front part is on Y axis
' -- Move according to parametrization
TBGL_EntityTurn(%sScene, entity2, 0, 0, (hoverData.steerFactor*(Min(hoverData.minSpeed+(distance*-0.18), hoverData.maxSpeed*6))*angle*v)/FrameRate)
TBGL_EntityPush(%sScene, entity2, 0, Min(hoverData.minSpeed*-0.01+(distance*7), hoverData.maxSpeed)/FrameRate, 0)
' -- Check for next waypoints
If distance < hoverData.tolerance Then
If hoverData.nextWayPoint < %eWayPointStart2+hoverData.numWayPoint Then
Incr hoverData.nextWayPoint
Else
hoverData.nextWayPoint = %eWayPointStart2
End If
End If
End Sub
one favour: can anybody test this example if it's running fine ? sometimes it's running without problems, next time I cannot start it, don't know why. may be my notebook is having a big cold ;) or it's myself ?
good night, frank