From d1b528b01796601c2bfea7b1a9813e5907e1c728 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Sat, 27 Feb 2021 17:32:32 -0500 Subject: 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 --- frontend/_shared/math/rectangle.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 frontend/_shared/math/rectangle.js (limited to 'frontend/_shared/math/rectangle.js') diff --git a/frontend/_shared/math/rectangle.js b/frontend/_shared/math/rectangle.js new file mode 100644 index 0000000..c24fa12 --- /dev/null +++ b/frontend/_shared/math/rectangle.js @@ -0,0 +1,32 @@ +/// + +function rectangle(pGl, pData) { + var lBuffer = pGl.createBuffer(), + lColor = pData.color || { x: 1, y: 0, z: 0, w: 1 }; + + pGl.bindBuffer(pGl.ARRAY_BUFFER, lBuffer); + + var lBufferedData = [ + 0, 0, lColor.x, lColor.y, lColor.z, lColor.w, + 0, pData.height, lColor.x, lColor.y, lColor.z, lColor.w, + pData.width, pData.height, lColor.x, lColor.y, lColor.z, lColor.w, + pData.width, pData.height, lColor.x, lColor.y, lColor.z, lColor.w, + pData.width, 0, lColor.x, lColor.y, lColor.z, lColor.w, + 0, 0, lColor.x, lColor.y, lColor.z, lColor.w + ]; + + pGl.bufferData(pGl.ARRAY_BUFFER, new Float32Array(lBufferedData), pGl.STATIC_DRAW) + pGl.bindBuffer(pGl.ARRAY_BUFFER, undefined); + + pData.getMomentOfInertia = function() { + return Math.pow(pData.width * pData.height, 3.0) / 12.0; + }; + + return makeRigidBody2({ + vertexCount: 6, + buffer: lBuffer, + width: pData.width, + height: pData.height, + model: translateMatrix(mat4(), pData.position ? pData.position.x : 0, pData.position ? pData.position.y : 0, 0), + }, pData); +} \ No newline at end of file -- cgit v1.2.1