CG_Labs 2021.2
Loading...
Searching...
No Matches
FPSCamera.h
Go to the documentation of this file.
1#pragma once
2
3#include "TRSTransform.h"
4#include "InputHandler.h"
5
6#include <glm/glm.hpp>
7#define GLM_ENABLE_EXPERIMENTAL
8#include <glm/gtx/io.hpp>
9
10#include <chrono>
11#include <iostream>
12
13template<typename T, glm::precision P>
15{
16public:
17 FPSCamera(T fovy, T aspect, T nnear, T nfar);
18 ~FPSCamera();
19
20public:
21 void Update(std::chrono::microseconds deltaTime, InputHandler &ih, bool ignoreKeyEvents = false, bool ignoreMouseEvents = false);
22 void SetProjection(T fovy, T aspect, T nnear, T nfar);
23 void SetFov(T fovy);
24 T GetFov();
25 void SetAspect(T a);
26 T GetAspect();
27
28 glm::tmat4x4<T, P> GetViewToWorldMatrix();
29 glm::tmat4x4<T, P> GetWorldToViewMatrix();
30 glm::tmat4x4<T, P> GetClipToWorldMatrix();
31 glm::tmat4x4<T, P> GetWorldToClipMatrix();
32 glm::tmat4x4<T, P> GetClipToViewMatrix();
33 glm::tmat4x4<T, P> GetViewToClipMatrix();
34
35 glm::tvec3<T, P> GetClipToWorld(glm::tvec3<T, P> xyw);
36 glm::tvec3<T, P> GetClipToView(glm::tvec3<T, P> xyw);
37
38public:
40 glm::tvec3<T, P> mMovementSpeed;
41 glm::tvec2<T, P> mMouseSensitivity;
42
43public:
45 glm::tmat4x4<T, P> mProjection;
46 glm::tmat4x4<T, P> mProjectionInverse;
47 glm::tvec2<T, P> mMousePosition;
48
49public:
50 friend std::ostream &operator<<(std::ostream &os, FPSCamera<T, P> &v) {
51 os << v.mFov << " " << v.mAspect << " " << v.mNear << " " << v.mFar << std::endl;
52 os << v.mMovementSpeed << " " << v.mMouseSensitivity << std::endl;
53 os << v.mWorld;
54 return os;
55 }
56 friend std::istream &operator>>(std::istream &is, FPSCamera<T, P> &v) {
57 T fov, aspect, nnear, far;
58 is >> fov >> aspect >> nnear >> far;
59 v.SetProjection(fov, aspect, nnear, far);
61 is >> v.mWorld;
62 return is;
63 }
64};
65
66#include "FPSCamera.inl"
67
FPSCamera< double, glm::defaultp > FPSCamerad
Definition FPSCamera.h:69
FPSCamera< float, glm::defaultp > FPSCameraf
Definition FPSCamera.h:68
Definition FPSCamera.h:15
void Update(std::chrono::microseconds deltaTime, InputHandler &ih, bool ignoreKeyEvents=false, bool ignoreMouseEvents=false)
Definition FPSCamera.inl:49
glm::tmat4x4< T, P > GetClipToViewMatrix()
Definition FPSCamera.inl:106
glm::tvec2< T, P > mMouseSensitivity
Definition FPSCamera.h:41
glm::tmat4x4< T, P > GetWorldToViewMatrix()
Definition FPSCamera.inl:88
T GetAspect()
Definition FPSCamera.inl:42
~FPSCamera()
Definition FPSCamera.inl:8
glm::tmat4x4< T, P > GetViewToClipMatrix()
Definition FPSCamera.inl:112
glm::tmat4x4< T, P > GetViewToWorldMatrix()
Definition FPSCamera.inl:82
TRSTransform< T, P > mWorld
Definition FPSCamera.h:39
glm::tvec3< T, P > mMovementSpeed
Definition FPSCamera.h:40
void SetProjection(T fovy, T aspect, T nnear, T nfar)
Definition FPSCamera.inl:13
T mNear
Definition FPSCamera.h:44
glm::tmat4x4< T, P > mProjectionInverse
Definition FPSCamera.h:46
T mFov
Definition FPSCamera.h:44
T GetFov()
Definition FPSCamera.inl:30
glm::tmat4x4< T, P > GetWorldToClipMatrix()
Definition FPSCamera.inl:100
glm::tvec3< T, P > GetClipToWorld(glm::tvec3< T, P > xyw)
Definition FPSCamera.inl:118
friend std::istream & operator>>(std::istream &is, FPSCamera< T, P > &v)
Definition FPSCamera.h:56
void SetAspect(T a)
Definition FPSCamera.inl:36
glm::tmat4x4< T, P > GetClipToWorldMatrix()
Definition FPSCamera.inl:94
glm::tvec2< T, P > mMousePosition
Definition FPSCamera.h:47
void SetFov(T fovy)
Definition FPSCamera.inl:24
T mAspect
Definition FPSCamera.h:44
glm::tmat4x4< T, P > mProjection
Definition FPSCamera.h:45
T mFar
Definition FPSCamera.h:44
glm::tvec3< T, P > GetClipToView(glm::tvec3< T, P > xyw)
Definition FPSCamera.inl:126
friend std::ostream & operator<<(std::ostream &os, FPSCamera< T, P > &v)
Definition FPSCamera.h:50
Definition InputHandler.h:19
Definition TRSTransform.h:34