22#ifndef EOS_MATRIX_PROJECTION_HPP
23#define EOS_MATRIX_PROJECTION_HPP
52Eigen::Matrix4<T>
perspective(T fov_y, T aspect, T z_near, T z_far)
61 const T tan_half_fov_y = tan(fov_y /
static_cast<T
>(2));
63 Eigen::Matrix4<T> result = Eigen::Matrix4<T>::Zero();
64 result(0, 0) =
static_cast<T
>(1) / (aspect * tan_half_fov_y);
65 result(1, 1) =
static_cast<T
>(1) / (tan_half_fov_y);
66 result(2, 2) = -(z_far + z_near) / (z_far - z_near);
67 result(3, 2) = -
static_cast<T
>(1);
68 result(2, 3) = -(
static_cast<T
>(2) * z_far * z_near) / (z_far - z_near);
89Eigen::Matrix4<T>
ortho(T left, T right, T bottom, T top)
91 Eigen::Matrix4<T> result = Eigen::Matrix4<T>::Identity();
92 result(0, 0) =
static_cast<T
>(2) / (right - left);
93 result(1, 1) =
static_cast<T
>(2) / (top - bottom);
94 result(2, 2) = -
static_cast<T
>(1);
95 result(0, 3) = -(right + left) / (right - left);
96 result(1, 3) = -(top + bottom) / (top - bottom);
118Eigen::Matrix4<T>
ortho(T left, T right, T bottom, T top, T z_near, T z_far)
120 Eigen::Matrix4<T> result = Eigen::Matrix4<T>::Identity();
121 result(0, 0) =
static_cast<T
>(2) / (right - left);
122 result(1, 1) =
static_cast<T
>(2) / (top - bottom);
123 result(2, 2) = -
static_cast<T
>(2) / (z_far - z_near);
124 result(0, 3) = -(right + left) / (right - left);
125 result(1, 3) = -(top + bottom) / (top - bottom);
126 result(2, 3) = -(z_far + z_near) / (z_far - z_near);
148Eigen::Vector3<T>
project(
const Eigen::Vector3<T>& point_3d,
const Eigen::Matrix4<T>& modelview_matrix,
149 const Eigen::Matrix4<T>& projection_matrix,
const Eigen::Vector4<T>& viewport)
151 Eigen::Vector4<T> projected_point = projection_matrix * modelview_matrix * point_3d.homogeneous();
152 projected_point /= projected_point.w();
154 projected_point *
static_cast<T
>(0.5) +
155 Eigen::Vector4<T>(
static_cast<T
>(0.5),
static_cast<T
>(0.5),
static_cast<T
>(0.5),
static_cast<T
>(0.5));
156 projected_point.x() = projected_point.x() * T(viewport(2)) + T(viewport(0));
157 projected_point.y() = projected_point.y() * T(viewport(3)) + T(viewport(1));
163 return projected_point.template head<3>();
Eigen::Matrix4< T > ortho(T left, T right, T bottom, T top)
Creates a 2D orthographic projection matrix.
Definition: matrix_projection.hpp:89
Eigen::Matrix4< T > perspective(T fov_y, T aspect, T z_near, T z_far)
Definition: matrix_projection.hpp:52
Eigen::Vector3< T > project(const Eigen::Vector3< T > &point_3d, const Eigen::Matrix4< T > &modelview_matrix, const Eigen::Matrix4< T > &projection_matrix, const Eigen::Vector4< T > &viewport)
Definition: matrix_projection.hpp:148
core::Image4u render(const core::Mesh &mesh, const Eigen::Matrix4f &model_view_matrix, const Eigen::Matrix4f &projection_matrix, int viewport_width, int viewport_height, bool enable_backface_culling=false, bool enable_near_clipping=true, bool enable_far_clipping=true)
Definition: render.hpp:52
Namespace containing all of eos's 3D model fitting functionality.