25 #ifndef INCLUDED_ProjectionMatrix_h_GUID_638B5832_DF1C_4BB7_9844_BF9810926107 26 #define INCLUDED_ProjectionMatrix_h_GUID_638B5832_DF1C_4BB7_9844_BF9810926107 36 #include <type_traits> 49 double near,
double far) {
62 auto const right = bounds[Rectd::RIGHT];
63 auto const left = bounds[Rectd::LEFT];
64 auto const top = bounds[Rectd::TOP];
65 auto const bottom = bounds[Rectd::BOTTOM];
69 mat << (2 * near / (right - left)), 0, ((right + left) / (right - left)), 0,
70 0, (2 * near / (top - bottom)), ((top + bottom) / (top - bottom)), 0,
71 0, 0, (-(far + near) / (far - near)), (-2 * far * near / (far - near)),
77 namespace projection_options {
81 enum OptMasks { ZOutputUnsignedBit = 0x1, LeftHandedInputBit = 0x2 };
88 ZOutputUnsigned = ZOutputUnsignedBit,
91 LeftHandedInput = LeftHandedInputBit
94 typedef unsigned char OptionType;
95 template <OptionType Options, OptionType Bit>
96 using CheckOptionBit =
97 std::integral_constant<bool,
98 static_cast<bool>(0 != (
Options & Bit))>;
100 template <OptionType Options>
101 using IsZOutputUnsigned = CheckOptionBit<Options, ZOutputUnsignedBit>;
102 template <OptionType Options>
103 using IsLeftHandedInput = CheckOptionBit<Options, LeftHandedInputBit>;
107 namespace projection_detail {
109 template <projection_options::OptionType options,
110 bool = projection_options::IsZOutputUnsigned<options>::value>
112 static inline double get3(
double near,
double far) {
113 return (-(far + near) / (far - near));
115 static inline double get4(
double near,
double far) {
116 return (-2 * far * near / (far - near));
120 template <projection_options::OptionType options>
122 static inline double get3(
double near,
double far) {
123 return (-far / (far - near));
125 static inline double get4(
double near,
double far) {
126 return (-far * near / (far - near));
129 template <projection_options::OptionType options>
130 inline double get33(
double near,
double far) {
133 template <projection_options::OptionType options>
134 inline double get34(
double near,
double far) {
139 template <projection_options::OptionType options,
typename =
void>
141 static void apply(Eigen::Matrix4d &) {}
144 template <projection_options::OptionType options>
147 typename
std::enable_if<
148 projection_options::IsLeftHandedInput<options>::value>::type> {
149 static void apply(Eigen::Matrix4d &mat) { mat.col(2) *= -1.; }
157 template <projection_options::OptionType options =
158 projection_options::ZOutputSigned |
159 projection_options::RightHandedInput>
160 inline Eigen::Matrix4d
174 auto right = bounds[Rectd::RIGHT];
175 auto left = bounds[Rectd::LEFT];
176 auto top = bounds[Rectd::TOP];
177 auto bottom = bounds[Rectd::BOTTOM];
181 using projection_detail::get33;
182 using projection_detail::get34;
185 mat << (2 * near / (right - left)), 0, ((right + left) / (right - left)), 0,
186 0, (2 * near / (top - bottom)), ((top + bottom) / (top - bottom)), 0,
187 0, 0, get33<options>(near, far), get34<options>(near, far),
200 #endif // INCLUDED_ProjectionMatrix_h_GUID_638B5832_DF1C_4BB7_9844_BF9810926107 Definition: RunLoopManager.h:42
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Definition: TypeSafeIdHash.h:44
Definition: ProjectionMatrix.h:111
Header wrapping include of <Eigen/Core> and <Eigen/Geometry> for warning quieting.
Eigen::Matrix4d parameterizedCreateProjectionMatrix(Rectd const &bounds, double near, double far)
Takes in points at the near clipping plane, as well as the near and far clipping planes.
Definition: ProjectionMatrix.h:161
typename F::template apply< Args... > apply
Apply an alias class.
Definition: Apply.h:44
OptBits
The flags (combine with bitwise-or |) for specifying configuration - do not depend on these being equ...
Definition: ProjectionMatrix.h:86
Adjustment needed for left-handed input: dummy case of not requesting left-hand input.
Definition: ProjectionMatrix.h:140
Eigen::Matrix4d createProjectionMatrix(Rectd const &bounds, double near, double far)
Takes in points at the near clipping plane, as well as the near and far clipping planes.
Definition: ProjectionMatrix.h:48
OptMasks
The bit masks for testing conditions - do not depend on these being equal to a given enum value of Op...
Definition: ProjectionMatrix.h:81
Definition: osvr_print_tree.cpp:52