24#include <glm/gtc/matrix_transform.hpp>
61 glm::vec3 position = glm::vec3(0.0f, 0.0f, 1.0f),
62 glm::vec3
up = glm::vec3(0.0f, 1.0f, 0.0f))
63 :
front(glm::vec3(0.0f, 0.0f, -1.0f))
110 float half_w =
width / 2.0f;
111 float half_h =
height / 2.0f;
129 return glm::vec2(mouse.x -
width / 2.0f,
height / 2.0f - mouse.y);
142 glm::unProject(glm::vec3(mouse.x,
height - mouse.y, 0.1f),
147 return glm::vec2(res.x, res.y);
159 glm::vec3 res = glm::project(glm::vec3(point, 0.1f),
173 float half_h =
height / 2.0f;
185 float half_h =
height / 2.0f;
196 void zoom(
float yoffset, glm::vec2 mouse)
198 if (yoffset > -0.0001 && yoffset < 0.0001)
201 float velocity = -1 * yoffset / 1500.0f * (
target_zoom * 100);
206 glm::vec3(zoom_around + powf(2.0f,
target_zoom * 400) *
233 right = glm::normalize(glm::cross(
249 return glm::vec2(point.x -
width / 2.0f, point.y -
height / 2.0f);
A small utility class that manages the viewport coordinates, together with the virtual "camera" posit...
glm::vec2 screen_mouse_coords(glm::vec2 mouse) const
Convert mouse coordinates ([0,0] in the upper left corner), to screen coordinates ([0,...
void move_y(int dir)
Move view along Y-axis.
void look_at(glm::vec2 tgt)
Cause the camera to look at the specified point.
const float movement_speed
glm::vec2 screen_point_coords(glm::vec2 point) const
Convert point coordinates ([0,0] in the upper left corner), to screen coordinates ([0,...
void zoom(float yoffset, glm::vec2 mouse)
Adjust zoom accordingly.
void update(float dt, int w, int h)
Move the current position and zoom a bit closer to the target position and zoom.
glm::mat4 get_proj_matrix() const
Compute projection matrix for orthographic projection.
void move_x(int dir)
Move view along X-axis.
glm::mat4 get_view_matrix() const
Compute view matrix for drawing into the "view" space.
glm::vec2 screen_coords(glm::vec2 point) const
Converts point to screen coordinates([0,0] in the middle of the screen).
glm::vec2 model_mouse_coords(glm::vec2 mouse) const
Convert mouse coordinates ([0,0] in the upper left corner), to model coordinates ([0,...
void update_view_vectors()
Re-calculates the right and up vector from the View's updated vectors.
View(int width=800, int height=600, glm::vec3 position=glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3 up=glm::vec3(0.0f, 1.0f, 0.0f))