YourGameLib
Loading...
Searching...
No Matches
camera.h
Go to the documentation of this file.
1/*
2Copyright (c) 2019-2024 Alexander Scholz
3
4This software is provided 'as-is', without any express or implied
5warranty. In no event will the authors be held liable for any damages
6arising from the use of this software.
7
8Permission is granted to anyone to use this software for any purpose,
9including commercial applications, and to alter it and redistribute it
10freely, subject to the following restrictions:
11
121. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
162. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
183. This notice may not be removed or altered from any source distribution.
19*/
20#ifndef YOURGAME_CAMERA_H
21#define YOURGAME_CAMERA_H
22
23#define GLM_ENABLE_EXPERIMENTAL
24#include <glm/glm.hpp>
25#include <glm/ext.hpp>
26#include "yourgame/math.h"
27#include "yourgame/math/trafo.h"
28
29namespace yourgame
30{
31 namespace math
32 {
33 class Camera
34 {
35 public:
36 Trafo *trafo();
37 glm::mat4 vMat();
38 glm::mat4 pMat();
39 glm::mat4 pMat(float zNear, float zFar);
41 void setPerspective(float fovy, float aspect, float zNear, float zFar);
42 void setOrthographic(float height, float aspect, float zNear, float zFar);
43 void setFovy(float fovy);
44 void setHeight(float height);
45 void setAspect(float aspect);
46 void setZNear(float zNear);
47 void setZFar(float zFar);
48 void rotateFirstPerson(float yaw, float pitch);
50 void castRay(float viewportX, float viewportY, glm::vec3 &dstOrg, glm::vec3 &dstDir);
51
52 private:
53 // Intrinsics
55 float m_fovy = 90.0f;
56 float m_height = 1.0f;
57 float m_aspect = 1.0f;
58 float m_zNear = 0.1f;
59 float m_zFar = 10.0f;
60 glm::mat4 m_pMat = glm::mat4(1.0f); // identity
61 bool m_pMatInvalidated = false;
62 void updatePMatIfInvalidated();
63 glm::mat4 calcPMat(float zNear, float zFar);
64
65 // Extrinsics
66 Trafo m_trafo;
67 float m_firstPersonYaw = 0.0f;
68 float m_firstPersonPitch = 0.0f;
69 glm::mat4 m_vMat = glm::mat4(1.0f); // identity
70 bool m_vMatInvalidated = false;
71 void updateVMatIfInvalidated();
72 };
73 } // namespace math
74} // namespace yourgame
75
76#endif
Definition camera.h:34
void setZFar(float zFar)
Definition camera.cpp:109
Trafo * trafo()
Definition camera.cpp:44
void setPerspective(float fovy, float aspect, float zNear, float zFar)
Definition camera.cpp:59
void setAspect(float aspect)
Definition camera.cpp:97
void castRay(float viewportX, float viewportY, glm::vec3 &dstOrg, glm::vec3 &dstDir)
viewportX,viewportY in [0.0,1.0]
Definition camera.cpp:124
glm::mat4 pMat()
Definition camera.cpp:33
void setZNear(float zNear)
Definition camera.cpp:103
void setOrthographic(float height, float aspect, float zNear, float zFar)
Definition camera.cpp:69
glm::mat4 vMat()
Definition camera.cpp:27
void setProjection(math::Projection proj)
Definition camera.cpp:50
void setFovy(float fovy)
Definition camera.cpp:79
void rotateFirstPerson(float yaw, float pitch)
Definition camera.cpp:115
void setHeight(float height)
Definition camera.cpp:88
Definition trafo.h:33
Projection
Definition math.h:28
Definition audio.h:27