Last week we started getting into interpolation and splines and the math behind it, so this weekend I decided to apply the knowledge immediately and complete at least two of the interpolation assignments.
First I added a linear interpolation function to an existing 3D vector class I had already created. The next step was setting up the SFML input so that it converted mouse coordinates to OpenGL coordinates. I drew a 2D sprite and tested the interpolation function with a few points and a simple algorithm to step through all the points and it worked.
Next I set up a vector of positions and when the user clicked a point was added to the vector. Everything worked fine in the first assignment, and I had very little trouble cycling through the keyframes and the sprite seemed to be interpolating just fine. Then I noticed some smaller movements that weren't supposed to be in there. After setting up a few output messages I discovered that because my implementation of SFML uses real-time input as opposed to event based input, several keyframes are being duplicated and keyframes the are very close to each other are also being added, so occasionally it looks like nothing is happening, but the sprite is in fact interpolating. Those little movements drove me crazy for the longest time, even though they usually lasted 2 seconds or less.
I added a reset for the keyframes vector and finished the assignment.
I moved on to the second question in the easy level assignments. This one took me a little longer to fully grasp the math. I couldn't seem to understand how the algorithm actually worked. I read through the slides from class, then I read from the text book, then I researched a little online. What I didn't understand, and most likely missed during class, was whether or not the catmull-rom spline would result in interpolation through all four points or just two.
I eventually discovered that to get it to go through all 4 points, all I needed to do was repeat the first and last keyframes and step through 4 points at a time. I did that and the code ran for any number of points and passed through all of them as long as the first and last were repeated. Next I tried to add input so that a user could click at least four points and then the sprite would start to interpolate.
When I started testing with input the sprite would sometimes go right past a point and continue infinitely, even though a simple output statement showed it had indeed reached that point. Turns out when doing my comparisons, there would be a difference of say 0.000000001 that wasn't being output to the console. I added a condition that should a point come within that range, it should move on to interpolating to the next point. It worked for some points but eventually I reduced the difference down to 0.00001 and that yielded much better results that were still accurate.
All in all, I have grasped and I understand both interpolation methods and hopefully when I move on to the next assignments I have the same success that I did on these ones.