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