Should have seen that one coming

Well, as happens most times when I think I’ve got it all down, further investigation reveals quite the opposite. Long story short, my camera doesn’t work in all cases. Long story long, keep reading.

To determine the furthest distance between focus points (the 2d positional vectors that my camera must keep in view at all times) I was using std::max_element and std::min_element, like so:

where FocusPoints is a container of const references to 2d vectors, and Vec2Predicate is a function pointer for sorting the container by. This is where I made my fatal mistake.

How do you determine whether one point on a Cartesian grid is greater or lesser than another? As far as I know, you can’t. You can tell which is greater on an axis, but that’s it. My function Vec2Predicate compared two vectors on the x axis only. At first it seemed to work fine, but I ran into problems when the focus points were aligned with each-other on Y. As best as I can figure, min_element and max_element were returning the same element. Thus, the distance between the two points was always zero, and the camera never zoomed out. This resulted in actors getting awkwardly close to the edges and, in some cases, going off screen while the camera did nothing.

For obvious reasons, I’ve decided to do away with the entire system involving distance between points and instead use bounding circles. Here’s my plan for the new implementation:

Each frame, loop through the list of focus points
Find which Cartesian quadrant each point lies in
Test a point three meters towards each of the two nearest walls
If either point is off screen, break the loop and zoom out
If the loop finishes without any test points extending past the bounds of the screen, zoom the view in.

I’m really hoping it’ll work…I’ve spent far too much time on this facet of the engine and I’m longing to move onto something else.

  • Chris Logsdon

    Just read through this, and I’m curious… did this new system work?

    ~Chris Logsdon

    • Jake Albano

      Woah, I totally forgot to post a followup. I should probably do that. But yes, it did work.