Last active
August 3, 2020 09:24
-
-
Save BlueMagnificent/dc5d75e626da33902e7cb19efa2e9698 to your computer and use it in GitHub Desktop.
Javascript 3D Physics Tut 3 Setup Contact Result Callback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setupContactResultCallback(){ | |
cbContactResult = new Ammo.ConcreteContactResultCallback(); | |
cbContactResult.addSingleResult = function(cp, colObj0Wrap, partId0, index0, colObj1Wrap, partId1, index1){ | |
let contactPoint = Ammo.wrapPointer( cp, Ammo.btManifoldPoint ); | |
const distance = contactPoint.getDistance(); | |
if( distance > 0 ) return; | |
let colWrapper0 = Ammo.wrapPointer( colObj0Wrap, Ammo.btCollisionObjectWrapper ); | |
let rb0 = Ammo.castObject( colWrapper0.getCollisionObject(), Ammo.btRigidBody ); | |
let colWrapper1 = Ammo.wrapPointer( colObj1Wrap, Ammo.btCollisionObjectWrapper ); | |
let rb1 = Ammo.castObject( colWrapper1.getCollisionObject(), Ammo.btRigidBody ); | |
let threeObject0 = rb0.threeObject; | |
let threeObject1 = rb1.threeObject; | |
let tag, localPos, worldPos | |
if( threeObject0.userData.tag != "ball" ){ | |
tag = threeObject0.userData.tag; | |
localPos = contactPoint.get_m_localPointA(); | |
worldPos = contactPoint.get_m_positionWorldOnA(); | |
} | |
else{ | |
tag = threeObject1.userData.tag; | |
localPos = contactPoint.get_m_localPointB(); | |
worldPos = contactPoint.get_m_positionWorldOnB(); | |
} | |
let localPosDisplay = {x: localPos.x(), y: localPos.y(), z: localPos.z()}; | |
let worldPosDisplay = {x: worldPos.x(), y: worldPos.y(), z: worldPos.z()}; | |
console.log( { tag, localPosDisplay, worldPosDisplay } ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment