Seems like a reasonable approach, right? It was. Those functions determine the angle of any vector just fine as far as I could tell. Let's pop over to the Sled class (the sled rides the lines) and grab the Euler angle of the line (do you feel that chill in your spine?):
Okay we're getting a little less reasonable now, but this was my solution to get the angle of the colliding line segment at least mostly correct.
First, I have a bit of boolean functionality to test whether it is the first frame of collision (I wanted to do this all without using contact points, as time was running out and finishing making this was becoming less and less possible). To find the rotational velocity of an object that is revolving around a point, given the linear velocity, is a simple enough task. It's simply the linear velocity divided by the distance of the object to the axis of rotation. Since I was not using contact points, and was just rotating about the center of the object, that distance was zero. So I just took that part out, which is valid.
After all this, it appeared that my angle math just didn't align with SFML rotations. Which makes sense, I am pretty arbitrarily defining the point of rotation. I tried simply adding and subtracting 90, 180, 270 degrees to and from the draw angle, but things just didn't work.
So getting the rotational velocity didn't happen, but the rest of it works pretty well! I used a distance check to detect whether lines were worth trying the SAT (Separating Axis Theorem) test with the sled. I got to write a pretty special version of it to handle collision not with another convex polygon, but with a line. I also had to be able to collide with the bottom of the line, so I implemented a special, yet very close to normal, version of SAT.
Phase 1:
Phase 2:
I also did some tricky stuff with line drawing to make the lines. Each connected series of lines was its own std::vector of sf::VertexArrays contained within one big 2d vector of these lines. I made it so the user can, after drawing any amount of lines, continue drawing existing lines. I also added a few constraints on how the user can draw lines to avoid ridiculous angles and make smooth lines.
Even though this didn't work out as I had hoped, feel free to pull the repository and play around with it. It's a Mercurial repository, go ahead and
hg clone https://nicholaspedalino@bitbucket.org/nicholaspedalino/line-rider
to play around with it. Here's a video link to see the final demo: