sgltk 0.6
Simple OpenGL Tool Kit
Loading...
Searching...
No Matches
camera.cpp
1#include "camera.h"
2
3using namespace sgltk;
4
6 glm::vec3 direction,
7 glm::vec3 up) {
8
9 this->position = position;
10 this->direction = glm::normalize(direction);
11 right = glm::normalize(glm::cross(direction, glm::normalize(up)));
12 this->up = glm::normalize(glm::cross(right, direction));
13 width = 640.f;
14 height = 480.f;
15 fovy = (float)M_PI;
16 near_plane = 1.0f;
17 far_plane = 800.f;
18
20}
21
22Camera::~Camera() {
23}
24
28
29void Camera::move_up(float delta) {
30 position += glm::normalize(up) * delta;
31}
32
33void Camera::move_right(float delta) {
34 position += glm::normalize(right) * delta;
35}
36
37void Camera::move_forward(float delta) {
38 position += glm::normalize(direction) * delta;
39}
40
41void Camera::move_by(float x, float y, float z) {
42 position.x += x;
43 position.y += y;
44 position.z += z;
45}
46
47void Camera::move_by(glm::vec3 vector) {
48 position += vector;
49}
50
51void Camera::yaw(float angle) {
52 glm::mat3 rot = glm::mat3(glm::rotate(angle, up));
53 direction = glm::normalize(rot * direction);
54 right = glm::normalize(rot * right);
55}
56
57void Camera::roll(float angle) {
58 glm::mat3 rot = glm::mat3(glm::rotate(angle, direction));
59 up = glm::normalize(rot * up);
60 right = glm::normalize(rot * right);
61}
62
63void Camera::pitch(float angle) {
64 glm::mat3 rot = glm::mat3(glm::rotate(angle, right));
65 direction = glm::normalize(rot * direction);
66 up = glm::normalize(rot * up);
67}
float far_plane
The far plane of the camera frustum.
Definition camera.h:37
void move_forward(float delta)
Move the camera along the forward vector.
Definition camera.cpp:37
void move_by(float x, float y, float z)
Move the camera by the vector (x, y, z)
Definition camera.cpp:41
float height
Viewport height.
Definition camera.h:29
glm::vec3 right
The right vector of the camera.
Definition camera.h:57
float width
Viewport width.
Definition camera.h:25
glm::mat4 view_matrix
The view matrix.
Definition camera.h:17
glm::vec3 direction
The direction the camera is pointing.
Definition camera.h:49
void pitch(float angle)
Rotate the camera using the right vector as the axis.
Definition camera.cpp:63
glm::vec3 up
The up vector of the camera.
Definition camera.h:53
void roll(float angle)
Rotate the camera using the forward vector as the axis.
Definition camera.cpp:57
glm::vec3 position
The camera position.
Definition camera.h:45
Camera(glm::vec3 position, glm::vec3 direction, glm::vec3 up)
Definition camera.cpp:5
void move_right(float delta)
Move the camera along the right vector.
Definition camera.cpp:33
float near_plane
The near plane of the camera frustum.
Definition camera.h:41
float fovy
The vertical field of view angle of the camera.
Definition camera.h:33
void update_view_matrix()
Recalculates the view matrix.
Definition camera.cpp:25
void yaw(float angle)
Rotate the camera using the up vector as the axis.
Definition camera.cpp:51
void move_up(float delta)
Move the camera along the up vector.
Definition camera.cpp:29