Game Development Reference
In-Depth Information
might be required to provide a stable differential. Of particular note with central dif‐
ference forms is that periodic functions that are in sync with your time step may result
in zero slope. If the motion you are tracking is periodic, you should take care to avoid
a time step near the period of oscillation. This is called aliasing and is a problem with
all signal analysis, including computer graphics displays. Also, note that this cannot be
computed until at least three time steps have been stored. In our notation, t [ i −1] is the
center data point, t [ i −2] the backward value, and t [ i ] the forward value. The acceleration
function would therefore be as follows:
Vector findAcceleration (x[i-2], y[i-2], z[i-2], t[i-2], x[i-1], y[i-1], z[i-1],
t[i-1], x[i], y[i], z[i], t[i] ){
float ax, ay, az, h;
vector acceleration;
h = t[i]-t[i-1];
ax = (x[i] − 2*x[i-1] + x[i-2]) / h;
ay = (y[i] − 2*y[i-1] + y[i-2]) / h;
az = (z[i] − 2*z[i-1] + z[i-2]) / h;
return acceleration = {ax, ay, az};
}
Now, let's say that you are tracking a ball in someone's hand. Until he lets it go, the
velocity and acceleration we are calculating could change at any moment in any number
of ways. It is not until the user lets go of the ball that the physics we have discussed takes
over. Hence, you have to optically track it until he completes the throw. Once the ball
is released, the physics from the rest of this topic applies! You can then use the position
at time of release, the velocity vector, and the acceleration vector to plot its trajectory
in the game.
Search Nedrilad ::




Custom Search