Skip to content

Instantly share code, notes, and snippets.

@jsancheznet
Last active November 5, 2016 21:14
Show Gist options
  • Save jsancheznet/d1b436618a5ad125df27 to your computer and use it in GitHub Desktop.
Save jsancheznet/d1b436618a5ad125df27 to your computer and use it in GitHub Desktop.
Equation of Motion
/*
// THIS CODE DOES NOT COMPILE, ITS PSEUDOCODE IN C'ish style
1- Calculate the Sum of Forces for an object
2- Acceleration is proportional to the sum of forces
3- Calculate Velocity
4- Calculate Position
*/
v2 Acceleration = {};
v2 Velocity = {};
v2 Position = {};
v2 Gravity = {};
v2 Gravity = {0.0f, 9.81f}; // Top->Down Cartesian system (SDL Like)
// Add Gravity to the Sum of Forces
Acceleration += Gravity;
NewVelocity = Acceleration * TimeStep + OldVelocity;
NewPosition = (1/2 * Acceleration * (TimeStep * TimeStep) + OldVelocity * TimeStep + OldPosition;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment