From ece2b67aa689aee0b881bac17a62c16e0469bc56 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Sun, 21 Feb 2021 18:32:04 -0500 Subject: Proper support for favicons, rigid body intersections are no longer broken, palinko game --- frontend/2d_part_1.html | 126 +++++++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 61 deletions(-) (limited to 'frontend/2d_part_1.html') diff --git a/frontend/2d_part_1.html b/frontend/2d_part_1.html index 312611a..830f201 100644 --- a/frontend/2d_part_1.html +++ b/frontend/2d_part_1.html @@ -7,6 +7,7 @@ Physics for Games + @@ -26,68 +27,71 @@ 2D - Rotational Forces 2D - Collision Forces -
-

Part 1: Linear Forces

-

- The first - and perhaps easiest - part of implementing any rigid body physics system is getting the entities in your scene to move in response to linear forces. - With this implementation alone, you can achieve an interesting level of realism in your 2D (and even 3D) scene. -

-

- Let's begin by recalling the relationships between acceleration, velocity, and position. -

-

- Knowing all this, you should be able to understand the following source code fairly easily; -

-                        
-function update(dtSeconds) {
-    // Add up the forces acting on the circle
-    const GRAVITY = 9.8;
-    const lGravityForce = vec2(0, -1.0 * (lCircle.mass * GRAVITY));
-    lCircle.force = addVec2(lCircle.force, lGravityForce);
-
-    // Figure out acceleration (a = F / m)
-    const lCurrentAcceleration = scaleVec2(lCircle.force, 1.0 / lCircle.mass);
-
-    // Calculate the new velocity: v = v0 + a * t
-    lCircle.velocity = addVec2(lCircle.velocity, scaleVec2(lCurrentAcceleration, dtSeconds));
-
-    // Update the position based on velocity: x = x0 + v * t
-    lCircle.position = addVec2(lCircle.position, scaleVec2(lCircle.velocity, dtSeconds));
-
-    // Update the model matrix accordingly
-    lCircle.model = translateMatrix(mat4(), lCircle.position.x, lCircle.position.y, 0);
-
-    // Reset the force vector for the next update
-    lCircle.force = vec2()
-}
-                        
-                    
-

-
- -
-
    -
  • Linear Force:N/A
  • -
  • Linear Acceleration:N/A
  • -
  • Linear Velocity:N/A
  • -
  • Linear Position:N/A
  • -
-
-
- - - -
- -
+
+
+

Part 1: Linear Forces

+

+ The first - and perhaps easiest - part of implementing any rigid body physics system is getting the entities in your scene to move in response to linear forces. + With this implementation alone, you can achieve an interesting level of realism in your 2D (and even 3D) scene. +

+

+ Let's begin by recalling the relationships between acceleration, velocity, and position. +

+

+ Knowing all this, you should be able to understand the following source code fairly easily; +

+                            
+    function update(dtSeconds) {
+        // Add up the forces acting on the circle
+        const GRAVITY = 9.8;
+        const lGravityForce = vec2(0, -1.0 * (lCircle.mass * GRAVITY));
+        lCircle.force = addVec2(lCircle.force, lGravityForce);
+    
+        // Figure out acceleration (a = F / m)
+        const lCurrentAcceleration = scaleVec2(lCircle.force, 1.0 / lCircle.mass);
+    
+        // Calculate the new velocity: v = v0 + a * t
+        lCircle.velocity = addVec2(lCircle.velocity, scaleVec2(lCurrentAcceleration, dtSeconds));
+    
+        // Update the position based on velocity: x = x0 + v * t
+        lCircle.position = addVec2(lCircle.position, scaleVec2(lCircle.velocity, dtSeconds));
+    
+        // Update the model matrix accordingly
+        lCircle.model = translateMatrix(mat4(), lCircle.position.x, lCircle.position.y, 0);
+    
+        // Reset the force vector for the next update
+        lCircle.force = vec2()
+    }
+                            
+                        
+

+
+ +
+
    +
  • Linear Force:N/A
  • +
  • Linear Acceleration:N/A
  • +
  • Linear Velocity:N/A
  • +
  • Linear Position:N/A
  • +
+
+
+ + + +
+ +
+
+ +
- - -
+ +
\ No newline at end of file -- cgit v1.2.1