From 5c613a10364f30bd6add25f7950433f0c482c3ca Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Sun, 31 Oct 2021 13:54:11 -0400 Subject: (mkosarek) Working undamped spring motion --- 2d/_collisions/pill_line/main.cpp | 20 ++++++++++---------- 2d/_collisions/pill_pill/main.cpp | 12 ++++++------ 2d/_collisions/polygon_polygon.html | 2 ++ 2d/_collisions/polygon_polygon/main.cpp | 12 ++++++------ 2d/_collisions/rectangle_line/main.cpp | 20 ++++++++++---------- 2d/_collisions/rectangle_rectangle.html | 2 ++ 2d/_collisions/rectangle_rectangle/main.cpp | 12 ++++++------ 7 files changed, 42 insertions(+), 38 deletions(-) (limited to '2d/_collisions') diff --git a/2d/_collisions/pill_line/main.cpp b/2d/_collisions/pill_line/main.cpp index b9315a8..65687ba 100644 --- a/2d/_collisions/pill_line/main.cpp +++ b/2d/_collisions/pill_line/main.cpp @@ -1,4 +1,4 @@ -#include "../../../shared_cpp/OrthographicRenderer.h" +#include "../../../shared_cpp/Renderer2d.h" #include "../../../shared_cpp/types.h" #include "../../../shared_cpp/WebglContext.h" #include "../../../shared_cpp/mathlib.h" @@ -54,7 +54,7 @@ struct Rigidbody { }; struct Pill { - OrthographicShape shape; + Mesh2d shape; Rigidbody body; float32 a = 0; float32 b = 0; @@ -68,7 +68,7 @@ struct Pill { return retval; } - void load(OrthographicRenderer* renderer, float32 numSegments, float32 width, float32 height) { + void load(Renderer2d* renderer, float32 numSegments, float32 width, float32 height) { // Note that a so-called "pill" is simply an ellipse. // Equation of an ellipse is: // @@ -80,7 +80,7 @@ struct Pill { // float32 angleIncrements = (2.f * PI) / numSegments; uint32 numVertices = static_cast(numSegments * 3.f); - OrthographicVertex* vertices = new OrthographicVertex[numVertices]; + Vertex2d* vertices = new Vertex2d[numVertices]; a = width / 2.f; b = height / 2.f; @@ -119,7 +119,7 @@ struct Pill { shape.model = Mat4x4().translateByVec2(body.position).rotate2D(body.rotation); } - void render(OrthographicRenderer* renderer) { + void render(Renderer2d* renderer) { shape.render(renderer); } @@ -129,15 +129,15 @@ struct Pill { }; struct LineSegment { - OrthographicShape shape; + Mesh2d shape; Rigidbody body; Vector2 start; Vector2 end; float32 length; Vector2 normal; - OrthographicVertex vertices[2]; + Vertex2d vertices[2]; - void load(OrthographicRenderer* renderer, Vector4 color, Vector2 inStart, Vector2 inEnd) { + void load(Renderer2d* renderer, Vector4 color, Vector2 inStart, Vector2 inEnd) { start = inStart; end = inEnd; length = (start - end).length(); @@ -156,7 +156,7 @@ struct LineSegment { body.momentOfInertia = body.mass * (length / 2.f); } - void render(OrthographicRenderer* renderer) { + void render(Renderer2d* renderer) { shape.render(renderer, GL_LINES); } @@ -195,7 +195,7 @@ void resolveCollision(Rigidbody* first, Rigidbody* second, IntersectionResult* i // Global Variables WebglContext context; -OrthographicRenderer renderer; +Renderer2d renderer; Pill pill; MainLoop mainLoop; LineSegment segmentList[4]; diff --git a/2d/_collisions/pill_pill/main.cpp b/2d/_collisions/pill_pill/main.cpp index 1aef594..7802a5d 100644 --- a/2d/_collisions/pill_pill/main.cpp +++ b/2d/_collisions/pill_pill/main.cpp @@ -1,4 +1,4 @@ -#include "../../../shared_cpp/OrthographicRenderer.h" +#include "../../../shared_cpp/Renderer2d.h" #include "../../../shared_cpp/types.h" #include "../../../shared_cpp/WebglContext.h" #include "../../../shared_cpp/mathlib.h" @@ -59,7 +59,7 @@ struct PillInData { }; struct Pill { - OrthographicShape shape; + Mesh2d shape; Rigidbody body; float32 a = 0; float32 b = 0; @@ -73,10 +73,10 @@ struct Pill { return retval; } - void load(OrthographicRenderer* renderer, PillInData data) { + void load(Renderer2d* renderer, PillInData data) { float32 angleIncrements = (2.f * PI) / data.numSegments; uint32 numVertices = static_cast(data.numSegments * 3.f); - OrthographicVertex* vertices = new OrthographicVertex[numVertices]; + Vertex2d* vertices = new Vertex2d[numVertices]; a = data.width / 2.f; b = data.height / 2.f; @@ -112,7 +112,7 @@ struct Pill { shape.model = Mat4x4().translateByVec2(body.position).rotate2D(body.rotation); } - void render(OrthographicRenderer* renderer) { + void render(Renderer2d* renderer) { shape.render(renderer); } @@ -141,7 +141,7 @@ void update(float32 time, void* userData); void unload(); WebglContext context; -OrthographicRenderer renderer; +Renderer2d renderer; MainLoop mainLoop; Pill pillList[2]; diff --git a/2d/_collisions/polygon_polygon.html b/2d/_collisions/polygon_polygon.html index da5edea..75dbcfd 100644 --- a/2d/_collisions/polygon_polygon.html +++ b/2d/_collisions/polygon_polygon.html @@ -26,6 +26,8 @@
  • Rectangle-Rectangle
  • Separating Axis Theorem
  • +
  • +
  • Softbody
  • diff --git a/2d/_collisions/polygon_polygon/main.cpp b/2d/_collisions/polygon_polygon/main.cpp index 9cb3eb2..3d8561f 100644 --- a/2d/_collisions/polygon_polygon/main.cpp +++ b/2d/_collisions/polygon_polygon/main.cpp @@ -1,4 +1,4 @@ -#include "../../../shared_cpp/OrthographicRenderer.h" +#include "../../../shared_cpp/Renderer2d.h" #include "../../../shared_cpp/types.h" #include "../../../shared_cpp/WebglContext.h" #include "../../../shared_cpp/mathlib.h" @@ -112,7 +112,7 @@ struct Edge { }; struct ConvexPolygon { - OrthographicShape shape; + Mesh2d shape; Rigidbody body; Rigidbody previousBody; Vector4 color; @@ -123,7 +123,7 @@ struct ConvexPolygon { Vector2* transformedVertices; Edge* edges; - void load(OrthographicRenderer* renderer) { + void load(Renderer2d* renderer) { transformedVertices = new Vector2[numVertices]; // This will be used for SAT calculations later originalVertices = new Vector2[numVertices]; @@ -134,7 +134,7 @@ struct ConvexPolygon { // is the 2k lines of JavaScript that are required to display it. int32 verticesNeeded = numVertices * 3; float32 angleIncrements = (2.f * PI) / static_cast(numVertices); - OrthographicVertex* shaderVertices = new OrthographicVertex[verticesNeeded]; + Vertex2d* shaderVertices = new Vertex2d[verticesNeeded]; for (int32 vidx = 0; vidx < numVertices; vidx++) { int32 indexPosition = vidx * 3; @@ -186,7 +186,7 @@ struct ConvexPolygon { body = previousBody; } - void render(OrthographicRenderer* renderer) { + void render(Renderer2d* renderer) { shape.render(renderer); } @@ -213,7 +213,7 @@ void update(float32 time, void* userData); void unload(); WebglContext context; -OrthographicRenderer renderer; +Renderer2d renderer; MainLoop mainLoop; ConvexPolygon polygons[4]; diff --git a/2d/_collisions/rectangle_line/main.cpp b/2d/_collisions/rectangle_line/main.cpp index 25e124c..49ce7d7 100644 --- a/2d/_collisions/rectangle_line/main.cpp +++ b/2d/_collisions/rectangle_line/main.cpp @@ -1,4 +1,4 @@ -#include "../../../shared_cpp/OrthographicRenderer.h" +#include "../../../shared_cpp/Renderer2d.h" #include "../../../shared_cpp/types.h" #include "../../../shared_cpp/WebglContext.h" #include "../../../shared_cpp/mathlib.h" @@ -60,13 +60,13 @@ struct IntersectionResult { }; struct Rectangle { - OrthographicShape shape; + Mesh2d shape; Rigidbody body; Vector4 color; float32 width = 0.f; float32 height = 0.f; - void load(OrthographicRenderer* renderer, Vector4 inColor, float32 inWidth, float32 inHeight) { + void load(Renderer2d* renderer, Vector4 inColor, float32 inWidth, float32 inHeight) { color = inColor.toNormalizedColor(); width = inWidth;; height = inHeight; @@ -74,7 +74,7 @@ struct Rectangle { float32 halfWidth = width / 2.f; float32 halfHeight = height / 2.f; - OrthographicVertex vertices[6]; + Vertex2d vertices[6]; vertices[0].position = Vector2 { -halfWidth, -halfHeight }; vertices[1].position = Vector2 { -halfWidth, halfHeight }; vertices[2].position = Vector2 { halfWidth, halfHeight }; @@ -96,7 +96,7 @@ struct Rectangle { shape.model = Mat4x4().translateByVec2(body.position).rotate2D(body.rotation); } - void render(OrthographicRenderer* renderer) { + void render(Renderer2d* renderer) { shape.render(renderer); } @@ -106,15 +106,15 @@ struct Rectangle { }; struct LineSegment { - OrthographicShape shape; + Mesh2d shape; Rigidbody body; Vector2 start; Vector2 end; float32 length; Vector2 normal; - OrthographicVertex vertices[2]; + Vertex2d vertices[2]; - void load(OrthographicRenderer* renderer, Vector4 color, Vector2 inStart, Vector2 inEnd) { + void load(Renderer2d* renderer, Vector4 color, Vector2 inStart, Vector2 inEnd) { start = inStart; end = inEnd; length = (start - end).length(); @@ -133,7 +133,7 @@ struct LineSegment { body.momentOfInertia = body.mass * (length / 2.f); } - void render(OrthographicRenderer* renderer) { + void render(Renderer2d* renderer) { shape.render(renderer, GL_LINES); } @@ -161,7 +161,7 @@ void update(float32 time, void* userData); void unload(); WebglContext context; -OrthographicRenderer renderer; +Renderer2d renderer; MainLoop mainLoop; LineSegment segmentList[4]; Rectangle rectangle; diff --git a/2d/_collisions/rectangle_rectangle.html b/2d/_collisions/rectangle_rectangle.html index d5c407a..75c2e62 100644 --- a/2d/_collisions/rectangle_rectangle.html +++ b/2d/_collisions/rectangle_rectangle.html @@ -26,6 +26,8 @@
  • Rectangle-Rectangle
  • Separating Axis Theorem
  • +
  • +
  • Softbody
  • diff --git a/2d/_collisions/rectangle_rectangle/main.cpp b/2d/_collisions/rectangle_rectangle/main.cpp index 6913749..3cd4f46 100644 --- a/2d/_collisions/rectangle_rectangle/main.cpp +++ b/2d/_collisions/rectangle_rectangle/main.cpp @@ -1,4 +1,4 @@ -#include "../../../shared_cpp/OrthographicRenderer.h" +#include "../../../shared_cpp/Renderer2d.h" #include "../../../shared_cpp/types.h" #include "../../../shared_cpp/WebglContext.h" #include "../../../shared_cpp/mathlib.h" @@ -67,14 +67,14 @@ struct Edge { }; struct Rectangle { - OrthographicShape shape; + Mesh2d shape; Rigidbody body; Rigidbody previousBody; Vector4 color; float32 width = 0.f; float32 height = 0.f; - void load(OrthographicRenderer* renderer, Vector4 inColor, float32 inWidth, float32 inHeight) { + void load(Renderer2d* renderer, Vector4 inColor, float32 inWidth, float32 inHeight) { color = inColor.toNormalizedColor(); width = inWidth;; height = inHeight; @@ -82,7 +82,7 @@ struct Rectangle { float32 halfWidth = width / 2.f; float32 halfHeight = height / 2.f; - OrthographicVertex vertices[6]; + Vertex2d vertices[6]; vertices[0].position = Vector2 { -halfWidth, -halfHeight }; vertices[1].position = Vector2 { -halfWidth, halfHeight }; vertices[2].position = Vector2 { halfWidth, halfHeight }; @@ -106,7 +106,7 @@ struct Rectangle { shape.model = Mat4x4().translateByVec2(body.position).rotate2D(body.rotation); } - void render(OrthographicRenderer* renderer) { + void render(Renderer2d* renderer) { shape.render(renderer); } @@ -169,7 +169,7 @@ void update(float32 time, void* userData); void unload(); WebglContext context; -OrthographicRenderer renderer; +Renderer2d renderer; MainLoop mainLoop; Rectangle rectangleList[4]; -- cgit v1.2.1