27 #include <glm/vec3.hpp>
28 #include <glm/glm.hpp>
29 #include <glm/gtc/matrix_transform.hpp>
30 #include <glm/gtc/type_ptr.hpp>
31 #include <glm/gtx/intersect.hpp>
33 #include "eng3d/camera.hpp"
34 #include "eng3d/value_chase.hpp"
43 :
Camera(_screen_size, _map_size)
57 void move(
float x_dir,
float y_dir,
float z_dir)
override {
86 out_pos.x = glm::mod(out_pos.x,
map_size.x);
94 glm::vec3 up_vector = glm::vec3(0.f, -1.f, 0.f);
99 const float mouse_x = mouse_pos.x;
100 const float mouse_y =
screen_size.y - 1.f - mouse_pos.y;
104 const glm::vec3 world_space_near = glm::unProject(
105 glm::vec3(mouse_x, mouse_y, 0.f),
109 const glm::vec3 world_space_far = glm::unProject(
110 glm::vec3(mouse_x, mouse_y, 1.f),
115 glm::vec3 ray_direction = world_space_far - world_space_near;
117 float distance = 0.f;
118 bool hit = glm::intersectRayPlane(world_space_near, ray_direction, glm::vec3(0, 0, 0), glm::vec3(0, 0, 1), distance);
120 glm::vec3 intersection_point = world_space_near + ray_direction * distance;
121 out_pos.x = intersection_point.x;
122 out_pos.x = glm::mod((
float)out_pos.x,
map_size.x);
123 out_pos.y = intersection_point.y;
124 if(intersection_point.y < 0 || intersection_point.y >
map_size.y)
130 return glm::vec3(tile_pos.x, tile_pos.y, 0.f);
virtual glm::mat4 get_projection() const
Get the projection matrix.
void move(float x_dir, float y_dir, float z_dir) override
Move the camera in the specified direction. Uses the map coordinate system, where the Z-axis is the m...
FlatCamera(glm::vec2 _screen_size, glm::vec2 _map_size)
void update() override
Update the movement of the camera. Used for smooth camera movement.
ValueChase< glm::vec3 > chase
bool get_cursor_map_pos(glm::ivec2 mouse_pos, glm::ivec2 &out_pos) const override
Get the cursors position on the map.
glm::vec3 get_tile_world_pos(glm::vec2 tile_pos) const override
Get the tiles world position.
void set_pos(float x, float y) override
Set the map position of the camera.
FlatCamera(const Camera &camera)
glm::vec3 get_map_pos() const override
Get the map position of the camera.
glm::mat4 get_view() const override
Get the view matrix.
constexpr T move_towards(T current, T target)