I'm encountering behavior I don't understand using ammo.js (the Emscripten port of Bullet to JavaScript). I store each of the three rows of a btMatrix3x3 off in separate variables, but when I log the variables to the console, they all contain the values of the last row I accessed. For example, this code:
let transform = Ammo.btTransform();
transform.setIdentity();
const basis = transform.getBasis();
const row0 = basis.getRow(0);
const row1 = basis.getRow(1);
const row2 = basis.getRow(2);
console.log(row0.x() + "," + row0.y() + "," + row0.z());
console.log(row1.x() + "," + row1.y() + "," + row1.z());
console.log(row2.x() + "," + row2.y() + "," + row2.z());
prints 0,0,1 three times. However, this code:
const row0 = basis.getRow(0);
console.log(row0.x() + "," + row0.y() + "," + row0.z());
const row1 = basis.getRow(1);
console.log(row1.x() + "," + row1.y() + "," + row1.z());
const row2 = basis.getRow(2);
console.log(row2.x() + "," + row2.y() + "," + row2.z());
successfully prints 1,0,0\n0,1,0\n0,0,1.
My best guess is getRow is returning some reference to something internal to btMatrix3x3, and so my row variables all end up pointing to the same place, but I don't really know what's going on.
Can someone please explain what's happening so I can avoid being bitten by this in the future? Also, is there a way to do what I want and store off the three rows separately instead of processing them one at a time?