Lagrange
|
#include <lagrange/ui/types/Camera.h>
Classes | |
struct | Ray |
struct | ViewportTransform |
Transform in the normalized coordinate space. More... | |
Public Types | |
enum class | Type { PERSPECTIVE , ORTHOGRAPHIC } |
Camera Mode. | |
enum class | RotationMode { TUMBLE , TURNTABLE , ARCBALL } |
enum class | Dir { TOP , BOTTOM , LEFT , RIGHT , FRONT , BACK } |
Orthogonal view directions, preserve distance from pos to lookat. | |
Public Member Functions | |
Camera (Type type=Type::PERSPECTIVE) | |
void | set_type (Type type) |
Type | get_type () const |
void | set_position (const Eigen::Vector3f &pos) |
void | set_lookat (const Eigen::Vector3f &dir) |
void | set_position_up (const Eigen::Vector3f &pos, const Eigen::Vector3f &up) |
Eigen::Vector3f | get_lookat () const |
void | set_up (const Eigen::Vector3f &up) |
Eigen::Vector3f | get_position () const |
Eigen::Vector3f | get_direction () const |
Eigen::Vector3f | get_up () const |
float | get_far_plane () const |
float | get_near_plane () const |
void | set_window_dimensions (float width, float height) |
Set the window dimensions. More... | |
void | set_aspect_ratio (float width, float height) |
void | set_fov (float fov) |
Set the Field of View. More... | |
float | get_fov () const |
void | set_planes (float znear, float zfar) |
float | get_near () const |
float | get_far () const |
Eigen::Projective3f | get_perspective () const |
Perspective matrix. More... | |
Eigen::Matrix4f | get_view () const |
View matrix. More... | |
Eigen::Matrix4f | get_PV () const |
Projection*View matrix. More... | |
Eigen::Matrix4f | get_view_inverse () const |
Eigen::Projective3f | get_perspective_inverse () const |
float | get_window_width () const |
float | get_window_height () const |
Eigen::Vector2f | get_window_size () const |
Ray | cast_ray (const Eigen::Vector2f &coord) const |
shoots a ray from coord pixel More... | |
Eigen::Vector2f | project (const Eigen::Vector3f &pos) const |
Projects 3D point to 2D pixel coordinates. More... | |
Eigen::Vector3f | project_with_depth (const Eigen::Vector3f &pos) const |
Projects 3D point to 2D pixel coordinates and depth. More... | |
Eigen::Vector3f | unproject (const Eigen::Vector2f &screen, float z=0.0f) const |
Unprojects 2D pixels to 3D point. More... | |
bool | get_ray_to_screen (const Eigen::Vector3f &rayOrigin, const Eigen::Vector3f &rayDir, Eigen::Vector2f *beginOut, Eigen::Vector2f *endOut) const |
Projects a ray back to screen coordinates. More... | |
void | rotate_around_lookat (float angleRad) |
void | rotate_tumble (float yaw_delta, float pitch_delta) |
void | rotate_turntable (float yaw_delta, float pitch_delta, Eigen::Vector3f primary_axis=Eigen::Vector3f::Zero()) |
Rotates camera by yaw and pitch angles. More... | |
void | rotate_arcball (const Eigen::Vector3f &camera_pos_start, const Eigen::Vector3f &camera_up_start, const Eigen::Vector2f &mouse_start, const Eigen::Vector2f &mouse_current) |
void | zoom (float delta) |
void | dolly (float delta) |
int | get_retina_scale () const |
void | set_retina_scale (int value) |
void | move_forward (float delta) |
void | move_right (float delta) |
void | move_up (float delta) |
void | set_ortho_viewport (Eigen::Vector4f viewport) |
Set the orthographic viewport. More... | |
Eigen::Vector4f | get_ortho_viewport () const |
void | set_rotation_mode (RotationMode mode) |
RotationMode | get_rotation_mode () const |
Camera | transformed (const ViewportTransform &vt) const |
Transform camera by ViewportTransform. More... | |
Eigen::Vector2f | inverse_viewport_transform (const ViewportTransform &vt, Eigen::Vector2f &pixel) const |
Map pixel from transformed viewport to original viewport. More... | |
bool | is_pixel_in (const Eigen::Vector2f &p) const |
Is pixel in camera. | |
bool | intersects_region (const Eigen::Vector2f &begin, const Eigen::Vector2f &end) const |
Does camera intersect pixel region. | |
Eigen::Vector2f | get_window_origin () const |
void | set_window_origin (float x, float y) |
bool | is_orthogonal_direction (Dir dir) const |
Is camera aligned to one of the six orthogonal Dir directions. | |
void | set_orthogonal_direction (Dir dir) |
Aligns camera to one of the six orthogonal Dir directions. | |
std::pair< Eigen::Vector3f, Eigen::Vector3f > | get_orthogonal_direction (Dir dir) const |
Returns position and up direction. | |
Frustum | get_frustum () const |
Get the Camera's Frustum. More... | |
Frustum | get_frustum (Eigen::Vector2f min, Eigen::Vector2f max) const |
Get the Camera's Frustum of a region. More... | |
Static Public Member Functions | |
static Camera | default_camera (float width, float height, Type type=Type::PERSPECTIVE) |
Initializes default view. More... | |
Protected Member Functions | |
void | update_view () |
virtual void | update_perspective () |
void | _changed () |
Protected Attributes | |
Eigen::Projective3f | m_P |
Eigen::Matrix4f | m_V = Eigen::Matrix4f::Identity() |
Eigen::Projective3f | m_Pinv |
Eigen::Matrix4f | m_Vinv = Eigen::Matrix4f::Identity() |
Eigen::Vector3f | m_pos = Eigen::Vector3f(1, 0, 0) |
Eigen::Vector3f | m_up = Eigen::Vector3f(0, 1, 0) |
Eigen::Vector3f | m_lookat = Eigen::Vector3f::Zero() |
float | m_aspectRatio = 1.0f |
float | m_fov = 3.14f / 4.0f |
float | m_znear = 0.0125f |
float | m_zfar = 128.0f |
float | m_windowWidth = 1.0f |
float | m_windowHeight = 1.0f |
int | m_retina_scale = 1 |
Type | m_type = Type::PERSPECTIVE |
float | m_window_origin_x = 0.0f |
float | m_window_origin_y = 0.0f |
Eigen::Vector4f | m_ortho_viewport = Eigen::Vector4f(0.0f, 1.0f, 1.0f, 0.0f) |
RotationMode | m_rotation_mode = RotationMode::TUMBLE |
Camera class.
Camera can be either Type::PERSPECTIVE or Type::ORTHOGRAPHIC
Camera is defined by: position, lookat point or direction, up vector, field of view or ortho_viewport, window dimensions, and far/near plane
Note: Caches view and perspective matrices and their inverses.
|
strong |
Initializes default view.
width | window width |
height | window height |
type | perspective or orthographic |
void set_window_dimensions | ( | float | width, |
float | height | ||
) |
Set the window dimensions.
width | in pixels |
height | in pixels |
void set_fov | ( | float | fov | ) |
Set the Field of View.
fov | in degrees |
Eigen::Projective3f get_perspective | ( | ) | const |
Perspective matrix.
Eigen::Matrix4f get_view | ( | ) | const |
View matrix.
Eigen::Matrix4f get_PV | ( | ) | const |
Projection*View matrix.
Camera::Ray cast_ray | ( | const Eigen::Vector2f & | coord | ) | const |
Eigen::Vector2f project | ( | const Eigen::Vector3f & | pos | ) | const |
Projects 3D point to 2D pixel coordinates.
pos | 3D world position |
Eigen::Vector3f project_with_depth | ( | const Eigen::Vector3f & | pos | ) | const |
Projects 3D point to 2D pixel coordinates and depth.
pos | 3D world position |
Eigen::Vector3f unproject | ( | const Eigen::Vector2f & | screen, |
float | z = 0.0f |
||
) | const |
Unprojects 2D pixels to 3D point.
screen | pixel coordinate |
z | depth of the 3D point (distance from camera) |
bool get_ray_to_screen | ( | const Eigen::Vector3f & | rayOrigin, |
const Eigen::Vector3f & | rayDir, | ||
Eigen::Vector2f * | beginOut, | ||
Eigen::Vector2f * | endOut | ||
) | const |
Projects a ray back to screen coordinates.
[in] | rayOrigin | |
[in] | rayDir | |
[out] | beginOut | start point of 2D line |
[out] | endOut | end point of 2D line |
void rotate_turntable | ( | float | yaw_delta, |
float | pitch_delta, | ||
Eigen::Vector3f | primary_axis = Eigen::Vector3f::Zero() |
||
) |
Rotates camera by yaw and pitch angles.
By default rotates around up() axis Rotates around primary_axis if specified
yaw_delta | |
pitch_delta | |
primary_axis |
|
inline |
|
inline |
void set_ortho_viewport | ( | Eigen::Vector4f | viewport | ) |
Set the orthographic viewport.
viewport | Orthographic rectangle |
Camera transformed | ( | const ViewportTransform & | vt | ) | const |
Eigen::Vector2f inverse_viewport_transform | ( | const ViewportTransform & | vt, |
Eigen::Vector2f & | pixel | ||
) | const |
Map pixel from transformed viewport to original viewport.
vt | viewport transfrom |
pixel | pixel in transfromed viewport |
Frustum get_frustum | ( | Eigen::Vector2f | min, |
Eigen::Vector2f | max | ||
) | const |