Monday, July 9, 2012

Movimentum - Visually debugging a small hiccup

When one watches that hockey stick movie, one sees that the stick does not move smoothly. What is the reason? Are the solutions wrong? Let me add a little more debugging output, this time for successful nodes ... ok, I'm back. Here is the new output for the hockey stick test case, where I deleted all variable assignments except for the B.P.X variable:

++++ solution node ++++
SolverNode 1036 < 0<=C-1035 < 0=C...
  B.P.X = 60
  .....

++++ solution node ++++
SolverNode 1073 < 0<=C-1072 < 0=C...
  B.P.X = 60.0500000001
  .....

++++ solution node ++++
SolverNode 1110 < 0<=C-1109 < 0=C...
  B.P.X = 60.1000000002
  .....

++++ solution node ++++
SolverNode 1147 < 0<=C-1146 < 0=C...
  B.P.X = 60.1500000003
  .....

It is easy to see that B.P.X grows by 0.05 (and a tiny bit more) in each frame. But ... these values are then directly interpreted as pixel coordinates—which are integer numbers! Therefore, it takes 20 frames, or a full second, until the stick moves one pixel. No wonder it hops along. The culprit is the test input. Part of it looks as follows:

.config (20, 200, 200);
...

@0  B.P = [60 + .t, 60 + .t];
...

We have 20 frames per second; and we increase the coordinates of B.P by one in each second! One can call this "garbage in, garbage out."

The solution? If we change this to move the stick 20 pixels per second (and modify it to get a little more fun), we immediately get a smooth ride:


No comments:

Post a Comment