diff options
| author | Matthew Kosarek <matthew.kosarek@vention.cc> | 2021-02-27 17:32:32 -0500 |
|---|---|---|
| committer | Matthew Kosarek <matthew.kosarek@vention.cc> | 2021-02-27 17:32:32 -0500 |
| commit | d1b528b01796601c2bfea7b1a9813e5907e1c728 (patch) | |
| tree | 77e2200e930fcad2166edf1e3d31d4cd1211db56 /frontend/2d/_rigidbody/rigidbody_3b.js | |
| parent | 026abdb98ad30209df0e88795f25b1f74556585e (diff) | |
Close to being done on line-circle collisions, but it appears we're running into a rotation problem. Going to work on square-line collisions in the meantime
Diffstat (limited to 'frontend/2d/_rigidbody/rigidbody_3b.js')
| -rw-r--r-- | frontend/2d/_rigidbody/rigidbody_3b.js | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/frontend/2d/_rigidbody/rigidbody_3b.js b/frontend/2d/_rigidbody/rigidbody_3b.js index 803161a..ddb4c70 100644 --- a/frontend/2d/_rigidbody/rigidbody_3b.js +++ b/frontend/2d/_rigidbody/rigidbody_3b.js @@ -62,7 +62,7 @@ // Same physics updates from part 2 - const lMomentOfInertia = getMomentOfInertia(pCircle); + const lMomentOfInertia = getCircleMomentOfInertia(pCircle); const lAngularAcceleration = pCircle.torque / lMomentOfInertia; pCircle.rotationVelocity += lAngularAcceleration * pDeltaTimeSeconds; pCircle.rotationRadians += pCircle.rotationVelocity * pDeltaTimeSeconds; @@ -119,14 +119,14 @@ const lNumerator = dot2(scaleVec2(lRelativeVelocity, -(1.0 + COF_OF_RESTITUITION)), lCollisionNormal); const lLinearDenomPart = dot2(lCollisionNormal, (scaleVec2(lCollisionNormal, 1 / lBall.mass))); - const lRotationalDenomPart = (Math.pow(dot2(lFirstPerp, lCollisionNormal), 2) / getMomentOfInertia(lPeg)) - + (Math.pow(dot2(lSecondPerp, lCollisionNormal), 2) / getMomentOfInertia(lBall)) + const lRotationalDenomPart = (Math.pow(dot2(lFirstPerp, lCollisionNormal), 2) / getCircleMomentOfInertia(lPeg)) + + (Math.pow(dot2(lSecondPerp, lCollisionNormal), 2) / getCircleMomentOfInertia(lBall)) const lImpulseMagnitude = lNumerator / (lLinearDenomPart + lRotationalDenomPart); lBall.position = lSubdividedBall.position; // Move the ball back to its proper subdivided position lBall.velocity = subVec2(lBall.velocity, scaleVec2(lCollisionNormal, lImpulseMagnitude / lBall.mass)); - lBall.rotationVelocity = lBall.rotationVelocity - dot2(lSecondPerp, scaleVec2(lCollisionNormal, lImpulseMagnitude)) / getMomentOfInertia(lBall); + lBall.rotationVelocity = lBall.rotationVelocity - dot2(lSecondPerp, scaleVec2(lCollisionNormal, lImpulseMagnitude)) / getCircleMomentOfInertia(lBall); // Now we update in our new direction with the remaining time that we have left. updateCircle(lBall, pDeltaTimeSeconds - lSubdividedDeltaTime); |
