Quaternion accuracy

pratty70

04-10-2006 15:29:14

We are developing a system requiring physics simulation with guaranteed consistent results (i.e. the same outcome every time). We are employing OgerNewt to do just that.

We are using cylinders and tree collision objects within the scene, positioned from information provided in a config file, including position and orientation.

We are now firing objects into the scene and have noticed something quite strange!! We have a scene symmetrical about the Y axis. When injecting objects into the scene at one side of the symetrical mesh we log a set of results which differ from the ones on the other side of the mesh!!

We have done various tests breaking the scene down and have determined that by placing the objects using setpositionorientation - if a quaternion rotation is required on an object - it behaves differently in the scene after the rotation. We have determined that (due to rounding errors??) the eventual orientation of rotated objects is not exact - and although only a by a very small fraction - it is enough to cause a different outcome of the physics. Our system is dependant on the outcome being the same at both sides of the mesh.

Should we expect this kind of result?

Any thoughts or help greatly appreciated.

HexiDave

04-10-2006 16:12:05

As far as I know, those rotation values are floats, so keep in mind that you're eventually going to have some degredation. First important thing to check is if you have Floating-Point mode set to Consistant when you run your program - Ogre chops up floating point values even more for speed purposes if it's set to Fastest. Next, you could go through OgreNewt and try to convert everything to double precision - I'm not sure how Newton handles doubles, or if it does at all, but in dealing with computer simulations you're very unlikely to get 100% precise results every time due to floating point issues.

If you're not working on a game, you're more likely going to want something built from scratch or maybe a physics engine designed for incredibly precise results. The other thing you could do, if you're after just symetrical results is take one side as the basis and use setPositionOrientation for each mirror object - just reverse everything down the axis - and it'll always be as precise as one side.

I don't know enough about your project to give you better information, but Ogre does have the option to be compiled such that all Real's are doubles instead of floats, so look into that as well.

pratty70

04-10-2006 16:41:37

Thanks for the tips. Looking through the Ogre forums, Consistant floating point mode is for D3D, and we're using Open GL - so not sure if we can benefit from it. Playing around with it now.

We could live with small discrepencies in the outcome, but the discrepencies we are getting seem too far out to be due to rounding errors.

Looking at Stunt Playground, it seems that Walaber prefers building rotation matrices and then producing quaternions from these - rather than using FromAngleAxis which is what we're currently using.

Still plodding on doing some testing!!......

pratty70

06-10-2006 10:51:10

Just to add a bit of padding to the information I have already provided. We have now rebuilt the environment so that nothing required rotations. All meshes were built in the correct orientation and placed raw into the scene.

The scenario we have is a cylinder (created with a cylinder primitive) being fired (by giving the cylinder a Y velocity) up the line of a curve generated as a mesh and loaded in as treecollision. When the cylinder "hits" the curve of the edge it starts to spin (due to friction) and follows the line of the curve, but despite the curve being perfectly flat surface across the Z axis, the cylinder picks up a Z component at the point of collision and begins to drift off path in the Z axis. This is not what we want - we want it to remain true for Z as it rolls around the curve.

We have determined that all the normals are being exported correctly from the milkshape mesh.

Any thoughts or should we expect this behaviour?

Sweenie

06-10-2006 11:23:03

I'm having a hard time picturing the scene with the cylinder(screenshot would help), but regarding the unpredictable outcome, do you update Newton at fixed timesteps?

walaber

06-10-2006 18:49:41

any chance of a screenshot or short video to show the problem?

pratty70

10-10-2006 09:27:59

Don't want to give too much of the game idea away - so need to hide some of it - this will be a commercial application - and the game concept is to be kept confdidential.

I will endeavour to provide a simplified video of what's happening to demonstrate asap.