Now that we have an understanding of these two fundamental fields of physics, we can begin setting up our rigidbody data structure.
@@ -118,7 +118,7 @@
-
The Dynamics Functions
+
The Functions
Now, let's put that Rigidbody data structure to work! As I mentioned earlier, you can think of dynamics as the input to the system. What we're going to do now is add a way apply some sort of force to our rigidbody instantaneously.
@@ -174,7 +174,7 @@
bool isDead = false;
};
-const int32 NUM_IMPULSES = 4;
+constint32 NUM_IMPULSES = 4;
struct Rigidbody {
int32 numImpulses = 0;
@@ -228,7 +228,7 @@ const int32 NUM_IMPULSES = 4;
void applyImpulse(Impulse i) {
if (numImpulses > NUM_IMPULSES) {
printf("Unable to apply impulse. Buffer full.\n");
- return;
+ return;
}
activeImpulses[numImpulses] = i;
diff --git a/2d/rigidbody/rigidbody_1.html.content b/2d/rigidbody/rigidbody_1.html.content
index c54fdab..567ca98 100644
--- a/2d/rigidbody/rigidbody_1.html.content
+++ b/2d/rigidbody/rigidbody_1.html.content
@@ -51,7 +51,7 @@
-
The Kinematics Data Structure
+
The Data Structure
Now that we have an understanding of these two fundamental fields of physics, we can begin setting up our rigidbody data structure.
@@ -61,7 +61,7 @@
-
The Dynamics Functions
+
The Functions
Now, let's put that Rigidbody data structure to work! As I mentioned earlier, you can think of dynamics as the input to the system. What we're going to do now is add a way apply some sort of force to our rigidbody instantaneously.
diff --git a/2d/rigidbody/rigidbody_2.html b/2d/rigidbody/rigidbody_2.html
index 4d85e50..53df782 100644
--- a/2d/rigidbody/rigidbody_2.html
+++ b/2d/rigidbody/rigidbody_2.html
@@ -68,13 +68,186 @@
Rigidbody #2: Rotational Forces
+
+ Now that we have linear forces acting upon the 2D objects in our scene, it is about time we incorporate rotational forces into our simulation. Please keep in mind that I do not go too into depth on why the rotational quantities and formulas are the way that they are. If you are looking for this information, I have linked to some great articles on physics (specifically Chris Hecker's articles!) on the home page.
+
-
Explanation
+
What are rotational forces?
+
+ Rotational forces help us to model how an object is rotating around its center of mass. The great part is that they have a lot in common with their linear counterparts: torque (τ) is the rotational equivalent of linear force; angular acceleration (α) is the rotational equivalent of linear acceleration; angular velocity (ω) is the rotational equivalent of linear velocity; moment of inertia (I) is the rotational equivalent of center of mass; and the current rotation of an object is the equivalent of the position of the object. In two dimensions, all of the angular quantities can be defined using a single floating point number (in 3D, this gets a little more complicated).
+
+
+
+
The Data Structure
+
+ Rotational forces introduce three new quanities into our Rigid Body data structure:
+
+
Rotational Velocity(float): Much like linear velocity, this value defines the rate at which our object is currently rotating around its center of mass.
+
Rotation(float): Much like position in the linear world, this value describes the current rotation of our object around its center of mass.
+
Moment of inertia(float): This quanitity defined how much our object wants to rotate around its center of mass. A higher moment of inertia means an object is less likely to rotate, while a lower moment of a inertia means an object is more likely to rotate.
+
+
+ Adding these three new quanities to the Rigidbody struct from last time, we get someting that looks like this:
+
+
+ Now, that's enough for the data side, let's see how we can input some forces into this data structure to make it move.
+
+
+
+
The Functions
+
+ When we inputted a force into our system in the first rigidbody example, we simply told the system "apply this force to the whole object over time." With the introduction of the rotational quantities into our model, we now say "apply this force at this particualr point of the object over time." This point is what we'll call the point of application. Our Impulse struct from last time will now look something like this:
+
+
+ So what's the big deal about including this point of application? Well, from physics, we get the following formula:
+
+
+
+
+
+ In laymen's terms, this says that the torque is equal to the perpendicular of the force at r, which is the point of application. When you think about this in your head, it makes a lot of sense. For example, if you smack the top of a pencil from the top with your hand, it's not really going to rotate. However, if you smack the top of the pencil from the side with your hand, it is going to rotate a lot. This is because taking the cross product of the end of the pencil (i.e. the point of application) with the force of your hand (i.e. the force acting on the object) is much larger when r is perpendicular to F.
+
+
+
+ One thing to note is that, in 2D, we do not have the cross product, per se. The closest thing we can do is get the vector perpendicular to another vector using the following function:
+
+
Vector2 getPerp() {
+ return { y, -x };
+}
+
+
+
+ Now that we've calculate torque, we just need to get angular acceleration, which, when differentiated with respect to time, will yield the velocity and position. Angualr acceleration relates to torque according to this formula:
+
+
+
+
+
+ The I in this case refers to the moment of inertia that I mentioned earlier. As you can tell, the larger the moment of inertia, the less like my object is going to be rotating. You can experience moment of inertia with the following example: Grab the middle of a pencil between your index and thumb fingers. Rotate it back and forth, and note how easy it is do so. Next, grab the end of the pencil and do the same thing. Note that it feels slightly more difficult to rotate the pencil now. This is because of moment of inertia! While you can calculate this quanitity (either manually or programatically), you will find the moment of inertia of many simple objects online.
+
+
+
+ With all of this in mind, we're ready for the code that puts it all together!:
+
+