Hello,
I have a weird problem (dont know if it's a bug or not, but is definitely a tv behavior and not from my code) with TVPath, Mesh.SetSpeed and AccurateTimeElapsed().
So the goal is to have N meshes moving along the tvpaths nodes at a constant speed, but the meshes do not move at a constant speed when AccurateTimeElapsed() is used in the SetSpeed command.
Bellow is a proof of concept. Just create a form and paste the code, then press 0 several times and you will see that some spheres have different speeds. Replace the line that uses AccurateTimeElapsed() with the one that does not (adjust the value for your computers because this value must be configured for each computer - that's why the AccurateTimeElapsed() is supposed to be used) and you will see that the movement is constant.
Public Class Form1
Public tv As TVEngine
Public inp As TVInputEngine
Public screen2d As TVScreen2DImmediate
Public scene As TVScene
Public path As TVPath
Dim lLoop As Boolean = True
Dim coord As ArrayList
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tv = New TVEngine()
inp = New TVInputEngine
screen2d = New TVScreen2DImmediate
scene = New TVScene
Me.Show()
tv.SetDebugMode(True)
tv.DisplayFPS(True)
tv.Init3DWindowed(Me.Handle, True)
tv.SetAngleSystem(CONST_TV_ANGLE.TV_ANGLE_DEGREE)
inp.Initialize(True, True)
coord = New ArrayList()
coord.Add(New TV_3DVECTOR(0, 0, 0))
coord.Add(New TV_3DVECTOR(100, 0, 0))
coord.Add(New TV_3DVECTOR(100, 0, 100))
coord.Add(New TV_3DVECTOR(0, 0, 100))
scene.GetCamera.SetPosition(50, 150, 50)
scene.GetCamera.SetRotation(90, 0, 0)
path = New TVPath()
For Each c As TV_3DVECTOR In coord
path.AddPathNode(c)
Next
While lLoop
GetInput()
tv.Clear()
scene.RenderAllMeshes()
screen2d.Draw_Line3D(coord(0).x, coord(0).y, coord(0).z, coord(1).x, coord(1).y, coord(1).z)
screen2d.Draw_Line3D(coord(1).x, coord(1).y, coord(1).z, coord(2).x, coord(2).y, coord(2).z)
screen2d.Draw_Line3D(coord(2).x, coord(2).y, coord(2).z, coord(3).x, coord(3).y, coord(3).z)
screen2d.Draw_Line3D(coord(3).x, coord(3).y, coord(3).z, coord(0).x, coord(0).y, coord(0).z)
tv.RenderToScreen()
Application.DoEvents()
End While
tv.ReleaseAll()
Application.Exit()
End Sub
Private Sub GetInput()
Dim aKeyBuffer As Array = New TV_KEYDATA(255) {}
Dim iBufferCount As Integer = 0
Dim iKey As Integer
With inp
.ForceUpdate()
.GetKeyBuffer(aKeyBuffer, iBufferCount)
For i As Integer = 0 To iBufferCount - 1
If DirectCast(aKeyBuffer.GetValue(i), TV_KEYDATA).Pressed <> 0 Then
iKey = CInt(DirectCast(aKeyBuffer.GetValue(i), TV_KEYDATA).Key)
Select Case iKey
Case CONST_TV_KEY.TV_KEY_0
CreateMesh()
End Select
End If
Next
End With
If inp.IsKeyPressed(CONST_TV_KEY.TV_KEY_ESCAPE) Then
lLoop = False
End If
End Sub
Private Sub CreateMesh()
Dim mesh As TVMesh = scene.CreateMeshBuilder()
With mesh
.CreateSphere(5)
.SetPath(path, True)
.SetPathSpeed(20 * tv.AccurateTimeElapsed(), True)
'.SetPathSpeed(20, True)
End With
End Sub
End Class
So, any ideas? Why the speed is different for each sphere. If it's a expected behavior, how to make all the spheres have the same movement?
I'm clueless here.
Thanks,
AMateus