MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
camera.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 */
9
10#ifndef OGL_CAMERA_HEADER
11#define OGL_CAMERA_HEADER
12
13#include "math/vector.h"
14#include "math/matrix.h"
15#include "math/matrix_tools.h"
16#include "ogl/defines.h"
17
19
32class Camera
33{
34public:
35
36 /* --- Viewing matrix parameters --- */
37
44
45 /* --- Projection matrix parameters --- */
46
48 float z_near;
50 float z_far;
52 float top;
54 float right;
55
56 /* --- Viewport parameters --- */
57
59 int width;
61 int height;
62
63 /* --- Viewing and projection matrices --- */
64
73
74public:
76 Camera (void);
77
79 //void set_view_params (math::Vec3f const& position,
80 // math::Vec3f const& viewdir, math::Vec3f const& upvec);
82 //void set_proj_params (float znear, float zfar, float top, float right);
83
85 float get_aspect (void) const;
87 float get_vertical_fov (void) const;
88
90 void update_matrices (void);
92 void update_view_mat (void);
94 void update_inv_view_mat (void);
96 void update_proj_mat (void);
98 void update_inv_proj_mat (void);
99};
100
101/* ---------------------------------------------------------------- */
102
103inline
104Camera::Camera (void)
105 : pos(0.0f, 0.0f, 5.0f)
106 , viewing_dir(0.0f, 0.0f, -1.0f)
107 , up_vec(0.0f, 1.0f, 0.0f)
108 , z_near(0.1f)
109 , z_far(500.0f)
110 , top(0.1f)
111 , right(0.1f)
112 , width(0)
113 , height(0)
114 , view(0.0f)
115 , inv_view(0.0f)
116 , proj(0.0f)
117 , inv_proj(0.0f)
118{
119}
120
121inline float
123{
124 return right / top;
125}
126
127inline float
129{
130 return 2.0f * std::atan(this->top / this->z_near);
131}
132
133inline void
135{
136 this->update_view_mat();
137 this->update_inv_view_mat();
138 this->update_proj_mat();
139 this->update_inv_proj_mat();
140}
141
142inline void
144{
145 this->view = math::matrix_viewtrans(this->pos,
146 this->viewing_dir, this->up_vec);
147}
148
149inline void
151{
153 this->viewing_dir, this->up_vec);
154}
155
156inline void
158{
160 this->z_far, this->top, this->right);
161}
162
163inline void
165{
167 this->z_far, this->top, this->right);
168}
169
171
172#endif /* OGL_CAMERA_HEADER */
Matrix class for arbitrary dimensions and types.
Definition matrix.h:54
Vector class for arbitrary dimensions and types.
Definition vector.h:87
A camera class that manages viewing and projection matrices.
Definition camera.h:33
float top
Top and -Bottom clipping plane of the projection matrix.
Definition camera.h:52
math::Vec3f pos
Position of the camera.
Definition camera.h:39
math::Vec3f up_vec
Up-vector of the camera.
Definition camera.h:43
math::Vec3f viewing_dir
Viewing direction of the camera.
Definition camera.h:41
math::Matrix4f inv_proj
Inverse projection matrix, use update_matrices() to calculate.
Definition camera.h:72
float get_vertical_fov(void) const
Returns the vertical FOV of the projection in RAD.
Definition camera.h:128
void update_view_mat(void)
Updates the view matrix from pos, viewdir and upvec.
Definition camera.h:143
void update_proj_mat(void)
Updates the projection matrix from znear, zfar and aspect.
Definition camera.h:157
math::Matrix4f inv_view
Inverse view matrix, use update_matrices() to calculate.
Definition camera.h:68
void update_matrices(void)
Updates view, projection and inverse matrices.
Definition camera.h:134
math::Matrix4f view
View matrix, use update_matrices() to calculate.
Definition camera.h:66
int width
The viewport width.
Definition camera.h:59
void update_inv_view_mat(void)
Updates the inverse view matrix from pos, viewdir and upvec.
Definition camera.h:150
float z_near
Near clipping plane of the projection matrix.
Definition camera.h:48
int height
The viewport height.
Definition camera.h:61
math::Matrix4f proj
Projection matrix, use update_matrices() to calculate.
Definition camera.h:70
float get_aspect(void) const
Sets the viewing parameters and calcualtes view matrices.
Definition camera.h:122
float right
Right and -Left clipping plane of the projection matrix.
Definition camera.h:54
void update_inv_proj_mat(void)
Updates inverse projection matrix from znear, zfar and aspect.
Definition camera.h:164
float z_far
Far clipping plane of the projection matrix.
Definition camera.h:50
Matrix< T, 4, 4 > matrix_inverse_gl_projection(T const &znear, T const &zfar, T const &top, T const &right)
Creates a symmetric inverse projection matrix as used in OpenGL.
Matrix< T, 4, 4 > matrix_inverse_viewtrans(Vector< T, 3 > const &campos, Vector< T, 3 > const &viewdir, Vector< T, 3 > const &upvec)
Creates an inverse view transformation matrix.
Matrix< T, 4, 4 > matrix_viewtrans(Vector< T, 3 > const &campos, Vector< T, 3 > const &viewdir, Vector< T, 3 > const &upvec)
Creates a view transformation matrix for camera parameters given as camera position,...
Matrix< T, 4, 4 > matrix_gl_projection(T const &znear, T const &zfar, T const &top, T const &right)
Creates a symmetric projection matrix as used in OpenGL.
#define OGL_NAMESPACE_END
Definition defines.h:14
#define OGL_NAMESPACE_BEGIN
Definition defines.h:13