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>
121 struct ThirdRow<options, true> {
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) {
131 return ThirdRow<options>::get3(near, far);
133 template <projection_options::OptionType options>
134 inline double get34(
double near,
double far) {
135 return ThirdRow<options>::get4(near, 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
The main namespace for all C++ elements of the framework, internal and external.
Header wrapping include of and 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. Result matrix maps [l, r] and [b, t] to [-1, 1], and [n, f] to [-1, 1] or [0, 1] depending on presence/absence of ZOutputUnsigned flag bit, taking in right- or left-handed input also as configured.
typename F::template apply< Args...> apply
Apply an alias class.
Adjustment needed for left-handed input: dummy case of not requesting left-hand input.
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. Result matrix maps [l, r] and [b, t] to [-1, 1], and [n, f] to [-1, 1] (should be configurable)