Skip to content

Commit

Permalink
New Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntWaffleCake committed Feb 9, 2024
1 parent 6a96857 commit 984a719
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 53 deletions.
4 changes: 2 additions & 2 deletions articleTemplateObjects/physicsEngineArticleNavObject.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<a href="../projects/Physics/BallCollision/index.html" target="_top" class="article-nav-link">Ball Collision</a>
<a href="../projects/Physics/BallCollisionOptimization/" target="_top" class="article-nav-link">Ball Collision Optimization</a>
<a href="../projects/Physics/BoxCollision/index.html" target="_top" class="article-nav-link">Box Collision</a>
<a href="../projects/Physics/index.html" target="_top" class="article-nav-link">Polygon Collision</a>
<a href="../projects/Physics/index.html" target="_top" class="article-nav-link">Physics Engine</a>
<a href="../projects/Physics/PolygonCollision/index.html" target="_top" class="article-nav-link">Polygon Collision</a>
<a href="../projects/Physics/VerletPhyics/index.html" target="_top" class="article-nav-link">Verlet Physics</a>
</nav>
</body>
71 changes: 71 additions & 0 deletions projects/Physics/PolygonCollision/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Box Collision</title>
<meta name="description" content="Projects" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="../../../styles/articlestylesheet.css" />
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
</head>

<style>
.image-holder {
max-width: 100%;
}

.image-holder img {
max-width: 100%;
height: auto;
background-color: white;
}

.article-nav-header {
font-size: larger;
}

.equation {
text-align: center;
padding: 0;
margin: 0;
padding-bottom: 1rem;
}
</style>

<body>
<object id="global-nav-object" data="../../../articleTemplateObjects/articleGlobalNavObject.html"></object>

<div id="article-body">
<object data="../../../articleTemplateObjects/physicsEngineArticleNavObject.html"></object>

<div class="vertical-divider"></div>

<article id="article-contents">
<h1 style="width: 100%">PolygonCollision</h1>

<p
class="codepen"
data-height="300"
data-default-tab="html,result"
data-slug-hash="gOEdemY"
data-user="WaffleCake-the-decoder"
style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em"
>
<span
>See the Pen <a href="https://codepen.io/WaffleCake-the-decoder/pen/gOEdemY"> Untitled</a> by WaffleCake (<a href="https://codepen.io/WaffleCake-the-decoder">@WaffleCake-the-decoder</a>)
on <a href="https://codepen.io">CodePen</a>.</span
>
</p>
<script async src="https://cpwebassets.codepen.io/assets/embed/ei.js"></script>
<a href="./source/index.html" target="_blank" style="color: white">Click to open in new tab</a>
</article>

<div class="vertical-divider"></div>

<nav id="article-bookmarks"></nav>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Vector2 } from "./Vector2.js";

const debug = true;
const debug = false;

function minDisToLineSeg(a, b, e) {
let ab = b.clone().subtract(a);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,37 @@
<!--[if gt IE 8]> <html class="no-js"> <!--<![endif]-->

<html>

<head>
<base href=".">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<head>
<base href="." />
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
</head>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="" />
</head>

<style>
html, body {
width: 100%;
height: 100%;
<style>
html,
body {
width: 100%;
height: 100%;

padding: 0;
margin: 0;
overflow: hidden;
padding: 0;
margin: 0;
overflow: hidden;
}

#source {
box-sizing: border-box;
background-color: black;
width: 100%;
height: 100%;
box-sizing: border-box;
background-color: black;
width: 100%;
height: 100%;
}
</style>
</style>

<body>
<body>
<canvas id="source"></canvas>
<script type="module" src="./main.js" async defer></script>
</body>

</html>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ function render(dt) {
// newPoly.render(ctx);
}

let gravity = new Vector2(1000, 0);
let gravity = new Vector2(0, 1000);
let substeps = 4;
function calculate(dt, t) {
if (paused) {
return;
}

gravity.set(1000 * Math.cos(t), 1000 * Math.sin(t));
// gravity.set(1000 * Math.cos(t), 1000 * Math.sin(t));

poly2.rot += dt * ((10 * Math.PI) / 180);

Expand All @@ -48,9 +48,6 @@ function calculate(dt, t) {
let dti = dt / substeps;
model.vel.add(gravity.clone().scale(dti));
model.tick(dti, t);
// if (!polygon.anchored) {
// // applyCollisionBounds(polygon)
// }`

for (let collPoly of polygons) {
let results = model.testPolygonCollision(collPoly, ctx);
Expand All @@ -63,7 +60,6 @@ function calculate(dt, t) {
});
}
}
// console.log(model)
}

for (let polygon of polygons) {
Expand Down Expand Up @@ -102,8 +98,9 @@ function loop(t) {

if (mouse1down) {
let delta = new Vector2(prevMouseEvent.clientX, prevMouseEvent.clientY).subtract(poly1.pos);
// poly1.applyImpulse(delta.scale(poly1.mass / 2), poly1.pos)
poly1.pos.set(prevMouseEvent.clientX, prevMouseEvent.clientY);
poly1.vel.set(delta.x * 25, delta.y * 25);
// poly1.applyImpulse(delta.scale(poly1.mass / 2), poly1.pos)
}

calculate(dt, t / 1000);
Expand Down Expand Up @@ -181,30 +178,34 @@ function startup() {
// poly2 = new polyModule.Wall(new Vector2(ctx.canvas.width / 2, ctx.canvas.height / 2), 500, 0, new Vector2(0, 0), 0)
// polygons.push(poly2)
for (let i = 0; i < 20; i++) {
polygons.push(
new polyModule.RegularPolygon(
new Vector2(ctx.canvas.width * Math.random(), ctx.canvas.height * Math.random()),
new Vector2(25 + Math.random() * 100, 25 + Math.random() * 100),
3 + Math.floor(Math.random() * 3),
0,
undefined,
180 * Math.random()
)

// new polyModule.Box(
// new Vector2(ctx.canvas.width * Math.random(), ctx.canvas.height * Math.random()),
// new Vector2(25 + Math.random() * 100, 25 + Math.random() * 100),
// 0,
// undefined,
// 180 * Math.random(),
// )
);
createNewRandomPolygon();
}

window.requestAnimationFrame(loop);
}
window.requestAnimationFrame(startup);

function createNewRandomPolygon() {
polygons.push(
new polyModule.RegularPolygon(
new Vector2(ctx.canvas.width * Math.random(), ctx.canvas.height * Math.random()),
new Vector2(25 + Math.random() * 100, 25 + Math.random() * 100),
3 + Math.floor(Math.random() * 3),
0,
undefined,
180 * Math.random()
)

// new polyModule.Box(
// new Vector2(ctx.canvas.width * Math.random(), ctx.canvas.height * Math.random()),
// new Vector2(25 + Math.random() * 100, 25 + Math.random() * 100),
// 0,
// undefined,
// 180 * Math.random()
// )
);
}

var prevMouseEvent = undefined;
document.addEventListener("mousemove", (event) => {
prevMouseEvent = event;
Expand Down
1 change: 1 addition & 0 deletions projects/Physics/VerletPhyics
Submodule VerletPhyics added at 381bb8

0 comments on commit 984a719

Please sign in to comment.