6#include <brenta/camera.hpp>
7#include <brenta/logger.hpp>
10using namespace brenta;
14 this->cam_type = conf.cam_type;
15 this->proj_type = conf.proj_type;
16 this->position = conf.position;
18 this->
center = conf.center;
20 this->mouse_sensitivity = conf.mouse_sensitivity;
21 this->
zoom = conf.zoom;
24 this->
front = conf.front;
26 this->
right = conf.right;
29 switch (this->cam_type)
31 case camera_type::spherical:
34 case camera_type::aircraft:
42glm::mat4 camera::get_view_matrix()
44 switch (this->cam_type)
46 case camera_type::spherical:
48 case camera_type::aircraft:
49 return glm::lookAt(this->position, this->position + this->
front, this->
up);
51 return glm::mat4(1.0f);
55glm::mat4 camera::get_projection_matrix(
int window_width,
int window_height)
57 switch (this->proj_type)
59 case projection_type::perspective:
60 return glm::perspective(glm::radians(this->
zoom),
62 / (
float) window_height,
64 case projection_type::orthographic:
65 return glm::ortho((
float) -window_width / 2.0f,
66 (
float) window_width / 2.0f,
67 (
float) -window_height / 2.0f,
68 (
float) window_height / 2.0f, 0.1f, 100.0f);
70 return glm::mat4(1.0f);
99 this->
front = glm::normalize(new_front);
102 this->
up = glm::normalize(glm::cross(this->
right, this->
front));
105camera::camera_type camera::get_camera_type()
107 return this->cam_type;
110void camera::set_camera_type(camera::camera_type camera_type)
112 this->cam_type = camera_type;
115camera::projection_type camera::get_projection_type()
117 return this->proj_type;
120void camera::set_projection_type(projection_type projection_type)
122 this->proj_type = projection_type;
125glm::vec3 camera::get_position()
127 return this->position;
130void camera::set_position(glm::vec3 position)
132 this->position = position;
135glm::vec3 camera::get_world_up()
140void camera::set_world_up(glm::vec3 world_up)
145glm::vec3 camera::get_center()
150void camera::set_center(glm::vec3 center)
155float camera::get_movement_speed()
160void camera::set_movement_speed(
float movement_speed)
165float camera::get_mouse_sensitivity()
167 return this->mouse_sensitivity;
170void camera::set_mouse_sensitivity(
float mouse_sensitivity)
172 this->mouse_sensitivity = mouse_sensitivity;
175float camera::get_zoom()
180void camera::set_zoom(
float zoom)
190void camera::set_spherical_coordinates(
206glm::vec3 camera::get_front()
211void camera::set_front(glm::vec3 front)
216glm::vec3 camera::get_up()
221void camera::set_up(glm::vec3 up)
226glm::vec3 camera::get_right()
231void camera::set_right(glm::vec3 right)
241void camera::set_first_mouse(
bool first_mouse)
271camera::builder::camera_type(camera::camera_type camera_type)
273 this->conf.cam_type = camera_type;
278camera::builder::projection_type(camera::projection_type projection_type)
280 this->conf.proj_type = projection_type;
286 this->conf.position = position;
298 this->conf.center =
center;
308camera::builder &camera::builder::mouse_sensitivity(
float mouse_sensitivity)
310 this->conf.mouse_sensitivity = mouse_sensitivity;
316 this->conf.zoom =
zoom;
336 this->conf.front =
front;
348 this->conf.right =
right;
354 return camera(this->conf);
Builder pattern for the Camera class.
types::spherical_coordinates spherical_coordinates
Spherical coordinates.
glm::vec3 front
Front vector.
void set_last_y(float last_y)
Set the last y position of the mouse.
float last_x
Last x position of the mouse.
void set_last_x(float last_x)
Set the last x position of the mouse.
glm::vec3 right
Right vector.
glm::vec3 world_up
The world up vector.
float get_last_x()
Get the last x position of the mouse.
void update_camera_euler()
Update the camera euler angles.
float movement_speed
Space translational movement speed.
bool get_first_mouse()
Get the first mouse flag.
camera()=default
Default constructor.
types::euler_angles euler_angles
Euler angles.
void spherical_to_cartesian()
Update the camera spherical coordinates.
float zoom
Zoom level (field of view)
bool first_mouse
Is the first mouse movement?
glm::vec3 center
The center of the spehere.
float get_last_y()
Get the last y position of the mouse.
float last_y
Last y position of the mouse.