Simulating single bodies

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Simulating single bodies

Postby Boost113 » Sun Dec 14, 2014 2:50 pm

Hey guys,

I've been lately working on networking and I'm currently trying to get all clients to synchronize their Newton simulation with a server. Many people have suggested (for networked physics in general) that the clients should compare past positions with ones that they receive from the server and then resimulate if needed by moving the object to a position received from the server and simulate its movement for how much time the server position is in the past.
Is there a way to do this with newton (without disabling all other bodies in the world)?

As far as I can tell there doesn't seem to be a function to simulate a single body in a world. Another approach could be to use forces and try to move bodies towards their "actual" positions that way.
What would be the best way to handle this?
thanks in advance
Boost113
 
Posts: 26
Joined: Thu Oct 23, 2014 3:24 am

Re: Simulating single bodies

Postby AntonSynytsia » Sun Dec 14, 2014 6:07 pm

You can use NewtonBodyGetSimulationState and NewtonBodySetSimulationState to enable/disable simulation of the desired bodies. IE you can disable simulation of all other player bodies while performing simulation of the current player body.

You can also use simulation islands. See this post for explanation by Juleo: viewtopic.php?f=9&t=6923&p=47975&hilit=NewtonSetIslandUpdateEvent#p47975
AntonSynytsia
 
Posts: 193
Joined: Sat Dec 28, 2013 6:36 pm

Re: Simulating single bodies

Postby Boost113 » Mon Dec 15, 2014 2:29 pm

I was kinda hoping that there was something more efficient than looping over all bodies and setting them disabled and then enabling a single body and running the simulation and afterwards enabling all bodies again.
The simulation islands would work if they grouped only the bodies that I want to be simulated otherwise some bodies would be simulated for too long when they get included in multiple resimulations.
Boost113
 
Posts: 26
Joined: Thu Oct 23, 2014 3:24 am

Re: Simulating single bodies

Postby Julio Jerez » Mon Dec 15, 2014 4:03 pm

There are no functions to update just one body, the engine updates a body and all it conections whis is call an island.

you could add for you own need if you want by talking the function and adding one like
UpdateDynamics (body, timesteo)

basically that function will find the island that the body belong to and uptake that island.
This is exactly how Continue collision works.

besaill you take function
void dgWorldDynamicUpdate::UpdateDynamics(dgFloat32 timestep)

and you modified so that is doe not execute look
Code: Select all
for (dgBodyMasterList::dgListNode* node = me.GetLast(); node; node = node->GetPrev()) {
...
}


Intead it simple Get the graphnode of that body and call
SpanningTree (dynamicBody, timestep); to build the island and the

call
CalculateReactionForcesParallel (&islandsArray[index], timestep);
of that island only.

inis jsu a patter of taking
void dgWorldDynamicUpdate::UpdateDynamics(dgFloat32 timestep)

changing so that is simple update one island,
the same apply the the broad phase part.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Simulating single bodies

Postby Boost113 » Wed Dec 17, 2014 2:51 pm

That could work quite nicely. I'll try creating that function...
Boost113
 
Posts: 26
Joined: Thu Oct 23, 2014 3:24 am

Re: Simulating single bodies

Postby Julio Jerez » Wed Dec 17, 2014 4:19 pm

what I could do is to add tow functions to the engine

void* NetwonGetForstIsaland()
void* NetwonGetNextIsaland(void island)
void* NetwonGetBodyIsandl (netwonBody* body)
NetwponUpdateIsland (void Island)

with those you can advance the just what you want, will that help?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Simulating single bodies

Postby Boost113 » Thu Dec 18, 2014 10:36 am

Yes, that would be great.
Boost113
 
Posts: 26
Joined: Thu Oct 23, 2014 3:24 am

Re: Simulating single bodies

Postby Boost113 » Sat Dec 20, 2014 10:17 am

I tried creating that function and duplicating all the functions through which it is called.
I think I got most of it done except for the broadphase as I can't figure out how I can filter out sync points that don't contain the wanted body.
https://github.com/Boost113/newton-dynamics/compare/MADEAPPS:master...master

I'm done trying to get it working right now but I'll check back once I get few other things done and actually need to simulate single bodies.
Boost113
 
Posts: 26
Joined: Thu Oct 23, 2014 3:24 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 4 guests