-
Notifications
You must be signed in to change notification settings - Fork 5
Camera
Gl2d has its metric system in pixels, this is not really good if you want to ship a game with it so for that you have a camera. You can move your camera around and zoom it in and out.
- position: the position of the camera.
- rotation: the rotation of the camera, degrees.
- zoom: zoom of the camera.
- follow(): Used to follow objects (player for example). The followed object (pos) will get placed in the center of the screen. Min is the minimum distance for the camera to start moving and max is the maximum possible distance. w and h are the dimensions of the window.
Use the follow method to easily place your camera where you want on the screen. The position member can be misleading to use, especially with zoom.
The renderer class has a camera. Whenever you render something, it will always use the current camera. So you can change the camera mid-drawing.
To render Ui for example, you usually need your camera to be the default one because you want the UI to cover your entire screen. So you can do this:
renderer2D.pushCamera(); //resets the camera temporarily
//...draw UI;
renderer2D.popCamera(); //gets back to the previous camera
-
glm::vec4 toScreen(const glm::vec4& transform): converts pixels to screen (top left) (bottom right), essentially applying the camera
-
glm::vec4 getViewRect(): returns the view coordinates of the camera. Doesn't take rotation into account, only size and position! This is what you can use for making a game like Terraria to not draw blocks that can't be seen. Add a bias to it because the floating point imprecisions seem to compound very quickly!