TazGraph Project v0.1.0
Loading...
Searching...
No Matches
ICamera.h
1#pragma once
2
3#define GLM_ENABLE_EXPERIMENTAL
4#include <glm/glm.hpp>
5#include <glm/gtc/matrix_transform.hpp>
6#include <glm/gtx/rotate_vector.hpp>
7#include <SDL2/SDL.h>
8
9enum class ViewMode {
10 Y_UP,
11 Z_UP
12};
13
14class ICamera {
15public:
16 int _screenWidth = 800, _screenHeight = 640;
17
18 glm::vec3 eyePos{ 0,0,0 };
19 glm::vec3 aimPos{ 0,0,0 };
20 glm::vec3 upDir{ 0,-1,0 };
21 float zFar = 1000000.0f;
22
23 ViewMode currentViewMode = ViewMode::Y_UP;
24
25 virtual ~ICamera() = default;
26
27 // Initializes the camera2D.worldLocation with the screen's width and height
28 virtual void init() = 0;
29
30 // Updates the camera2D.worldLocation's matrix if there have been any changes
31 virtual void update() = 0;
32
33 // Converts screen coordinates to world coordinates
34 virtual glm::vec2 convertScreenToWorld(glm::vec2 screenCoords) const = 0;
35
36 // Returns the dimensions of the camera2D.worldLocation's view
37 virtual glm::ivec2 getCameraDimensions() const = 0;
38
39 // Returns the SDL_Rect representing the camera2D.worldLocation's viewport
40 virtual SDL_FRect getCameraRect() const = 0;
41
42 // Additional methods to expose camera2D.worldLocation properties as needed
43 virtual glm::vec3 getPosition() const = 0;
44 virtual void setPosition(const glm::vec3 newPosition) = 0;
45 virtual void setPosition_X(const float newPosition) = 0;
46 virtual void setPosition_Y(const float newPosition) = 0;
47 virtual void setPosition_Z(const float newPosition) = 0;
48 virtual float getScale() const = 0;
49 virtual glm::mat4 getCameraMatrix() const = 0;
50 virtual glm::vec3 getAimPos() = 0;
51 virtual void setScale(float scale) = 0;
52
53 virtual void makeCameraDirty() = 0;
54 virtual bool hasChanged() = 0;
55 virtual void refreshCamera() = 0;
56
57 void updateCameraOrientation();
58
59 void setOrientation(glm::vec3 eye, glm::vec3 target, glm::vec3 up);
60
61 bool isPointInCameraView(const glm::vec4 point, float margin);
62
63 // Function to cast a ray from screen coordinates into world space
64 glm::vec3 castRayAt(const glm::vec2& screenPos);
65
66 glm::vec3 getPointOnRayAtZ(const glm::vec3& rayOrigin, const glm::vec3& rayDirection, float desiredZ);
67
68 void setViewMatrix(glm::mat4 newViewMatrix);
69
70 glm::mat4 getViewMatrix();
71
72 void setProjMatrix(glm::mat4 newProjMatrix);
73
74 glm::mat4 getProjMatrix();
75
76 glm::vec3 getUpDir();
77protected:
78 glm::mat4 _projectionMatrix = glm::mat4(1.0f); // changed once in init
79 glm::mat4 _viewMatrix = glm::mat4(1.0f);
80 glm::mat4 _cameraMatrix = glm::mat4(1.0f);
81
82 bool _cameraChange = true;
83
84};
Definition ICamera.h:14