Havok buffer offsets for contact point

From the Babylon.js source shown below:

static readToRef(buffer: any, offset: number, eventOut: CollisionEvent) {
    const intBuf = new Int32Array(buffer, offset);
    const floatBuf = new Float32Array(buffer, offset);
    const offA = 2;
    eventOut.contactOnA.bodyId = BigInt(intBuf[offA]); //<todo Need to get the high+low words!
    eventOut.contactOnA.position.set(floatBuf[offA + 8], floatBuf[offA + 9], floatBuf[offA + 10]);
    eventOut.contactOnA.normal.set(floatBuf[offA + 11], floatBuf[offA + 12], floatBuf[offA + 13]);
    const offB = 18;
    eventOut.contactOnB.bodyId = BigInt(intBuf[offB]);
    eventOut.contactOnB.position.set(floatBuf[offB + 8], floatBuf[offB + 9], floatBuf[offB + 10]);
    eventOut.contactOnB.normal.set(floatBuf[offB + 11], floatBuf[offB + 12], floatBuf[offB + 13]);
    eventOut.impulseApplied = floatBuf[offB + 13 + 3];
    eventOut.type = intBuf[0];
}

we can see that the contact point

  • world position is located at floats # 8 - 10
  • normal is located at floats # 11 - 13

Would anyone know what data is located at floats # 2 - 7, # 13 - 15?

I’m looking for the local position of the contact point (different from the world position). Ammo provides both types of positions in its contact points, so I thought that some of these unknown floats may be the local position

@eoin @Cedric Apologies for the ping, I believe you have the expertise here :slight_smile:

Also, I was really curious about the comment //<todo Need to get the high+low words!. If you could please share, what is the meaning of these high+low words?

cc @Cedric (be patient he is on vacation) or @eoin maybe

1 Like

We never compute the local-space contact positions, but you can calculate them yourself by multiplying the world positions by the inverse transform of the body.

Would anyone know what data is located at floats # 2 - 7, # 13 - 15?

The rest of the data in there is described in the ContactPoint struct:

Those might be useful fields in the future, but we just haven’t exposed them in the javascript interface yet.

Also, I was really curious about the comment //<todo Need to get the high+low words!. If you could please share, what is the meaning of these high+low words?

So, really, an HP_BodyId is 8 bytes, and we’re only reading out four. In practice, this doesn’t cause a problem, since the top bytes are all zero. That might be a problem in future if some application allocates millions of bodies, so the todo is just to bring attention to that if we ever run into non-zero bytes in the top ID words.

1 Like

Thank you so much, @eoin, this is super helpful :smile: