diff options
| author | Matthew Kosarek <mattkae@protonmail.com> | 2021-05-16 19:50:15 -0400 |
|---|---|---|
| committer | Matthew Kosarek <mattkae@protonmail.com> | 2021-05-16 19:50:15 -0400 |
| commit | a00c0aab1eb5a7a55bef8ca08115bdd722ab5699 (patch) | |
| tree | 45b5c4cc8c380d0630a8e0185af7229f26dc754a /_shared/math/rectangle.js | |
| parent | 4941a1874b6ca9d142d94df70b2aec5e0b35b94e (diff) | |
Moved the frontend directory up so that it no longer exists
Diffstat (limited to '_shared/math/rectangle.js')
| -rw-r--r-- | _shared/math/rectangle.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/_shared/math/rectangle.js b/_shared/math/rectangle.js new file mode 100644 index 0000000..012c460 --- /dev/null +++ b/_shared/math/rectangle.js @@ -0,0 +1,32 @@ +/// <reference path="rigidbody2.js" /> + +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 = [ + -pData.width / 2.0, -pData.height / 2.0, lColor.x, lColor.y, lColor.z, lColor.w, + -pData.width / 2.0, pData.height / 2.0, lColor.x, lColor.y, lColor.z, lColor.w, + pData.width / 2.0, pData.height / 2.0, lColor.x, lColor.y, lColor.z, lColor.w, + pData.width / 2.0, pData.height /2.0, lColor.x, lColor.y, lColor.z, lColor.w, + pData.width / 2.0, -pData.height / 2.0, lColor.x, lColor.y, lColor.z, lColor.w, + -pData.width / 2.0, -pData.height / 2.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 (1.0 / 12.0) * pData.mass * (pData.height * pData.height + pData.width * pData.width); + }; + + 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 |
