-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.h
More file actions
142 lines (122 loc) · 3.35 KB
/
Camera.h
File metadata and controls
142 lines (122 loc) · 3.35 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#pragma once
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
/**
* @class Camera
* @brief FPS (First Person Shooter) style camera
*
* Features:
* - Position, pitch (up/down), yaw (left/right) rotation
* - WASD movement (forward, backward, strafe left, strafe right)
* - Mouse/arrow controls for rotation
* - Generates view and projection matrices
*/
class Camera
{
private:
// Position
glm::vec3 position;
// Rotation in degrees
float yaw; // Left/right rotation (around Y axis)
float pitch; // Up/down rotation (around X axis)
// Camera vectors
glm::vec3 front;
glm::vec3 right;
glm::vec3 up;
glm::vec3 worldUp;
// Camera settings
float sensitivity;
float speed;
float fov;
float aspect;
float nearPlane;
float farPlane;
/**
* Recalculate camera vectors based on pitch and yaw
*/
void updateCameraVectors();
public:
/**
* Constructor: Initialize FPS camera
* @param pos Initial position
* @param worldUp World up vector (typically (0, 1, 0))
*/
Camera(const glm::vec3& pos = glm::vec3(0.0f, 2.0f, 5.0f),
const glm::vec3& worldUp = glm::vec3(0.0f, 1.0f, 0.0f));
// ===== Movement =====
/**
* Move camera forward/backward
* @param distance Distance to move (positive = forward, negative = backward)
*/
void moveForward(float distance);
/**
* Move camera left/right (strafe)
* @param distance Distance to move (positive = right, negative = left)
*/
void moveRight(float distance);
/**
* Move camera up/down
* @param distance Distance to move (positive = up, negative = down)
*/
void moveUp(float distance);
// ===== Rotation =====
/**
* Rotate camera based on mouse movement (like in FPS games)
* @param xOffset Mouse X offset
* @param yOffset Mouse Y offset
*/
void rotate(float xOffset, float yOffset);
/**
* Set rotation directly via euler angles
* @param yawAngle Yaw in degrees
* @param pitchAngle Pitch in degrees
*/
void setRotation(float yawAngle, float pitchAngle);
// ===== Getters =====
/**
* Get camera position
* @return Position vector
*/
glm::vec3 getPosition() const { return position; }
/**
* Get camera front vector (where camera is looking)
* @return Front vector
*/
glm::vec3 getFront() const { return front; }
/**
* Get view matrix
* @return 4x4 view matrix
*/
glm::mat4 getViewMatrix() const;
/**
* Get projection matrix
* @return 4x4 projection matrix
*/
glm::mat4 getProjectionMatrix() const;
// ===== Setters =====
/**
* Set camera position
* @param pos New position
*/
void setPosition(const glm::vec3& pos) { position = pos; }
/**
* Set movement speed
* @param spd Speed value
*/
void setSpeed(float spd) { speed = spd; }
/**
* Set mouse sensitivity
* @param sens Sensitivity value
*/
void setSensitivity(float sens) { sensitivity = sens; }
/**
* Set field of view
* @param fovDegrees FOV in degrees
*/
void setFOV(float fovDegrees) { fov = fovDegrees; }
/**
* Set aspect ratio
* @param aspectRatio Width / Height
*/
void setAspectRatio(float aspectRatio) { aspect = aspectRatio; }
};