summaryrefslogtreecommitdiff
path: root/frontend/2d
diff options
context:
space:
mode:
authorMatthew Kosarek <mattkae@protonmail.com>2021-03-27 21:12:42 -0400
committerMatthew Kosarek <mattkae@protonmail.com>2021-03-27 21:13:04 -0400
commitb17c518155fae64083eb5b56b78b9eec57603ac0 (patch)
tree0e8013b557a284b6d17491f9cf805634de9a11ff /frontend/2d
parentcc05fdc7396532b329f30decde5583853da92a44 (diff)
Drawing pretty line segments in easter colors
Diffstat (limited to 'frontend/2d')
-rwxr-xr-xfrontend/2d/_collisions/pill_line/dist/output.wasmbin37565 -> 40465 bytes
-rw-r--r--frontend/2d/_collisions/pill_line/main.cpp43
2 files changed, 42 insertions, 1 deletions
diff --git a/frontend/2d/_collisions/pill_line/dist/output.wasm b/frontend/2d/_collisions/pill_line/dist/output.wasm
index 92ee1f2..e282f2c 100755
--- a/frontend/2d/_collisions/pill_line/dist/output.wasm
+++ b/frontend/2d/_collisions/pill_line/dist/output.wasm
Binary files differ
diff --git a/frontend/2d/_collisions/pill_line/main.cpp b/frontend/2d/_collisions/pill_line/main.cpp
index df20fa0..4187435 100644
--- a/frontend/2d/_collisions/pill_line/main.cpp
+++ b/frontend/2d/_collisions/pill_line/main.cpp
@@ -9,6 +9,8 @@
#include <pthread.h>
#include <cmath>
+// Side note: It is Eastertime, so I chose this easter color palette. Enjoy: https://htmlcolors.com/palette/144/easter
+
//
// Pill object
//
@@ -52,6 +54,11 @@ struct Pill {
}
shape.load(vertices, numVertices, renderer);
+ delete[] vertices;
+ }
+
+ void render(OrthographicRenderer* renderer) {
+ shape.render(renderer);
}
void unload() {
@@ -63,6 +70,25 @@ struct Pill {
}
};
+struct LineSegment {
+ OrthographicShape shape;
+ Vector2 start;
+ Vector2 end;
+ OrthographicVertex vertices[2];
+
+ void load(OrthographicRenderer* renderer, Vector4 color, Vector2 start, Vector2 end) {
+ vertices[0].position = start;
+ vertices[0].color = color;
+ vertices[1].position = end;
+ vertices[1].color = color;
+ shape.load(vertices, 2, renderer);
+ }
+
+ void render(OrthographicRenderer* renderer) {
+ shape.render(renderer, GL_LINES);
+ }
+};
+
EM_BOOL onPlayClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData);
EM_BOOL onStopClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData);
EM_BOOL update(float time, void* userData);
@@ -72,6 +98,7 @@ WebglContext context;
OrthographicRenderer renderer;
Pill pill;
MainLoop mainLoop;
+LineSegment segmentList[4];
int main() {
context.init("#gl_canvas");
@@ -83,6 +110,11 @@ int main() {
EM_BOOL update(float deltaTimeSeconds, void* userData) {
renderer.render();
pill.shape.render(&renderer);
+
+ for (int segmentIndex = 0; segmentIndex < 4; segmentIndex++) {
+ segmentList[segmentIndex].render(&renderer);
+ }
+
return true;
}
@@ -93,10 +125,19 @@ EM_BOOL onPlayClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, voi
printf("Play clicked\n");
renderer.load(&context);
+
+ // Add the pill
pill.width = 100.f;
pill.height = 50.f;
- pill.shape.model = pill.shape.model.translateByVec2(Vector2 { context.width / 2.f, context.height / 2.f });
+ pill.shape.model = Mat4x4().translateByVec2(Vector2 { context.width / 2.f, context.height / 2.f });
pill.load(&renderer, 64);
+
+ // Add the lines
+ segmentList[0].load(&renderer, Vector4().fromColor(191, 251, 146, 255.f), Vector2 { 50.f, 0.f }, Vector2 { 50.f, static_cast<float>(context.height) });
+ segmentList[1].load(&renderer, Vector4().fromColor(159, 224, 210, 255.f), Vector2 { context.width - 50.f, 0.f }, Vector2 { context.width - 50.f, static_cast<float>(context.height) });
+ segmentList[2].load(&renderer, Vector4().fromColor(248, 255, 156, 255.f), Vector2 { 50.f, 50.f }, Vector2 { context.width - 50.f, 150.f });
+ segmentList[3].load(&renderer, Vector4().fromColor(205, 178, 214, 255.f), Vector2 { 50.f, 150.f }, Vector2 { context.width - 50.f, 50.f });
+
mainLoop.run(update);
return true;
}