Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: [SOLVED - Not a BUG] TVPath and Mesh.SetSpeed  (Read 7571 times)
António Mateus
Community Member
*
Posts: 58


WWW
« on: October 20, 2010, 05:16:16 AM »

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.

Code:
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
« Last Edit: October 21, 2010, 03:54:49 AM by António Mateus » Logged
asia
Customers
Community Member
*****
Posts: 183


« Reply #1 on: October 20, 2010, 07:58:55 AM »

I think the speed is related to the segment lenght to follow. It is something like a fraction of that lenght. If segment A is double of segment B then the speed will be double following segment A than will be in B. So I did normalize the speed to such a lenght for every segment the mesh is following...I do not if this is clear...
Bye
Logged

Fabio Musmeci
ENEA
CR Casaccia
Via Anguillarese 301
00060 Rome
Italy
musmeci@enea.it
+39 3333934898
Learning to live better on a smaller footprint..
António Mateus
Community Member
*
Posts: 58


WWW
« Reply #2 on: October 20, 2010, 08:34:54 AM »

Sorry, I didn't understand anything.

Can you please be a little more specific?

Thank You Smiley
Logged
António Mateus
Community Member
*
Posts: 58


WWW
« Reply #3 on: October 20, 2010, 02:51:59 PM »

Ok, more information:

I discovered that if I set VSync(True) the movement is correct, but the movement is different from computer to computer, and that should not happen because the use of the AccurateTimeElapsed() function. The behavior is the same as if the AccurateTimeElapsed() function was used.

Any ideas?
Logged
jviper
Community Member
*
Posts: 2131

Discipline in training


« Reply #4 on: October 20, 2010, 03:36:23 PM »

I think what asia was trying to say was, if you are using SetSpeed, that means you already know the speed, which should not involve how much time has passed, which is what both AccurateTimeElapsed() and GetElapsedTime are supposed to do. You only need to know how much time has passed when you are changing the PathPosition manually
Code:
sngCurrentPathPosition += AccurateTimeElapsed()*sngSpeedAlongPath
.SetPathPosition(sngCurrentPathPosition)
What you really want to do is
Code:
.SetPathSpeed(sngSpeedAlongPath)
What you were doing by this code
Code:
.SetPathSpeed(AccurateTimeElapsed()*sngSpeedAlongPath
was setting the acceleration along the path, ---- without updating the speed......hmmm
if you do .SetPathSpeed(sngSomeConstantNumber) and your meshes do not move (stay in the same position along the path), that means the .SetPathSpeed is bugged, because that would mean it's setting the path position and not the path speed.

Also, if you do that and meshes move at different speeds (along the path) for different machines (or even different meshes on the same machine), there may be somthing wrong with how timing is being used in that function.
« Last Edit: October 20, 2010, 03:38:28 PM by jviper » Logged

JAbstract.....Don't just imagine, make it happen!
António Mateus
Community Member
*
Posts: 58


WWW
« Reply #5 on: October 20, 2010, 03:54:12 PM »

Thanks for your answers, but I'm afraid it's not that simple (or maybe I'm not understanding correctly).

First, I'm not updating the path manually: SetSpeed is called at the beginning with a given speed*speedfactor *and* it's indicated that the movement should be constant along the path. Then I just render the mesh and TV do all the work.

If I set VSync then the movement is correct for all the meshes along the path, but it differs from machine to machine. This would be normal if I just give it a constant value, but since I use * speedfactor it should move at the same speed on all machines.

For example, the mesh that is controlled by the keyboard, no matter what configuration I setup, always move at the same speed.

Don't know how to explain clearer, because the sample I provided gives a proof of concept of the problem.

I really just want to know if this is my problem (maybe I could misunderstood the use of the commands) or a tv bug Smiley

But for that we need Sylvain, or someone with more knowledge in the subject than me.

Thanks
Logged
serial
Customers
Community Member
*****
Posts: 380


« Reply #6 on: October 20, 2010, 10:17:27 PM »

Well look at what AccurateTimeElapsed() returns and what you are doing in your example.

"Returns the number of milliseconds passed since the last time it was called."

Of course your balls move at differant speeds unless you are able to accuratly whack the 0 key with exactly the same time interval in between.

You would have to be able to press the 0 key with the exact same amount of time in between each key press.

To prove it hit the 0 button once. Wait 2 seconds hit it again.  Wait 4 seconds hit it again.  I bet the 3rd ball is moving about twice as fast as the second ball. 

AccurateTimeElapsed is meant to be called every frame. 


Logged
António Mateus
Community Member
*
Posts: 58


WWW
« Reply #7 on: October 21, 2010, 03:53:47 AM »

Agreed.

The problem is that SetSpeedPath already use AccurateTimeElapsed() internally so we just need to give a constant value to the function independently of the machine.

Thanks for the help *and* thanks for the guys last nigt on irc Smiley

Feel free to move the post to another category, since this is not a bug.

AMateus
Logged
serial
Customers
Community Member
*****
Posts: 380


« Reply #8 on: October 22, 2010, 02:14:08 AM »

Do you mean that SetSpeed has a mechanic that smooths movement speed out independant of FPS? 

Or does it actually call AccurateTimeElapsed()?

If the second statement is true does the AccurateTimeElapsed() called by the SetSpeed function affect AccurateTimeElapsed if it is called else where?

Logged
António Mateus
Community Member
*
Posts: 58


WWW
« Reply #9 on: October 22, 2010, 04:26:43 AM »

Do you mean that SetSpeed has a mechanic that smooths movement speed out independant of FPS? 

Or does it actually call AccurateTimeElapsed()?

If the second statement is true does the AccurateTimeElapsed() called by the SetSpeed function affect AccurateTimeElapsed if it is called else where?

According to Sylvain, SetSpeedPath uses AccurateTimeElapsed() internally. And no, it does not affect other AccurateTimeElapsed() calls.

Regards,
AMateus
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks