TazGraph Project v0.1.0
Loading...
Searching...
No Matches
OrthoCamera.h
1#pragma once
2#include "ICamera.h"
3
4
5class OrthoCamera : public ICamera {
6public:
7
8
10 {
11 _scale = 1.0f;
12 eyePos = glm::vec3(0.f, 0.f, -770.0f);
13 aimPos = glm::vec3(0.f, 0.f, 0.f);
14 }
16 {
17
18 }
19
20 void init() override {
21
22 _projectionMatrix = glm::ortho(0.0f, (float)_screenWidth, 0.0f, (float)_screenHeight);
23
24 updateCameraOrientation();
25
26 _cameraMatrix = glm::mat4(1.0f);
27
28 _cameraMatrix = _projectionMatrix * _viewMatrix;
29 }
30
31 void update() override {
32
33 if (_cameraChange) {
34 updateCameraOrientation();
35
36 _cameraMatrix = glm::mat4(1.0f);
37
38 _cameraMatrix = _projectionMatrix * _viewMatrix;
39 }
40 }
41
42
43
44 glm::vec3 getEulerAnglesFromDirection(glm::vec3 direction) {
45 float yaw = glm::atan(direction.x, direction.z);
46 float pitch = glm::asin(-direction.y);
47 float roll = 0.0f;
48
49 return glm::vec3(glm::degrees(pitch), glm::degrees(yaw), glm::degrees(roll));
50 }
51
52
53 //getters
54
55 glm::ivec2 getCameraDimensions() const override {
56 glm::vec2 cameraDimensions = { _screenWidth, _screenHeight };
57 return cameraDimensions;
58 }
59
60 SDL_FRect getCameraRect() const override {
61 float cameraWidth = getCameraDimensions().x / getScale();
62 float cameraHeight = getCameraDimensions().y / getScale();
63
64 float cameraX = eyePos.x - cameraWidth / 2.0f + getCameraDimensions().x / 2;
65 float cameraY = eyePos.y - cameraHeight / 2.0f + getCameraDimensions().y / 2;
66
67 SDL_FRect cameraRect = { cameraX , cameraY , cameraWidth, cameraHeight };
68 return cameraRect;
69 }
70
71 void setCameraMatrix(glm::mat4 newMatrix) {
72 _cameraChange = true;
73 }
74
75};
Definition ICamera.h:10
Definition OrthoCamera.h:5