-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcamera.h
More file actions
95 lines (69 loc) · 2.96 KB
/
Copy pathcamera.h
File metadata and controls
95 lines (69 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef CAMERA_H
#define CAMERA_H
#include <iostream>
#include <math.h> // Used only for sin() and cos() functions
#include <GLFW/glfw3.h> // Include OpenGL Framework library for the GLFW_PRESS constant only!
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/matrix_inverse.hpp"
#include "glm/gtc/type_ptr.hpp"
class Camera
{
protected:
// Camera position
glm::vec3 position;
// Camera rotation
glm::vec3 rotation;
// Camera movement speed. When we call the move() function on a camera, it moves using these speeds
glm::vec3 speed;
double movementSpeedFactor; // Controls how fast the camera moves
double pitchSensitivity; // Controls how sensitive mouse movements affect looking up and down
double yawSensitivity; // Controls how sensitive mouse movements affect looking left and right
// Window size in pixels and where the midpoint of it falls
int windowWidth;
int windowHeight;
int windowMidX;
int windowMidY;
GLFWwindow* window;
// Method to set some reasonable default values. For internal use by the class only.
void initCamera();
public:
static const double TO_RADS; // The value of 1 degree in radians
// Holding any keys down?
bool holdingForward;
bool holdingBackward;
bool holdingLeftStrafe;
bool holdingRightStrafe;
// Altitude lock flag, default is on, set false for forward movement to be aligned to camera forward.
bool altLock;
// Constructor
Camera(GLFWwindow* window, float windowWidth, float windowHeight);
// Destructor
~Camera();
// Mouse movement handler to look around
void handleMouseMove(GLFWwindow* window, int mouseX, int mouseY);
// Method to convert an angle in degress to radians
const double toRads(const double &angleInDegrees) const;
// Method to move the camera based on the current direction
void move(double deltaTime);
void handleKeypress(GLint key, GLint action);
glm::vec3 getRotVec();
glm::vec3 getUpVec();
// --------------------------------- Inline methods ----------------------------------------------
// Setters to allow for change of vertical (pitch) and horizontal (yaw) mouse movement sensitivity
double getPitchSensitivity() { return pitchSensitivity; }
void setPitchSensitivity(float value) { pitchSensitivity = value; }
double getYawSensitivity() { return yawSensitivity; }
void setYawSensitivity(float value) { yawSensitivity = value; }
// Position getters
glm::vec3 getPosition() const { return position; }
double getXPos() const { return position.x; }
double getYPos() const { return position.y; }
double getZPos() const { return position.z; }
// Rotation getters
glm::vec3 getRotation() const { return rotation; }
double getXRot() const { return rotation.x; }
double getYRot() const { return rotation.y; }
double getZRot() const { return rotation.z; }
};
#endif // CAMERA_H