Lagrange
Camera Class Reference

Camera class. More...

#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
 

Detailed Description

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.

Member Enumeration Documentation

◆ RotationMode

enum class RotationMode
strong
Enumerator
TURNTABLE 

Local view x,y axis.

ARCBALL 

Global y, local x axis.

Sphere projection

Member Function Documentation

◆ default_camera()

Camera default_camera ( float  width,
float  height,
Type  type = Type::PERSPECTIVE 
)
static

Initializes default view.

Parameters
widthwindow width
heightwindow height
typeperspective or orthographic
Returns
Camera

◆ set_window_dimensions()

void set_window_dimensions ( float  width,
float  height 
)

Set the window dimensions.

Parameters
widthin pixels
heightin pixels

◆ set_fov()

void set_fov ( float  fov)

Set the Field of View.

Parameters
fovin degrees

◆ get_perspective()

Eigen::Projective3f get_perspective ( ) const

Perspective matrix.

Returns
Eigen::Matrix4f

◆ get_view()

Eigen::Matrix4f get_view ( ) const

View matrix.

Returns
Eigen::Matrix4f

◆ get_PV()

Eigen::Matrix4f get_PV ( ) const

Projection*View matrix.

Returns
Eigen::Matrix4f

◆ cast_ray()

Camera::Ray cast_ray ( const Eigen::Vector2f &  coord) const

shoots a ray from coord pixel

Parameters
coordpixel coordinate
Returns
Ray

◆ project()

Eigen::Vector2f project ( const Eigen::Vector3f &  pos) const

Projects 3D point to 2D pixel coordinates.

Parameters
pos3D world position
Returns
Eigen::Vector2f

◆ project_with_depth()

Eigen::Vector3f project_with_depth ( const Eigen::Vector3f &  pos) const

Projects 3D point to 2D pixel coordinates and depth.

Parameters
pos3D world position
Returns
Eigen::Vector3f x,y in screen coordinates, z in NDC

◆ unproject()

Eigen::Vector3f unproject ( const Eigen::Vector2f &  screen,
float  z = 0.0f 
) const

Unprojects 2D pixels to 3D point.

Parameters
screenpixel coordinate
zdepth of the 3D point (distance from camera)
Returns
Eigen::Vector3f 3D point in world space

◆ get_ray_to_screen()

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.

Parameters
[in]rayOrigin
[in]rayDir
[out]beginOutstart point of 2D line
[out]endOutend point of 2D line
Returns
bool is ray visible

◆ rotate_turntable()

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

Parameters
yaw_delta
pitch_delta
primary_axis

◆ get_retina_scale()

int get_retina_scale ( ) const
inline
Deprecated:
Deprecated

◆ set_retina_scale()

void set_retina_scale ( int  value)
inline
Deprecated:
Deprecated

◆ set_ortho_viewport()

void set_ortho_viewport ( Eigen::Vector4f  viewport)

Set the orthographic viewport.

Parameters
viewportOrthographic rectangle

◆ transformed()

Camera transformed ( const ViewportTransform vt) const

Transform camera by ViewportTransform.

Parameters
vtviewport transform
Returns
Camera

◆ inverse_viewport_transform()

Eigen::Vector2f inverse_viewport_transform ( const ViewportTransform vt,
Eigen::Vector2f &  pixel 
) const

Map pixel from transformed viewport to original viewport.

Parameters
vtviewport transfrom
pixelpixel in transfromed viewport
Returns
Eigen::Vector2f pixel in original viewport

◆ get_frustum() [1/2]

Frustum get_frustum ( ) const

Get the Camera's Frustum.

Returns
Frustum planes

◆ get_frustum() [2/2]

Frustum get_frustum ( Eigen::Vector2f  min,
Eigen::Vector2f  max 
) const

Get the Camera's Frustum of a region.

Returns
Frustum planes of a region

The documentation for this class was generated from the following files: