Timing Question

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Timing Question

Postby Leadwerks » Thu May 17, 2018 3:35 am

What is the difference between calling NewtonUpdate(16.6666666) twice and calling NewtonUpdate(33.3333333) once? Is the first method more precise?
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: Timing Question

Postby Julio Jerez » Thu May 17, 2018 2:17 pm

I hope when you write 16.66 you mean 0.0156

you can do tow steps at 16.66 if you want to advance 33.33 ms

but the bets way to do it is using function.
NewtonSetNumberOfSubsteps (m_world, 2);

the you can run the step at 33.33 and it will do the tow step, saving few common thong that do no change per step.
for example the thread signaling and the transform update, and broad phase set up happen once,

also you simply your logic, is late you want more or lest physic simulation quality you call
NewtonSetNumberOfSubsteps (m_world, 3); or what ever count and bot more change needed.
in you interpolation core.

This is specially useful when you run the physics asynchronous, you get the 33.33 as long as the update can be completed in less time than that.
meaning the quality is independent of the simulation step as long as is can be completed in less that the time step.

The other way doin steps you will need to handle a lo of time u[date transform with in-between that will never be interpolated because the will happen is one frame. basically late for copies of transforms.

it is way simpler using.
NewtonSetNumberOfSubsteps (m_world, n);
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Timing Question

Postby Leadwerks » Fri May 18, 2018 9:26 am

Our new engine uses a game loop that can be set to run at 30 or 60 hz. The physics will update once per loop. So I should do like this?:

Code: Select all
void World::Update(const int frequency)
{
   switch (frequency)
   {
   case 30:
      NewtonSetNumberOfSubsteps(2);
      NewtonUpdate(0.3333);
      break;
   case 60:
      NewtonSetNumberOfSubsteps(1);
      NewtonUpdate(0.01667);
      break;
   }
}
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: Timing Question

Postby Julio Jerez » Fri May 18, 2018 10:05 am

for the update loop
Code: Select all
{
   switch (frequency)
   {
   case 30:
      NewtonUpdate(0.03333);
      break;
   case 60:
      NewtonUpdate(0.01667);
      break;
   }
}


and some where in the setup outside the update loop
Code: Select all
void World::Update(const int frequency)
{
   switch (frequency)
   {
   case 30:
      NewtonSetNumberOfSubsteps(2);
      break;
   case 60:
      NewtonSetNumberOfSubsteps(1);
      break;
   }
}
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Timing Question

Postby MeltingPlastic » Fri Jun 15, 2018 1:45 pm

I am having trouble getting consistent behalvior with varying the substeps. I am not currently using Asynchronous updates but rather have one setup function and an update function that gets called every ~16ms.
Setup Code:
Code: Select all
    void NewtonPhysicsWorld::OnSceneSet(Scene* scene)
    {
        if (scene) {
            //create the newton world
            if (newtonWorld_ == nullptr) {
                newtonWorld_ = NewtonCreate();
                NewtonSetSolverModel(newtonWorld_, 4);
                NewtonSetNumberOfSubsteps(newtonWorld_, 1);
            }
        }
        else
        {
            freeWorld();
        }
    }


Update Code:
Code: Select all
    //gets called every 16 ms.
    void NewtonPhysicsWorld::HandleUpdate(StringHash eventType, VariantMap& eventData)
    {
        //use target time step to give newton constant time steps. timeStep = 0.01666666 in seconds.
        float timeStep = eventData[Update::P_TARGET_TIMESTEP].GetFloat();

        NewtonUpdate(newtonWorld_, timeStep);
        NewtonWaitForUpdateToFinish(newtonWorld_);
    }


When I have the substeps set to 1 I get bouncy behavior on my cube stack as well as some instability.
when I increase the substeps to say 4 I get slower and slower gravitational effects and less bounciness.

The effect seems to be similar (but not the same) if I call NewtonUpdate 4 times with timeStep/4.




I am using the 3.14 version of newton tagged in github.
MeltingPlastic
 
Posts: 237
Joined: Fri Feb 07, 2014 11:30 pm

Re: Timing Question

Postby Julio Jerez » Fri Jun 15, 2018 2:08 pm

you should sync to the current version on GitHub,
the last 3.14 stable has some bug and will be replaced soon.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Timing Question

Postby MeltingPlastic » Fri Jun 15, 2018 7:10 pm

I have pulled from master with the latest. The demos compile fine for me using the premade projects. For my engine I maintain a branch that has the project/demo files stripped out as well as other things like GLFW, Imgui, etc.. stripped out. There is a custom CMake script that builds from the sdk source folder which has been working with the 3.14 version.

Right now I keep getting the error:
Code: Select all
...
...

2>dNewtonMesh.cpp
2>c:\users\casht\repos\greatgame\urho3d\source\thirdparty\newton-dynamics\sdk\dnewton\dnewtonarticulationmanager.h(31): error C2504: 'dCustomArticulaledTransformManager': base class undefined (compiling source file C:\Users\casht\Repos\greatgame\Urho3D\Source\ThirdParty\newton-dynamics\sdk\dNewton\dNewtonArticulationManager.cpp)

...
..


Where is dCustomArticulaledTransformManager defined? I can not find its definition anywhere in the source.

Cant wait to try out the new improvements!
MeltingPlastic
 
Posts: 237
Joined: Fri Feb 07, 2014 11:30 pm

Re: Timing Question

Postby MeltingPlastic » Sat Jun 16, 2018 7:36 pm

Alright I have gotten around the bug by removing dnewtonarticulationmanager.h/cpp from the build.

Things are working again! I still see behavioral differences when I increase the substep count. Also I get the following crash sometimes after I spawn a bunch of objects during runtime (below is a screenshot):

https://drive.google.com/file/d/1F4co8Xqb4pn-y88BJS_2_Zo8BWt6hJKM/view?usp=sharing

I had multithreading turned on to 4
MeltingPlastic
 
Posts: 237
Joined: Fri Feb 07, 2014 11:30 pm

Re: Timing Question

Postby Julio Jerez » Sat Jun 16, 2018 8:05 pm

are you spawning the objects form a newton call back?
is so, that will cause a random crash, you soudl put then on a list and the do the spawning when eth update returns or before the next update.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Timing Question

Postby MeltingPlastic » Sat Jun 16, 2018 11:10 pm

The only callback from newton I have doing anything is the ApplyForcesAndTorque callback and that only applies the gravitational forces.

I am creating the rigid bodies after/before the update is finished and I am calling NewtonWaitForUpdateToFinish() right after the call to update.
MeltingPlastic
 
Posts: 237
Joined: Fri Feb 07, 2014 11:30 pm

Re: Timing Question

Postby MeltingPlastic » Sat Jun 16, 2018 11:23 pm

The crash does seem to go away if I switch to normal NewtonUpdate instead of Asynchronous.
MeltingPlastic
 
Posts: 237
Joined: Fri Feb 07, 2014 11:30 pm

Re: Timing Question

Postby Julio Jerez » Sun Jun 17, 2018 12:09 am

do you have a test repro that I can run. a exe that link to the dll,
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Timing Question

Postby MeltingPlastic » Sun Jun 17, 2018 12:54 am

Here is the branch on the repo: https://github.com/TrevorCash/Urho3D/tree/ThirdParty/NewtonDynamics

you might need to use
Code: Select all
git submodule init
git submodule update


After the initial clone to get the newton source in.

After that you should just need to run cmake_win64.sh on windows. Then build and run the "11_Physics" demo which is under samples in the visual studio solution.

The newton integration itself is in the NewtonPhysicsWorld.h/cpp in the Urho3D subproject.
MeltingPlastic
 
Posts: 237
Joined: Fri Feb 07, 2014 11:30 pm

Re: Timing Question

Postby Julio Jerez » Sun Jun 17, 2018 1:41 am

that's to complicated, can just just make a binary executable that link to the newton DLL, I can debug for that, no need to install engine which is always a rabbithole for me and I do not have time for that.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Timing Question

Postby Sweenie » Mon Jun 18, 2018 8:13 am

MeltingPlastic wrote:I am having trouble getting consistent behalvior with varying the substeps. I am not currently using Asynchronous updates but rather have one setup function and an update function that gets called every ~16ms.
Setup Code:
Code: Select all
    void NewtonPhysicsWorld::OnSceneSet(Scene* scene)
    {
        if (scene) {
            //create the newton world
            if (newtonWorld_ == nullptr) {
                newtonWorld_ = NewtonCreate();
                NewtonSetSolverModel(newtonWorld_, 4);
                NewtonSetNumberOfSubsteps(newtonWorld_, 1);
            }
        }
        else
        {
            freeWorld();
        }
    }


Update Code:
Code: Select all
    //gets called every 16 ms.
    void NewtonPhysicsWorld::HandleUpdate(StringHash eventType, VariantMap& eventData)
    {
        //use target time step to give newton constant time steps. timeStep = 0.01666666 in seconds.
        float timeStep = eventData[Update::P_TARGET_TIMESTEP].GetFloat();

        NewtonUpdate(newtonWorld_, timeStep);
        NewtonWaitForUpdateToFinish(newtonWorld_);
    }


When I have the substeps set to 1 I get bouncy behavior on my cube stack as well as some instability.
when I increase the substeps to say 4 I get slower and slower gravitational effects and less bounciness.

The effect seems to be similar (but not the same) if I call NewtonUpdate 4 times with timeStep/4.




I am using the 3.14 version of newton tagged in github.


I've been tinkering a bit with Urho as well. Which event is your HandleUpdate-function subscribed to?
E_PHYSICSPRESTEP?
Just making sure HandleUpdate is actually called at even 16ms intervals and not at a variable rate which it would be if subscribed to E_SCENEUPDATE or E_SCENESUBSYSTEMUPDATE.
Sweenie
 
Posts: 498
Joined: Mon Jan 24, 2005 7:59 am
Location: Sweden

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 21 guests

cron