Ember
A C++ 20 'game engine' built with SDL3 with wide platform support.
camera.h
Go to the documentation of this file.
1 #pragma once
2 #include "transform.h"
3 
14 struct Camera2D {
16 
17  Camera2D(int view_width, int view_height, float zoom = 1.0f) : width(view_width), height(view_height), zoom(zoom) {}
18 
19  glm::mat4 GetViewMatrix() const;
20 
30  glm::vec4 GetViewport() const;
31 
42  bool IsVisible(const glm::vec3& position);
43 
55  void Resize(int view_width, int view_height);
56 
66  glm::mat4 GetProjectionMatrix() const;
67 
68  int GetHeight() const {
69  return height;
70  }
71 
72  int GetWidth() const {
73  return width;
74  }
75 
76  void SetZoom(float zoom) {
77  this->zoom = SDL_clamp(zoom, 0.10f, 10.0f); // ENSURE CAMERA ZOOM NEVER HITS 0
78  }
79 
80  float GetZoom() const {
81  return this->zoom;
82  }
83 
84  float zoom = 1.0f; // MAX_ZOOM = 10.0f
85 private:
86  int width = 0, height = 0;
87 };
Camera2D component.
Definition: camera.h:14
glm::mat4 GetProjectionMatrix() const
Get the projection matrix (orthographic)
Definition: camera.cpp:22
Transform transform
Definition: camera.h:15
int GetHeight() const
Definition: camera.h:68
Camera2D(int view_width, int view_height, float zoom=1.0f)
Definition: camera.h:17
void SetZoom(float zoom)
Definition: camera.h:76
glm::mat4 GetViewMatrix() const
Definition: camera.cpp:4
glm::vec4 GetViewport() const
Get the viewport.
Definition: camera.cpp:28
void Resize(int view_width, int view_height)
Resize the camera view.
Definition: camera.cpp:17
int GetWidth() const
Definition: camera.h:72
bool IsVisible(const glm::vec3 &position)
Check if the position is visible by the camera.
Definition: camera.cpp:11
float zoom
Definition: camera.h:84
float GetZoom() const
Definition: camera.h:80
Definition: transform.h:20