-1

I'm using the Ammo.js physics library (https://github.com/kripken/ammo.js/)

Here's an example of the problem:

const a = [-0.0000064798259700182825, -0.0013201627880334854, 0.0000027575993044592906, 0.9999991059303284]
const t = new Ammo.btTransform();
t.setIdentity();
const q = new Ammo.btQuaternion(a[0], a[1], a[2], a[3])
t.setRotation(q)
const r = t.getRotation()
assert(a[0] === r.x()) // fails here as r.x() === -0.000006479827334260335
assert(a[1] === r.y())
assert(a[2] === r.z())
assert(a[3] === r.w())

I was expecting to get the same values for the rotation as I had set, but didn't get them. I've also tried normalizing the quaternion first, but that was not the problem. Any advice would be much appreciated!

Aaron Meese
  • 1,670
  • 3
  • 22
  • 32
Steve Dekorte
  • 79
  • 1
  • 4

1 Answers1

0

This isn't an issue with the library, but rather a limitation of JavaScript. To achieve arbitrary-precision decimal arithmetic in JavaScript, you should check out this answer. Unfortunately it is unlikely that any of those libraries will be compatible with ammo.js, so I'm not going to bother including those code samples in this answer.

For your specific library, this issue explains how to use double precision instead of float precision. As the thread explains, you will need to modify the btScalar.h file to turn on BT_USE_DOUBLE_PRECISION. The author also mentions possibly needing a modification to the ammo.idl file, but does not go into further detail.

For further support I recommend either reaching out to the author on that issue (which closed in 2020) or creating your own issue requesting more detail on how to make the necessary changes.

Aaron Meese
  • 1,670
  • 3
  • 22
  • 32