summaryrefslogtreecommitdiff
path: root/2d
diff options
context:
space:
mode:
authorMatthew Kosarek <mattkae@protonmail.com>2021-06-21 20:05:08 -0400
committerMatthew Kosarek <mattkae@protonmail.com>2021-06-21 20:05:08 -0400
commita36f425491aaf019243a31179e80cb10ea62db59 (patch)
treef0c2e4677011b6595a51b628326bc2595bd08681 /2d
parent454fa3628bd35a37b7ed147a081f8f25590b3232 (diff)
(mkosarek) Transpiling code snippets in a shotty way, but it is good enough
Diffstat (limited to '2d')
-rw-r--r--2d/rigidbody/rigidbody_1.html36
-rw-r--r--2d/rigidbody/rigidbody_1.html.content4
2 files changed, 34 insertions, 6 deletions
diff --git a/2d/rigidbody/rigidbody_1.html b/2d/rigidbody/rigidbody_1.html
index e7e848d..0751499 100644
--- a/2d/rigidbody/rigidbody_1.html
+++ b/2d/rigidbody/rigidbody_1.html
@@ -93,8 +93,14 @@
<p>
Now that we have that understanding, we can begin setting up our rigidbody data structure.
- {{{rigidbody_1/snippet1.cpp}}}
-
+ <pre><code><span class="code_keyword">struct</span> Rigidbody {
+ <span class="code_keyword">Vector2</span> force = { 0, 0 };
+ <span class="code_keyword">Vector2</span> acceleration = { 0, 0 };
+ <span class="code_keyword">Vector2</span> velocity = { 0, 0 };
+ <span class="code_keyword">Vector2</span> position = { 0, 0 };
+ <span class="code_keyword">float32</span> mass = 1.f;
+};
+</code></pre>
As you can see, the base data structure exactly mirrors what we already know from 2D newtonian physics.
</p>
</section>
@@ -103,8 +109,30 @@
<p>
Now, let's put that Rigidbody data structure to work! As I mentioned earlier, you can think of dynamics as the <i>input</i> to the system. What we're going to do now is add a way to
- {{{rigidbody_1/snippet2.cpp}}}
- </p>
+ <pre><code><span class="code_keyword">struct</span> Rigidbody {
+ <span class="code_keyword">Vector2</span> force = { 0, 0 };
+ <span class="code_keyword">Vector2</span> velocity = { 0, 0 };
+ <span class="code_keyword">Vector2</span> position = { 0, 0 };
+ <span class="code_keyword">float32</span> mass = 1.f;
+
+ <span class="code_keyword">void</span> applyForce(Vector2 f) {
+ force += f;
+ }
+
+ <span class="code_keyword">void</span> applyGravity(float32 deltaTimeSeconds) {
+ velocity += (Vector2 { 0.f, -50.f } * deltaTimeSeconds);
+ }
+
+ <span class="code_keyword">void</span> update(float32 deltaTimeSeconds) {
+ applyGravity(deltaTimeSeconds);
+
+ <span class="code_keyword">Vector2</span> acceleration = force / mass;
+ velocity += (acceleration * deltaTimeSeconds);
+ position += (velocity * deltaTimeSeconds);
+ force = <span class="code_keyword">Vector2</span> { 0.f, 0.f };
+ }
+};
+</code></pre> </p>
</section>
<section>
<h2>
diff --git a/2d/rigidbody/rigidbody_1.html.content b/2d/rigidbody/rigidbody_1.html.content
index 0e75bdc..de3898a 100644
--- a/2d/rigidbody/rigidbody_1.html.content
+++ b/2d/rigidbody/rigidbody_1.html.content
@@ -43,7 +43,7 @@
<p>
Now that we have that understanding, we can begin setting up our rigidbody data structure.
- {{{rigidbody_1/snippet1.cpp}}}
+ #SNIPPET rigidbody_1/snippet1.cpp
As you can see, the base data structure exactly mirrors what we already know from 2D newtonian physics.
</p>
@@ -53,7 +53,7 @@
<p>
Now, let's put that Rigidbody data structure to work! As I mentioned earlier, you can think of dynamics as the <i>input</i> to the system. What we're going to do now is add a way to
- {{{rigidbody_1/snippet2.cpp}}}
+ #SNIPPET rigidbody_1/snippet2.cpp
</p>
</section>
<section>