summaryrefslogtreecommitdiff
path: root/frontend/2d/_rigidbody
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/2d/_rigidbody')
-rw-r--r--frontend/2d/_rigidbody/rigidbody_2.js2
-rw-r--r--frontend/2d/_rigidbody/rigidbody_3a.js10
-rw-r--r--frontend/2d/_rigidbody/rigidbody_3b.js8
3 files changed, 10 insertions, 10 deletions
diff --git a/frontend/2d/_rigidbody/rigidbody_2.js b/frontend/2d/_rigidbody/rigidbody_2.js
index 4632b11..76d8047 100644
--- a/frontend/2d/_rigidbody/rigidbody_2.js
+++ b/frontend/2d/_rigidbody/rigidbody_2.js
@@ -43,7 +43,7 @@
// Angular code starts here
// Retrieve the moment of inertia for our shape (Ours is a circle by default)
- const lMomentOfInertia = getMomentOfInertia(lCircle);
+ const lMomentOfInertia = getCircleMomentOfInertia(lCircle);
// Calculate the angular acceperation (omega = T / I)
const lAngularAcceleration = lCircle.torque / lMomentOfInertia;
diff --git a/frontend/2d/_rigidbody/rigidbody_3a.js b/frontend/2d/_rigidbody/rigidbody_3a.js
index d38f1da..ef9577b 100644
--- a/frontend/2d/_rigidbody/rigidbody_3a.js
+++ b/frontend/2d/_rigidbody/rigidbody_3a.js
@@ -62,7 +62,7 @@
pCircle.force = vec2();
// 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;
@@ -118,8 +118,8 @@
const lNumerator = dot2(scaleVec2(lRelativeVelocity, -(1.0 + COF_OF_RESTITUITION)), lCollisionNormal);
const lLinearDenomPart = dot2(lCollisionNormal, (scaleVec2(lCollisionNormal, 1 / horizontalCircle.mass + 1 / verticalCircle.mass)));
- const lRotationalDenomPart = (Math.pow(dot2(lFirstPerp, lCollisionNormal), 2) / getMomentOfInertia(horizontalCircle))
- + (Math.pow(dot2(lSecondPerp, lCollisionNormal), 2) / getMomentOfInertia(verticalCircle))
+ const lRotationalDenomPart = (Math.pow(dot2(lFirstPerp, lCollisionNormal), 2) / getCircleMomentOfInertia(horizontalCircle))
+ + (Math.pow(dot2(lSecondPerp, lCollisionNormal), 2) / getCircleMomentOfInertia(verticalCircle))
const lImpulseMagnitude = lNumerator / (lLinearDenomPart + lRotationalDenomPart);
@@ -129,8 +129,8 @@
horizontalCircle.velocity = addVec2(horizontalCircle.velocity, scaleVec2(lCollisionNormal, lImpulseMagnitude / horizontalCircle.mass));
verticalCircle.velocity = subVec2(verticalCircle.velocity, scaleVec2(lCollisionNormal, lImpulseMagnitude / verticalCircle.mass));
- horizontalCircle.rotationVelocity = horizontalCircle.rotationVelocity + dot2(lFirstPerp, scaleVec2(lCollisionNormal, lImpulseMagnitude)) / getMomentOfInertia(horizontalCircle);
- verticalCircle.rotationVelocity = verticalCircle.rotationVelocity - dot2(lSecondPerp, scaleVec2(lCollisionNormal, lImpulseMagnitude)) / getMomentOfInertia(verticalCircle);
+ horizontalCircle.rotationVelocity = horizontalCircle.rotationVelocity + dot2(lFirstPerp, scaleVec2(lCollisionNormal, lImpulseMagnitude)) / getCircleMomentOfInertia(horizontalCircle);
+ verticalCircle.rotationVelocity = verticalCircle.rotationVelocity - dot2(lSecondPerp, scaleVec2(lCollisionNormal, lImpulseMagnitude)) / getCircleMomentOfInertia(verticalCircle);
updateCircle(horizontalCircle, pDeltaTimeSeconds - lSubdividedDeltaTime);
updateCircle(verticalCircle, pDeltaTimeSeconds - lSubdividedDeltaTime);
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);