Manual integration question (for objects outside the world)

Project5

30-04-2006 16:10:05

I ran into a quandry, and figured that someone on here would know more than me about this sort of thing :-)

I'm running a network simulation, and use client prediction for each client. So each client has a Newton simulation running for the objects immediately around that player. The trouble is that each player is in a different location, and so has their Newton world centered in a different place than all other clients.

This trouble happens when one client gets a network update for an object to move outside that client's Newton world. The system will place the object there, and Newton will tell me that it left the world, and then not move it any more.

This has the result that distant objects seem to lurch across the client's field of view instead of moving smoothly, much as expected when objects leave Newton's world and go to sleep.

Assuming that I cannot increace Newton's world size due to processing power limitations, I tried moving the objects myself using simple euler integration and ignoring collisions, thinking that future network updates would correct from collisions I wasn't calculating, and even if it was incorrect, smooth non colliding motion looks less jarring than correct colliding motion at long distances.

Which brings me to the integration and my question. Thanks for staying with me so far :-)

Integrating linear movement is easy, I just keep track of what forces / impulses should be applied to a newton object and apply them myself.

Rotation has me a bit stumped. First, in what order are the values in Omega applied? My idea was to construct a rotation matrix or quaternion based on each of the x,y,and z values in Omega, multiply them by time, and add it to the current orientation. But combining rotations yields different results depending on what order they're applied. Does anyone know in what order Newton applies the rotations given in Omega?

Secondly, is the inertia vector normalized? i.e. do I need to multiply it by mass before using it?

Anything else I should be aware of? :-)

--Ben

walaber

30-04-2006 18:53:47

first one quick question. what size are you using for the local Newton world on each client?

as for Omega(), it is a vector describing the axis around which the object si currently rotating, and the magnitude determines the rotational velocity around that vector... so I think you could probably turn it into a quaternion by normalizing and using that as the axis, and then using the magnitude (length) as the W component.

as for inertia, yes I believe you do use it in place of mass when calculating the effects of torque, but I'm not 100% sure about that... that's why I use Newton :)

Project5

01-05-2006 15:33:28

Right now the Newton world is a cube, 4000 units to a side, more or less centered on the camera (the synch happens every now and again). In the scale I'm using, that's 4km, and it may be too large all ready depending on the number of objects in it. I read on Newton's boards that raising the world size slows Newton down. If that's not really the case (or not as pronounced as I assumed) then this is moot :-)

The simulation coordinate system type is larger than floats can handle reliably, and that's why I center everything around the camera for all of the external libraries I'm using, just giving them relative vectors. It is possible for some clients' worlds to be completely outside other client's worlds, and that's when I started looking into this :-)

Thanks for the heads up on Omega. Not at all what I expected :-)

On inertia, I just checked and Newton does use mass to calculate inertia, so you're right about the simple replacement.

Thanks for the help :-)

EDIT:
Actually, looking at OgreNewt::Body::addTorque() I have the same question as I did about Omega. In what order are the Torques applied, or is it handled as a magnitude vector as before?

--Ben

Project5

01-05-2006 19:28:45

In reply to myself, Newton's torque does work that way, which means that unless I sorely misunderstood something, this should work for manual integration:

Ogre::Real time = mManager->getTimeStep() / (Ogre::Real)1000;

position += velocity * time + (forces / mass * time * time * .5f);

velocity += forces / mass * time;

Ogre::Vector3 deltaOrientation = omega * time + (torques / inertia * time * time * .5f);
Ogre::Real mag = deltaOrientation->normalise();
orientation += Ogre::Quaternion(mag, deltaOrientation);

omega += (torques / inertia) * time;


For reference, position, velocity, omega, torques, and forces are all of type Ogre::Vector3. Orientation is a Quaternion.

Time for some testing, and if anyone finds a glaring physics problem with that, let me know :-)

--Ben

Project5

15-05-2006 04:42:21

And by anyone, I mean me.

That code will work for position / velocity / acceleration, but not for rotation. To see how to do it properly:
http://www.gaffer.org/articles/Physics3D.html

--Ben