During the last week I've been developing a camera library. It's on github, as usual:
It does translating, scaling, and rotation. It also transforms screen coords into world coords. That much is "usual". The special things:
- A method, :getVisible() will give you a the region that the camera is seeing, taking into account things like scale and rotation. You can use it to optimize and don't draw anything outside that region.
- The system tries very, very hard not to show you any "world edges". It adjusts its position and scale levels so that you never see the "world ends" by default.
- This is a small thing, but it defines a "window" - the region of the screen where it can draw. The window can only be rectangular.
- The getVisibleCorners method returns the 4 corners of the rotated rectangle containing the region of space visible by the camera
I'm attaching a demo showing two different cameras displaying the game world. The left camera is the "main" one, while the other one is a "minimap" of sorts. It displays the same as the main camera, zoomed out, and the "visible area" of the first cam as a blueish rectangle. Inside it, a rotated rectangle shows the "real" visible rectangle, rotation included. The blue rectangle is cam1:getVisible(), the other one is cam1:getVisibleCorners()
Controls: Mouse moves the "target" around. Up/Down changes scale on main camera. Left/Right changes angle on main camera. Esc exits.
You can not see it, but only the visible cells of the "world matrix" are drawn, depending on the visible zone. I think it's quite neat.
v1.0.1 fixes a buggy implemenation of toScreen()
Having vrld's hump.camera module helped me significantly on the tricky trigonometric calculations, but I feel the code is different enough from his lib to guarantee a separate license (MIT in any case). If you need a camera system and gamera doesn't meet your needs, you should check hump.camera out.