14#include <lagrange/ui/types/Frustum.h>
15#include <lagrange/ui/api.h>
43 enum class Type { PERSPECTIVE, ORTHOGRAPHIC };
51 Camera(Type type = Type::PERSPECTIVE);
62 static Camera default_camera(
float width,
float height, Type type = Type::PERSPECTIVE);
64 void set_type(Type type);
65 Type get_type()
const {
return m_type; }
67 void set_position(
const Eigen::Vector3f& pos);
68 void set_lookat(
const Eigen::Vector3f& dir);
69 void set_position_up(
const Eigen::Vector3f& pos,
const Eigen::Vector3f& up);
70 Eigen::Vector3f get_lookat()
const {
return m_lookat; }
71 void set_up(
const Eigen::Vector3f& up);
73 Eigen::Vector3f get_position()
const;
74 Eigen::Vector3f get_direction()
const;
75 Eigen::Vector3f get_up()
const;
77 float get_far_plane()
const;
78 float get_near_plane()
const;
86 void set_window_dimensions(
float width,
float height);
87 void set_aspect_ratio(
float width,
float height);
94 void set_fov(
float fov);
95 float get_fov()
const {
return m_fov; }
97 void set_planes(
float znear,
float zfar);
98 float get_near()
const {
return m_znear; }
99 float get_far()
const {
return m_zfar; }
106 Eigen::Projective3f get_perspective()
const;
113 Eigen::Matrix4f get_view()
const;
120 Eigen::Matrix4f get_PV()
const;
122 Eigen::Matrix4f get_view_inverse()
const {
return m_Vinv; }
123 Eigen::Projective3f get_perspective_inverse()
const {
return m_Pinv; }
125 float get_window_width()
const;
126 float get_window_height()
const;
132 Eigen::Vector3f origin;
142 Ray cast_ray(
const Eigen::Vector2f& coord)
const;
150 Eigen::Vector2f project(
const Eigen::Vector3f& pos)
const;
158 Eigen::Vector3f project_with_depth(
const Eigen::Vector3f& pos)
const;
167 Eigen::Vector3f unproject(
const Eigen::Vector2f& screen,
float z = 0.0f)
const;
178 bool get_ray_to_screen(
179 const Eigen::Vector3f& rayOrigin,
180 const Eigen::Vector3f& rayDir,
181 Eigen::Vector2f* beginOut,
182 Eigen::Vector2f* endOut)
const;
185 void rotate_around_lookat(
float angleRad);
186 void rotate_tumble(
float yaw_delta,
float pitch_delta);
199 void rotate_turntable(
202 Eigen::Vector3f primary_axis = Eigen::Vector3f::Zero());
206 const Eigen::Vector3f& camera_pos_start,
207 const Eigen::Vector3f& camera_up_start,
208 const Eigen::Vector2f& mouse_start,
209 const Eigen::Vector2f& mouse_current);
211 void zoom(
float delta);
212 void dolly(
float delta);
221 void move_forward(
float delta);
222 void move_right(
float delta);
223 void move_up(
float delta);
230 void set_ortho_viewport(Eigen::Vector4f viewport);
232 Eigen::Vector4f get_ortho_viewport()
const;
234 void set_rotation_mode(RotationMode mode) { m_rotation_mode = mode; }
235 RotationMode get_rotation_mode()
const {
return m_rotation_mode; }
242 Eigen::Vector2f scale = Eigen::Vector2f::Ones();
243 Eigen::Vector2f translate = Eigen::Vector2f::Zero();
269 Eigen::Vector2f inverse_viewport_transform(
const ViewportTransform& vt, Eigen::Vector2f& pixel)
275 bool is_pixel_in(
const Eigen::Vector2f& p)
const;
280 bool intersects_region(
const Eigen::Vector2f& begin,
const Eigen::Vector2f& end)
const;
282 Eigen::Vector2f get_window_origin()
const {
return {m_window_origin_x, m_window_origin_y}; }
283 void set_window_origin(
float x,
float y)
285 m_window_origin_x = x;
286 m_window_origin_y = y;
290 enum class Dir { TOP, BOTTOM, LEFT, RIGHT, FRONT, BACK };
295 bool is_orthogonal_direction(Dir dir)
const;
300 void set_orthogonal_direction(Dir dir);
303 std::pair<Eigen::Vector3f, Eigen::Vector3f> get_orthogonal_direction(Dir dir)
const;
317 Frustum get_frustum(Eigen::Vector2f min, Eigen::Vector2f max)
const;
321 virtual void update_perspective();
325 Eigen::Projective3f m_P;
326 Eigen::Matrix4f m_V = Eigen::Matrix4f::Identity();
327 Eigen::Projective3f m_Pinv;
328 Eigen::Matrix4f m_Vinv = Eigen::Matrix4f::Identity();
330 Eigen::Vector3f m_pos = Eigen::Vector3f(1, 0, 0);
331 Eigen::Vector3f m_up = Eigen::Vector3f(0, 1, 0);
332 Eigen::Vector3f m_lookat = Eigen::Vector3f::Zero();
334 float m_aspectRatio = 1.0f;
335 float m_fov = 3.14f / 4.0f;
336 float m_znear = 0.0125f;
337 float m_zfar = 128.0f;
339 float m_windowWidth = 1.0f;
340 float m_windowHeight = 1.0f;
341 int m_retina_scale = 1;
342 Type m_type = Type::PERSPECTIVE;
344 float m_window_origin_x = 0.0f;
345 float m_window_origin_y = 0.0f;
347 Eigen::Vector4f m_ortho_viewport = Eigen::Vector4f(0.0f, 1.0f, 1.0f, 0.0f);
349 RotationMode m_rotation_mode = RotationMode::TUMBLE;
Camera class.
Definition: Camera.h:38
Type
Camera Mode.
Definition: Camera.h:43
RotationMode
Definition: Camera.h:45
Dir
Orthogonal view directions, preserve distance from pos to lookat.
Definition: Camera.h:290
void set_retina_scale(int value)
Definition: Camera.h:219
int get_retina_scale() const
Definition: Camera.h:216
Frustum defined using 6 planes.
Definition: Frustum.h:43
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
LA_UI_API const WindowSize & get_window_size(const Registry &r)
Returns global window size.
Definition: uipanel.cpp:151
Main namespace for Lagrange.
Definition: AABBIGL.h:30