Scratch 2, 1 Remaining, 1 New.
The “negative slope bug” was caused by accidentally reversing X and Y in a statement. Fixing that cleared up the problem with the oddly reversing lines. Of course, a positive slope should have gotten just as screwed by the problem. Whatever. It works now.
I also found a mitigation for the duplicate paddle contours causing a jittery trajectory. I changed a parameter to cvFindContours to use the External contour retrieval mode, rather than List. I think the duplicate contours weren’t really duplicates at all, but were actually inner and outer contours around the object. That is, in certain frames, the paddle looked like a donut to the algorithm, rather than a solid block, so I was getting concentric contours representing the inside and outside of that donut. External looks like it simply gives a bounding box, which is what I wanted anyway. There are still occasional jitters, but I think I can live with them. It’s running much smoother now.
That still leaves the integer extrapolation issue, which should be fairly straightforward to take care of. Just look in the history for a few more points and get a clearer trajectory.
Another bug was exposed after I fixed the two big problems. While I was working out the calculation for the intersection between the extrapolated trajectory and the boundary walls, I noted a case where there’d be a division by zero, if the slope ever happened to be zero, so I put in a guard clause against that. However, at the time, I didn’t think about the fact that a zero slope is, in fact, perfectly acceptable in Pong. If you hit the ball at the middle of your paddle, it’s bounced back straight across the playfield.
0 comments
Kick things off by filling out the form below.
Leave a Comment