Varying Velocities

The previous formula for computing a moving object's position only works if the object always moves with the same, constant velocity.

In many cases, we will want our objects' velocities to vary over time. Many things could change an object's velocity - gravity, friction, bouncing off of a wall, thrust from an engine, etc.

The general idea, in such a case, is that the velocity V is actually a function of time, and we want to compute an integral of it.

Usually, there will not be an analytical solution to this problem (i.e. a simple formula).
Instead, we must approximate it.

We do this by treating the value of V as a current snapshot of the velocity, and apply the simple linear formula, from the previous slide, on a frame-to-frame basis. i.e.:

      P(t1) = P(t0) + (t1 - t0) * V

where t1 is the time value of the current frame being computed, and t0 is the time of the previous frame.

If we simply use a single variable P to continually recompute the position, and dt for the "delta-time" (time from the previous frame to the current), then in our code the formula becomes:

        P = P + dt * V

If V is constant, then this will produce the same results as the previous formula.

Example: bounce.cpp




next