I use mesh loading from obj
files using blender for modeling.
I have one cube also in physics world it is the cube shape.And my physics works fine.
Now i need to detect which edge is on top (dice).
Logic is : Vertex stay same - state is in viewModel/projection
I need find trixk to catch and figure which face is touchig or which face is on top in current situation.
Here some most interest part of code (visual part):
this.getTransformationMatrix = (pos) => { const now = Date.now(); const deltaTime = (now - this.lastFrameMS) / this.mainCameraParams.responseCoef; this.lastFrameMS = now; // const this.viewMatrix = mat4.identity() const camera = this.cameras[this.mainCameraParams.type]; this.viewMatrix = camera.update(deltaTime, this.inputHandler()); mat4.translate(this.viewMatrix, vec3.fromValues(pos.x, pos.y, pos.z), this.viewMatrix); mat4.rotate( this.viewMatrix, vec3.fromValues(this.rotation.axis.x, this.rotation.axis.y, this.rotation.axis.z), degToRad(this.rotation.angle), this.viewMatrix) // console.info('angle: ', this.rotation.angle, ' axis ' , this.rotation.axis.x, ' , ', this.rotation.axis.y, ' , ', this.rotation.axis.z) mat4.multiply(this.projectionMatrix, this.viewMatrix, this.modelViewProjectionMatrix); return this.modelViewProjectionMatrix; }
One more code part maybe most inportant(physics part):
detectCollision() { let dispatcher = this.dynamicsWorld.getDispatcher(); let numManifolds = dispatcher.getNumManifolds(); // console.log('detect collision') for(let i = 0;i < numManifolds;i++) { let contactManifold = dispatcher.getManifoldByIndexInternal(i); let numContacts = contactManifold.getNumContacts(); this.rigidBodies.forEach((item) => { if(item.kB == contactManifold.getBody0().kB) { // console.log('Detected body0 =', item.name) } if(item.kB == contactManifold.getBody1().kB) { // console.log('Detected body1 =', item.name) } }) if(this.ground.kB == contactManifold.getBody0().kB && this.getNameByBody(contactManifold.getBody1()) == 'CubePhysics1') { // console.log(this.ground ,'GROUND IS IN CONTACT WHO IS BODY1 ', contactManifold.getBody1()) // console.log('GROUND IS IN CONTACT WHO IS BODY1 getNameByBody ', this.getNameByBody(contactManifold.getBody1())) // CHECK ROTATION var testR = contactManifold.getBody1().getWorldTransform().getRotation(); var TEST = this.getBodyByName('CubePhysics2') // console.log('testR.getAngle() = ', radToDeg(testR.getAngle())) // console.log('testR.getAngle() = ', TEST ) // console.log('testR.getAxis() = ', testR.getAxis().x(), ' y ' , testR.getAxis().y(), ' z ' , testR.getAxis().z()) // console.log('testR.x y z() = ', testR.x(), ' , ' , testR.y(), ' , ' , testR.z() , ' w ', testR.w()) } for(let j = 0;j < numContacts;j++) { let contactPoint = contactManifold.getContactPoint(j); let distance = contactPoint.getDistance(); // console.log({manifoldIndex: i, contactIndex: j, distance: distance}); } } }
I dont now who can help me info from quat to find top side face...
Any suggestion.
This is interest explanation for viewModel matrix presentation
I can make syntetic physic bodies to attach for each face and then track position but i dont wanna do this i know that data is alredy present...