summaryrefslogtreecommitdiff
path: root/2d/rigidbody
diff options
context:
space:
mode:
authorMatthew Kosarek <mattkae@protonmail.com>2021-10-31 13:54:11 -0400
committerMatthew Kosarek <mattkae@protonmail.com>2021-10-31 13:54:11 -0400
commit5c613a10364f30bd6add25f7950433f0c482c3ca (patch)
treeaf8f6e481b6400329eca12bd8cdb35e0237d63af /2d/rigidbody
parenta214b4f8977a4b115710b5c9d152b392ac8e24f7 (diff)
(mkosarek) Working undamped spring motion
Diffstat (limited to '2d/rigidbody')
-rw-r--r--2d/rigidbody/rigidbody_1.html2
-rw-r--r--2d/rigidbody/rigidbody_1/main.cpp20
-rw-r--r--2d/rigidbody/rigidbody_2.html2
-rw-r--r--2d/rigidbody/rigidbody_2/main.cpp20
-rw-r--r--2d/rigidbody/rigidbody_3.html2
-rw-r--r--2d/rigidbody/rigidbody_3/main.cpp12
6 files changed, 32 insertions, 26 deletions
diff --git a/2d/rigidbody/rigidbody_1.html b/2d/rigidbody/rigidbody_1.html
index 62e4bf6..153e443 100644
--- a/2d/rigidbody/rigidbody_1.html
+++ b/2d/rigidbody/rigidbody_1.html
@@ -26,6 +26,8 @@
<li><label>Collisions</label></li>
<li><a title="/2d/_collisions/rectangle_rectangle.html" href="/2d/_collisions/rectangle_rectangle.html">Rectangle-Rectangle</a></li>
<li><a title="/2d/_collisions/polygon_polygon.html" href="/2d/_collisions/polygon_polygon.html">Separating Axis Theorem</a></li>
+ <li><label>Softbody</label></li>
+ <li><a title="/2d/softbody/softbody_1.html" href="/2d/softbody/softbody_1.html">Softbody</a></li>
</ul>
</li>
<li>
diff --git a/2d/rigidbody/rigidbody_1/main.cpp b/2d/rigidbody/rigidbody_1/main.cpp
index a327fee..c8a3cb4 100644
--- a/2d/rigidbody/rigidbody_1/main.cpp
+++ b/2d/rigidbody/rigidbody_1/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"
@@ -85,18 +85,18 @@ struct Rigidbody {
};
struct Rectangle {
- OrthographicShape shape;
+ Mesh2d shape;
Rigidbody body;
Vector2 originalPoints[4];
Vector2 transformedPoints[4];
- void load(OrthographicRenderer* renderer, Vector4 color, float32 width, float32 height) {
+ void load(Renderer2d* renderer, Vector4 color, float32 width, float32 height) {
color = color.toNormalizedColor();
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 };
@@ -128,7 +128,7 @@ struct Rectangle {
}
}
- void render(OrthographicRenderer* renderer) {
+ void render(Renderer2d* renderer) {
shape.render(renderer);
}
@@ -138,20 +138,20 @@ struct Rectangle {
};
struct Circle {
- OrthographicShape shape;
+ Mesh2d shape;
Rigidbody body;
Vector2 force;
float32 radius = 5.f;
- void load(OrthographicRenderer* renderer, Vector4 color) {
+ void load(Renderer2d* renderer, Vector4 color) {
const int32 numSegments = 36;
const float32 radiansPerSegment = (2.f * PI) / static_cast<float>(numSegments);
const int32 numVertices = numSegments * 3;
color = color.toNormalizedColor();
- OrthographicVertex vertices[numSegments * 3];
+ Vertex2d vertices[numSegments * 3];
for (int idx = 0; idx < numSegments; idx++) {
int vIdx = idx * 3;
@@ -171,7 +171,7 @@ struct Circle {
shape.model = Mat4x4().translateByVec2(body.position);
}
- void render(OrthographicRenderer* renderer) {
+ void render(Renderer2d* renderer) {
shape.render(renderer);
}
@@ -189,7 +189,7 @@ void update(float32 time, void* userData);
void unload();
WebglContext context;
-OrthographicRenderer renderer;
+Renderer2d renderer;
MainLoop mainLoop;
Rectangle rectangle;
Circle pointer;
diff --git a/2d/rigidbody/rigidbody_2.html b/2d/rigidbody/rigidbody_2.html
index 2378a7e..f24666c 100644
--- a/2d/rigidbody/rigidbody_2.html
+++ b/2d/rigidbody/rigidbody_2.html
@@ -26,6 +26,8 @@
<li><label>Collisions</label></li>
<li><a title="/2d/_collisions/rectangle_rectangle.html" href="/2d/_collisions/rectangle_rectangle.html">Rectangle-Rectangle</a></li>
<li><a title="/2d/_collisions/polygon_polygon.html" href="/2d/_collisions/polygon_polygon.html">Separating Axis Theorem</a></li>
+ <li><label>Softbody</label></li>
+ <li><a title="/2d/softbody/softbody_1.html" href="/2d/softbody/softbody_1.html">Softbody</a></li>
</ul>
</li>
<li>
diff --git a/2d/rigidbody/rigidbody_2/main.cpp b/2d/rigidbody/rigidbody_2/main.cpp
index 44a3c53..cae18a5 100644
--- a/2d/rigidbody/rigidbody_2/main.cpp
+++ b/2d/rigidbody/rigidbody_2/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"
@@ -100,18 +100,18 @@ struct Rigidbody {
};
struct Rectangle {
- OrthographicShape shape;
+ Mesh2d shape;
Rigidbody body;
Vector2 originalPoints[4];
Vector2 transformedPoints[4];
- void load(OrthographicRenderer* renderer, Vector4 color, float32 width, float32 height) {
+ void load(Renderer2d* renderer, Vector4 color, float32 width, float32 height) {
color = color.toNormalizedColor();
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 };
@@ -145,7 +145,7 @@ struct Rectangle {
}
}
- void render(OrthographicRenderer* renderer) {
+ void render(Renderer2d* renderer) {
shape.render(renderer);
}
@@ -155,20 +155,20 @@ struct Rectangle {
};
struct Circle {
- OrthographicShape shape;
+ Mesh2d shape;
Rigidbody body;
Vector2 force;
float32 radius = 5.f;
- void load(OrthographicRenderer* renderer, Vector4 color) {
+ void load(Renderer2d* renderer, Vector4 color) {
const int32 numSegments = 36;
const float32 radiansPerSegment = (2.f * PI) / static_cast<float>(numSegments);
const int32 numVertices = numSegments * 3;
color = color.toNormalizedColor();
- OrthographicVertex vertices[numSegments * 3];
+ Vertex2d vertices[numSegments * 3];
for (int idx = 0; idx < numSegments; idx++) {
int vIdx = idx * 3;
@@ -188,7 +188,7 @@ struct Circle {
shape.model = Mat4x4().translateByVec2(body.position);
}
- void render(OrthographicRenderer* renderer) {
+ void render(Renderer2d* renderer) {
shape.render(renderer);
}
@@ -206,7 +206,7 @@ void update(float32 time, void* userData);
void unload();
WebglContext context;
-OrthographicRenderer renderer;
+Renderer2d renderer;
MainLoop mainLoop;
Rectangle rectangle;
Circle pointer;
diff --git a/2d/rigidbody/rigidbody_3.html b/2d/rigidbody/rigidbody_3.html
index 052c6b1..ed07bbb 100644
--- a/2d/rigidbody/rigidbody_3.html
+++ b/2d/rigidbody/rigidbody_3.html
@@ -26,6 +26,8 @@
<li><label>Collisions</label></li>
<li><a title="/2d/_collisions/rectangle_rectangle.html" href="/2d/_collisions/rectangle_rectangle.html">Rectangle-Rectangle</a></li>
<li><a title="/2d/_collisions/polygon_polygon.html" href="/2d/_collisions/polygon_polygon.html">Separating Axis Theorem</a></li>
+ <li><label>Softbody</label></li>
+ <li><a title="/2d/softbody/softbody_1.html" href="/2d/softbody/softbody_1.html">Softbody</a></li>
</ul>
</li>
<li>
diff --git a/2d/rigidbody/rigidbody_3/main.cpp b/2d/rigidbody/rigidbody_3/main.cpp
index 2a0af24..7d3edd0 100644
--- a/2d/rigidbody/rigidbody_3/main.cpp
+++ b/2d/rigidbody/rigidbody_3/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"
@@ -100,13 +100,13 @@ struct Rigidbody {
};
struct Circle {
- OrthographicShape shape;
+ Mesh2d shape;
Rigidbody body;
Rigidbody previousBody;
Vector2 force;
float32 radius;
- void load(OrthographicRenderer* renderer, float32 inRadius, Vector4 startColor, Vector4 endColor) {
+ void load(Renderer2d* renderer, float32 inRadius, Vector4 startColor, Vector4 endColor) {
radius = inRadius;
const int32 numSegments = 36;
const float32 radiansPerSegment = (2.f * PI) / static_cast<float>(numSegments);
@@ -115,7 +115,7 @@ struct Circle {
startColor = startColor.toNormalizedColor();
endColor = endColor.toNormalizedColor();
- OrthographicVertex vertices[numSegments * 3];
+ Vertex2d vertices[numSegments * 3];
for (int idx = 0; idx < numSegments; idx++) {
int vIdx = idx * 3;
@@ -146,7 +146,7 @@ struct Circle {
body.update(dtSeconds);
}
- void render(OrthographicRenderer* renderer) {
+ void render(Renderer2d* renderer) {
shape.render(renderer);
}
@@ -175,7 +175,7 @@ void update(float32 time, void* userData);
void unload();
WebglContext context;
-OrthographicRenderer renderer;
+Renderer2d renderer;
MainLoop mainLoop;
Circle c1;
Circle c2;