summaryrefslogtreecommitdiff
path: root/2d/_collisions
diff options
context:
space:
mode:
authorMatthew Kosarek <mattkae@protonmail.com>2021-05-25 20:58:53 -0400
committerMatthew Kosarek <mattkae@protonmail.com>2021-05-25 20:58:53 -0400
commit76b6fa0ce8cfaaab8e2052bdd43266ded8e404b6 (patch)
tree245508c6121a0b9327d216ba3593a847972f08c1 /2d/_collisions
parentc3cad9328cff7bfee8d9d824a2098f1b019e884a (diff)
Finally able to remove all of those unneeded javascript files
Diffstat (limited to '2d/_collisions')
-rw-r--r--2d/_collisions/circle_line.html51
-rw-r--r--2d/_collisions/circle_line.js179
-rw-r--r--2d/_collisions/pill_line.html1
-rw-r--r--2d/_collisions/pill_pill.html1
-rw-r--r--2d/_collisions/polygon_polygon.html1
-rw-r--r--2d/_collisions/rectangle_line.html1
-rw-r--r--2d/_collisions/rectangle_rectangle.html1
7 files changed, 0 insertions, 235 deletions
diff --git a/2d/_collisions/circle_line.html b/2d/_collisions/circle_line.html
deleted file mode 100644
index 791d1ed..0000000
--- a/2d/_collisions/circle_line.html
+++ /dev/null
@@ -1,51 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
- <head>
- <meta charset="utf-8">
- <script src="/scripts/jquery-3.5.1.min.js"></script>
- <script src="/index.js"></script>
- <link rel="stylesheet" href="/index.css">
- <link rel="shortcut icon" href="/favicon/favicon.ico" type="image/x-icon">
-
- <title>Physics for Games</title>
-
- <script src="/_shared/math/vec2.js"></script>
- <script src="/_shared/math/mat4.js"></script>
- <script src="/_shared/math/circle.js"></script>
- <script src="/_shared/math/line2.js"></script>
- <script src="/_shared/math/point2.js"></script>
- <script src="/_shared/math/collision.js"></script>
- <script src="/_shared/2d/shader.js"></script>
- <script src="/_shared/2d/program_common.js"></script>
- <script src="circle_line.js"></script>
- </head>
- <body>
- <header>
- <h1>Physics for Games</h1>
- </header>
- <main>
- <nav>
- </nav>
- <section>
- <h1>Circle-Line</h1>
- <article>
- <p>
- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- </p>
- <div id="circle_line_collision" class="opengl_canvas_container">
- <canvas width="800" height="600"></canvas>
- <div class="opengl_canvas_sidebar">
-
- </div>
- <button class="play_button">
- Play
- </button>
- <button class="stop_button">
- Stop
- </button>
- </div>
- </article>
- </section>
- </main>
- </body>
-</html> \ No newline at end of file
diff --git a/2d/_collisions/circle_line.js b/2d/_collisions/circle_line.js
deleted file mode 100644
index 0736e2c..0000000
--- a/2d/_collisions/circle_line.js
+++ /dev/null
@@ -1,179 +0,0 @@
-/// <reference path="../../scripts/jquery-3.5.1.min.js"/>
-/// <reference path="../../_shared/math/vec2.js" />
-/// <reference path="../../_shared/math/mat4.js" />
-/// <reference path="../../_shared/2d/shader.js" />
-/// <reference path="../../_shared/math/circle.js" />
-/// <reference path="../../_shared/math/line2.js" />
-/// <reference path="../../_shared/math/collision.js" />
-/// <reference path="../../_shared/2d/program_common.js" />
-
-(function() {
- // Define Constants
- const CIRCLE_RADIUS = 16;
- const GRAVITY = 20.0;
- const COF_OF_RESTITUITION = 0.75;
- const TORQUE_MULTIPLIER = 100.0; // TODO: This may be unncessary
-
- var programContext,
- circleObject,
- lineObjectList,
- programInfo,
- exitRequestFunc;
-
- function main() {
- programContext = getContext('#circle_line_collision');
-
- if (programContext.gl === null) {
- console.error('Unable to initialize WebGL. Your browser or machine may not support it.');
- return;
- }
-
- programContext.gl.clearColor(0.1, 0.15, 0.2, 1.0);
- programContext.gl.clear(programContext.gl.COLOR_BUFFER_BIT);
- programContext.playButton.on('click', run);
- }
-
- function run() {
- console.log('Running Circle-Line Collisions');
- programContext.load().then(function(pProgramInfo) {
- programInfo = pProgramInfo;
- circleObject = circle(programContext.gl, CIRCLE_RADIUS, 30, [
- { x: 1, y: 0, z: 0, w: 1 },
- { x: 0, y: 1, z: 0, w: 1 },
- { x: 0, y: 0, z: 1, w: 1 }
- ], vec2(programContext.width * (3.0 / 4.0), programContext.height / 2.0 + 100));
-
- circleObject.velocity = vec2(0, -50);
-
- lineObjectList = [];
-
- lineObjectList.push(line2({ x: 100, y: 100 }, { x: programContext.width - 100, y: 200 }, programContext.gl,
- { x: 1, y: 0, z: 0, w: 1 }, 2.0));
-
- lineObjectList.push(line2({ x: 100, y: 200 }, { x: programContext.width - 100, y: 100 }, programContext.gl,
- { x: 1, y: 1, z: 0, w: 1 }, 2.0));
-
- lineObjectList.push(line2({ x: 100, y: 0 }, { x: 100, y: programContext.height }, programContext.gl,
- { x: 0, y: 1, z: 0, w: 1 }, 2.0));
-
- lineObjectList.push(line2({ x: programContext.width - 100, y: 0 }, { x: programContext.width - 100, y: programContext.height }, programContext.gl,
- { x: 0, y: 1, z: 0, w: 1 }, 2.0));
-
-
- exitRequestFunc = requestUpdateLoop(update, cleanup);
- programContext.stopButton.on('click', reset);
- });
- }
-
- function update(pDeltaTimeSeconds) {
- pDeltaTimeSeconds = pDeltaTimeSeconds;
- updateCircle(circleObject, pDeltaTimeSeconds);
- collision(pDeltaTimeSeconds);
- render();
- }
-
- function updateCircle(pCircle, pDeltaTimeSeconds) {
- applyForce(pCircle, vec2(0, -1.0 * (pCircle.mass * GRAVITY)));
- const lCurrentAcceleration = scaleVec2(pCircle.force, 1.0 / pCircle.mass);
- pCircle.prevVelocity = pCircle.velocity;
- pCircle.velocity = addVec2(pCircle.velocity, scaleVec2(lCurrentAcceleration, pDeltaTimeSeconds));
- pCircle.prevPos = { ...pCircle.position };
- pCircle.position = addVec2(pCircle.position, scaleVec2(pCircle.velocity, pDeltaTimeSeconds));
- pCircle.force = vec2();
-
- const lMomentOfInertia = getCircleMomentOfInertia(pCircle);
- const lAngularAcceleration = pCircle.torque / lMomentOfInertia;
- pCircle.rotationVelocity += lAngularAcceleration * pDeltaTimeSeconds;
- pCircle.rotationRadians += pCircle.rotationVelocity * pDeltaTimeSeconds;
- pCircle.torque = 0;
-
- pCircle.model = rotateMatrix2d(translateMatrix(mat4(), pCircle.position.x, pCircle.position.y, 0), pCircle.rotationRadians);
- }
-
- function collision(pDeltaTimeSeconds) {
- lineObjectList.forEach(function(lineObject) {
- if (!lineCircleCollision2(circleObject, lineObject)) {
- return;
- }
-
- var lSubdividedDeltaTime = pDeltaTimeSeconds,
- lSubdividedCircle = undefined;
-
- do {
- lSubdividedCircle = JSON.parse(JSON.stringify(circleObject));
- lSubdividedCircle.position = {...circleObject.prevPos};
- lSubdividedCircle.velocity = {...circleObject.prevVelocity};
- lSubdividedDeltaTime = lSubdividedDeltaTime / 2.0;
- updateCircle(lSubdividedCircle, lSubdividedDeltaTime);
- if (lSubdividedDeltaTime === 0) {
- console.error('This should NOT be happening');
- break;
- }
- } while (lineCircleCollision2(lSubdividedCircle, lineObject))
-
- const lIntersectionResult = getLineCircleCollison2Data(lSubdividedCircle, lineObject),
- lRelativeVelocity = lIntersectionResult.relativeVelocity,
- lCollisionNormal = lIntersectionResult.collisionNormal,
- lFirstPerp = getPerp2(lIntersectionResult.firstPointOfApplication),
- lSecondPerp = getPerp2(lIntersectionResult.secondPointOfApplication);
-
- const lNumerator = dot2(scaleVec2(lRelativeVelocity, -(1.0 + COF_OF_RESTITUITION)), lCollisionNormal);
- const lLinearDenomPart = dot2(lCollisionNormal, (scaleVec2(lCollisionNormal, 1 / circleObject.mass)));
- const lRotationalDenomPart = (Math.pow(dot2(lFirstPerp, lCollisionNormal), 2) / getCircleMomentOfInertia(circleObject));
-
- const lImpulseMagnitude = lNumerator / (lLinearDenomPart + lRotationalDenomPart);
-
- circleObject.position = lSubdividedCircle.position;
- circleObject.velocity = addVec2(lSubdividedCircle.velocity, scaleVec2(lCollisionNormal, lImpulseMagnitude / circleObject.mass));
- circleObject.rotationVelocity = lSubdividedCircle.rotationVelocity
- + dot2(lFirstPerp, scaleVec2(lCollisionNormal, lImpulseMagnitude)) / getCircleMomentOfInertia(circleObject);
-
- updateCircle(circleObject, pDeltaTimeSeconds - lSubdividedDeltaTime);
-
- return;
- })
- }
-
- function applyForce(pCircle, pForceVector, pPointOfApplication) {
- if (pPointOfApplication !== undefined) {
- const lOriginToPointOfApp = subVec2(vec2(), pPointOfApplication),
- lPerpVec = vec2(-lOriginToPointOfApp.y, lOriginToPointOfApp.x);
-
- pCircle.torque += TORQUE_MULTIPLIER * dot2(lPerpVec, pForceVector);
- }
-
- pCircle.force = addVec2(pCircle.force, pForceVector);
- }
-
- function render() {
- programContext.gl.clearColor(0.1, 0.15, 0.2, 1.0);
- programContext.gl.clearDepth(1.0);
- programContext.gl.enable(programContext.gl.DEPTH_TEST);
- programContext.gl.depthFunc(programContext.gl.LEQUAL);
- programContext.gl.clear(programContext.gl.COLOR_BUFFER_BIT | programContext.gl.DEPTH_BUFFER_BIT);
- programContext.gl.useProgram(programInfo.program);
- programContext.gl.uniformMatrix4fv(programInfo.uniformLocations.projection, false, programContext.perspective);
-
- renderCircle(programContext.gl, programInfo, circleObject);
- lineObjectList.forEach(function(lineObject) {
- renderLine2(programContext.gl, programInfo, lineObject);
- });
- }
-
- function cleanup() {
- programContext.gl.deleteBuffer(circleObject.buffer);
- lineObjectList.forEach(function(lineObject) {
- programContext.gl.deleteBuffer(lineObject.buffer);
- });
- programContext.gl.deleteProgram(programInfo.program);
- programContext.gl.clearColor(0.1, 0.15, 0.2, 1.0);
- programContext.gl.clear(programContext.gl.COLOR_BUFFER_BIT);
- }
-
- function reset() {
- exitRequestFunc();
- programContext.reset();
- }
-
- $(document).ready(main);
-})() \ No newline at end of file
diff --git a/2d/_collisions/pill_line.html b/2d/_collisions/pill_line.html
index fbe9251..de96b37 100644
--- a/2d/_collisions/pill_line.html
+++ b/2d/_collisions/pill_line.html
@@ -20,7 +20,6 @@
<li><label>Rigidbody</label></li>
<li><a title="/2d/rigidbody/rigidbody_1.html" href="/2d/rigidbody/rigidbody_1.html">Linear Forces</a></li>
<li><label>Collisions</label></li>
- <li><a title="/2d/_collisions/circle_line.html" href="/2d/_collisions/circle_line.html">Circle-Line</a></li>
<li><a title="/2d/_collisions/rectangle_line.html" href="/2d/_collisions/rectangle_line.html">Rectangle-Line</a></li>
<li><a title="/2d/_collisions/rectangle_rectangle.html" href="/2d/_collisions/rectangle_rectangle.html">Rectangle-Rectangle</a></li>
<li><a title="/2d/_collisions/pill_line.html" href="/2d/_collisions/pill_line.html">Pill-Line</a></li>
diff --git a/2d/_collisions/pill_pill.html b/2d/_collisions/pill_pill.html
index b8fa01c..2d47542 100644
--- a/2d/_collisions/pill_pill.html
+++ b/2d/_collisions/pill_pill.html
@@ -20,7 +20,6 @@
<li><label>Rigidbody</label></li>
<li><a title="/2d/rigidbody/rigidbody_1.html" href="/2d/rigidbody/rigidbody_1.html">Linear Forces</a></li>
<li><label>Collisions</label></li>
- <li><a title="/2d/_collisions/circle_line.html" href="/2d/_collisions/circle_line.html">Circle-Line</a></li>
<li><a title="/2d/_collisions/rectangle_line.html" href="/2d/_collisions/rectangle_line.html">Rectangle-Line</a></li>
<li><a title="/2d/_collisions/rectangle_rectangle.html" href="/2d/_collisions/rectangle_rectangle.html">Rectangle-Rectangle</a></li>
<li><a title="/2d/_collisions/pill_line.html" href="/2d/_collisions/pill_line.html">Pill-Line</a></li>
diff --git a/2d/_collisions/polygon_polygon.html b/2d/_collisions/polygon_polygon.html
index 44496fb..1bdb759 100644
--- a/2d/_collisions/polygon_polygon.html
+++ b/2d/_collisions/polygon_polygon.html
@@ -20,7 +20,6 @@
<li><label>Rigidbody</label></li>
<li><a title="/2d/rigidbody/rigidbody_1.html" href="/2d/rigidbody/rigidbody_1.html">Linear Forces</a></li>
<li><label>Collisions</label></li>
- <li><a title="/2d/_collisions/circle_line.html" href="/2d/_collisions/circle_line.html">Circle-Line</a></li>
<li><a title="/2d/_collisions/rectangle_line.html" href="/2d/_collisions/rectangle_line.html">Rectangle-Line</a></li>
<li><a title="/2d/_collisions/rectangle_rectangle.html" href="/2d/_collisions/rectangle_rectangle.html">Rectangle-Rectangle</a></li>
<li><a title="/2d/_collisions/pill_line.html" href="/2d/_collisions/pill_line.html">Pill-Line</a></li>
diff --git a/2d/_collisions/rectangle_line.html b/2d/_collisions/rectangle_line.html
index e9720d1..bb5d1e8 100644
--- a/2d/_collisions/rectangle_line.html
+++ b/2d/_collisions/rectangle_line.html
@@ -20,7 +20,6 @@
<li><label>Rigidbody</label></li>
<li><a title="/2d/rigidbody/rigidbody_1.html" href="/2d/rigidbody/rigidbody_1.html">Linear Forces</a></li>
<li><label>Collisions</label></li>
- <li><a title="/2d/_collisions/circle_line.html" href="/2d/_collisions/circle_line.html">Circle-Line</a></li>
<li><a title="/2d/_collisions/rectangle_line.html" href="/2d/_collisions/rectangle_line.html">Rectangle-Line</a></li>
<li><a title="/2d/_collisions/rectangle_rectangle.html" href="/2d/_collisions/rectangle_rectangle.html">Rectangle-Rectangle</a></li>
<li><a title="/2d/_collisions/pill_line.html" href="/2d/_collisions/pill_line.html">Pill-Line</a></li>
diff --git a/2d/_collisions/rectangle_rectangle.html b/2d/_collisions/rectangle_rectangle.html
index cfa2810..3c4e80e 100644
--- a/2d/_collisions/rectangle_rectangle.html
+++ b/2d/_collisions/rectangle_rectangle.html
@@ -20,7 +20,6 @@
<li><label>Rigidbody</label></li>
<li><a title="/2d/rigidbody/rigidbody_1.html" href="/2d/rigidbody/rigidbody_1.html">Linear Forces</a></li>
<li><label>Collisions</label></li>
- <li><a title="/2d/_collisions/circle_line.html" href="/2d/_collisions/circle_line.html">Circle-Line</a></li>
<li><a title="/2d/_collisions/rectangle_line.html" href="/2d/_collisions/rectangle_line.html">Rectangle-Line</a></li>
<li><a title="/2d/_collisions/rectangle_rectangle.html" href="/2d/_collisions/rectangle_rectangle.html">Rectangle-Rectangle</a></li>
<li><a title="/2d/_collisions/pill_line.html" href="/2d/_collisions/pill_line.html">Pill-Line</a></li>