How to prevent 2D camera rotation if it would violate the bounds of the camera?
- by Andrew Price
I'm working on a Camera class and I have a rectangle field named Bounds that determines the bounds of the camera. I have it working for zooming and moving the camera so that the camera cannot exit its bounds.
However, I'm a bit confused on how to do the same for rotation. Currently I allow rotating of the camera's Z-axis. However, if sufficiently zoomed out, upon rotating the camera, areas of the screen outside the camera's bounds can be shown.
I'd like to deny the rotation assuming it meant that the newly rotated camera would expose areas outside the camera's bounds, but I'm not quite sure how. I'm still new to Matrix and Vector math and I'm not quite sure how to model if the newly rotated camera sees outside of its bounds, undo the rotation. Here's an image showing the problem:
http://i.stack.imgur.com/NqprC.png
The red is out of bounds and as a result, the camera should never be allowed to rotate itself like this. This seems like it would be a problem with all rotated values, but this is not the case when the camera is zoomed in enough.
Here are the current member variables for the Camera class:
private Vector2 _position = Vector2.Zero;
private Vector2 _origin = Vector2.Zero;
private Rectangle? _bounds = Rectangle.Empty;
private float _rotation = 0.0f;
private float _zoom = 1.0f;
Is this possible to do? If so, could someone give me some guidance on how to accomplish this? Thanks.
EDIT: I forgot to mention I am using a transformation matrix style camera that I input in to SpriteBatch.Begin. I am using the same transformation matrix from this tutorial.