Physics and network

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Physics and network

Postby Crashy » Wed Nov 21, 2012 8:33 am

Hi everybody,

I'm currently trying to use networking in a client/server architecture, I've tested two solutions for the physic part of the netcode, and both have problems:

-First solution is that each player controlls and simulate his own aircraft, the server only dispatch the player's position/orientation and velocity/omega to the other players. When a player receive another aircraft physical state, it estimates the actual position/orientation of the aircraft taking in account the travel time of the packet, and then apply a small impulse to make some corrections. Globally it works, but I have some stutters when the players are making tight turns. Another part of the problem is that I don't know how to calculate the impulse apply point so that the orientation of the aircraft is corrected too and for now, orientation is corrected by an "hard" correction, interpolating between the client-side aircraft orientation and the estimated orientation of the other aircraft.

-Second solution is to compute physics only in server side, the clients only send their inputs to the server and get the aircrafts position, orientation, velocity and angular velocity from the server, make some small corrections, and between two packets reception transform the aircraft according to velocity/omega. This is working quite nice although I don't know to correctly fix the orientations. This solution is not my favourite, but I may be the easiest to fix.

Which way would you suggest me to follow, and is there another solution?

Thanks.

Thanks.
Crashy
 
Posts: 101
Joined: Fri Dec 03, 2010 6:30 am

Re: Physics and network

Postby Julio Jerez » Wed Nov 21, 2012 10:59 am

the second solution although it is simpler in reality is terrible. The reason for that is that is does nor scale with the size for the Game. It a global solution that does not understand the concept of locality. It does matter how fast the server is, it is simply a matter of adding few more players to slowing it down.

but let us first see how to solve the impulse correction problem.

Code: Select all
if you inputs are:
input: posit0, posit1, veloc, timeStep
then the linear veloc is
desiredVeloc = (posit1 - post0) * (1.0f/ timeStep) - veloc;
linearImpulse = desiredVeloc * mass;


for rotation, this is more involve but is very simulate to the above case
Code: Select all
input: quat0, quat1, omega, timestep
then the angular velocity is

desiredOmega = quat0.CalcAverageOmega(quat1, timestep) -  omega
Matrix matrix = GetBodyMatrix()
Vector Inertia = GetBodyInertia;

localOmega = matrix.Unrotate (desiredOmega)
angularLocalImpulse =  localOmega.ComponetPruduct (Inertia);
angularImpulse = matrix (angularLocalImpulse);

now you have the linear and angular impulse, that you need to achieve the desired omega and velocity
you can call this funtions

Code: Select all
NewtonBodyApplyImpulsePair (const NewtonBody* const bodyPtr, dFloat* const linearImpulse, dFloat* const angularImpulse)
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Physics and network

Postby Crashy » Wed Nov 21, 2012 11:33 am

Thanks for the tips, I'm going to test it.

BTW, CalcAverageOmega does nothing in core 300, everything is commented, but I think I understand what it does;
Crashy
 
Posts: 101
Joined: Fri Dec 03, 2010 6:30 am

Re: Physics and network

Postby Julio Jerez » Wed Nov 21, 2012 11:48 am

what cpp file are you lokking at?
this is what I have: ..\packages\dMath\dQuaternion.cpp

Code: Select all
dVector dQuaternion::CalcAverageOmega (const dQuaternion &q1, dFloat dt) const
{
   dQuaternion q0 (*this);
   if (q0.DotProduct (q1) < 0.0f) {
      q0.Scale(-1.0f);
   }
   dQuaternion dq (q0.Inverse() * q1);
   dVector omegaDir (dq.m_q1, dq.m_q2, dq.m_q3);

   dFloat dirMag2 = omegaDir % omegaDir;
   if (dirMag2   < dFloat(dFloat (1.0e-5f) * dFloat (1.0e-5f))) {
      return dVector (dFloat(0.0f), dFloat(0.0f), dFloat(0.0f), dFloat(0.0f));
   }

   dFloat dirMagInv = dFloat (1.0f) / dSqrt (dirMag2);
   dFloat dirMag = dirMag2 * dirMagInv;

   dFloat omegaMag = dFloat(2.0f) * dAtan2 (dirMag, dq.m_q0) / dt;
   return omegaDir.Scale (dirMagInv * omegaMag);
}
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Physics and network

Postby d.l.i.w » Wed Nov 21, 2012 12:02 pm

A bit off-topic and more general, but worth reading:
http://gafferongames.com/game-physics/networked-physics/
[There are some more interesting texts on this page]
d.l.i.w
 
Posts: 81
Joined: Mon Sep 26, 2011 4:35 am

Re: Physics and network

Postby Crashy » Wed Nov 21, 2012 2:45 pm

@d.l.i.w : yes I've read this link multiple times and it was very helpfull, but some points aren't that clear :)

@Julio: ok I wasn't looking in the right dgQuaternion.cpp file.

BTW I inform you that your code works like a charm for the moment, I have no more stutters. I'm doing a huge stress test this evening, but I'm confident.
Thank you Julio, you're really helpfull, as always :)
Crashy
 
Posts: 101
Joined: Fri Dec 03, 2010 6:30 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest