-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.h
85 lines (62 loc) · 3 KB
/
camera.h
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
#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 "vec3.h" // Include our custom Vec3 class
class Camera
{
protected:
// Camera position
Vec3<double> position;
// Camera rotation
Vec3<double> rotation;
// Camera movement speed. When we call the move() function on a camera, it moves using these speeds
Vec3<double> 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 lastX;
int lastY;
// 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;
// Constructor
Camera();
// Destructor
~Camera();
void mouseMoved(int x, int y);
void mouseButtonPressed(int button, int state, int x, int y);
// Mouse movement handler to look around
void handleMouseMove(int mouseX, int mouseY);
void rotateLeft();
void rotateRight();
// 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);
// --------------------------------- Inline methods ----------------------------------------------
// Setters to allow for change of vertical (pitch) and horizontal (yaw) mouse movement sensitivity
float getPitchSensitivity() { return pitchSensitivity; }
void setPitchSensitivity(float value) { pitchSensitivity = value; }
float getYawSensitivity() { return yawSensitivity; }
void setYawSensitivity(float value) { yawSensitivity = value; }
// Position getters
Vec3<double> getPosition() const { return position; }
double getXPos() const { return position.getX(); }
double getYPos() const { return position.getY(); }
double getZPos() const { return position.getZ(); }
// Rotation getters
Vec3<double> getRotation() const { return rotation; }
double getXRot() const { return rotation.getX(); }
double getYRot() const { return rotation.getY(); }
double getZRot() const { return rotation.getZ(); }
};
#endif // CAMERA_H