summaryrefslogtreecommitdiff
path: root/2d/softbody/softbody_2/main.cpp
diff options
context:
space:
mode:
authormattkae <mattkae@protonmail.com>2022-01-22 13:03:12 -0500
committermattkae <mattkae@protonmail.com>2022-01-22 13:03:12 -0500
commit19defa9be56588803bbae0f38e2f271a91b9d690 (patch)
tree92bd58290432c747b670883dbde7cbe5aed83fed /2d/softbody/softbody_2/main.cpp
parentdce6e971023d6c4bc849641c10db5d65ce5fad55 (diff)
Rendering the square for the spring rectangle
Diffstat (limited to '2d/softbody/softbody_2/main.cpp')
-rw-r--r--2d/softbody/softbody_2/main.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/2d/softbody/softbody_2/main.cpp b/2d/softbody/softbody_2/main.cpp
new file mode 100644
index 0000000..80686f9
--- /dev/null
+++ b/2d/softbody/softbody_2/main.cpp
@@ -0,0 +1,69 @@
+#include "../../../shared_cpp/WebglContext.h"
+#include "../../../shared_cpp/Renderer2d.h"
+#include "../../../shared_cpp/types.h"
+#include "../../../shared_cpp/mathlib.h"
+#include "../../../shared_cpp/MainLoop.h"
+#include <cstdio>
+#include <cmath>
+#include <emscripten/html5.h>
+#include "SpringRectangle.h"
+
+WebglContext context;
+Renderer2d renderer;
+MainLoop mainLoop;
+SoftbodyRectangle rectangle;
+
+void load();
+EM_BOOL onPlayClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData);
+EM_BOOL onStopClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData);
+void unload();
+void update(float32 deltaTimeSeconds, void* userData);
+
+int main() {
+ emscripten_set_click_callback("#gl_canvas_play", NULL, false, onPlayClicked);
+ emscripten_set_click_callback("#gl_canvas_stop", NULL, false, onStopClicked);
+ return 0;
+}
+
+EM_BOOL onPlayClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData) {
+ printf("Play clicked\n");
+ load();
+ return true;
+}
+
+EM_BOOL onStopClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData) {
+ printf("Stop clicked\n");
+ unload();
+ return true;
+}
+
+void load() {
+ context.init("#gl_canvas");
+ renderer.load(&context);
+ rectangle.load(&renderer);
+ mainLoop.run(update);
+}
+
+void update(float32 deltaTimeSeconds, void* userData) {
+ // -- Update
+
+ // -- Render
+ renderer.render();
+ rectangle.render(&renderer);
+}
+
+void unload() {
+ mainLoop.stop();
+ renderer.unload();
+ context.destroy();
+ rectangle.unload();
+}
+
+
+//
+// Interactions with DOM handled here
+//
+
+extern "C" {
+
+}