23#ifndef VCL_SPACE_CORE_CAMERA_MATRIX_H
24#define VCL_SPACE_CORE_CAMERA_MATRIX_H
31enum Handedness { LEFT_HAND, RIGHT_HAND };
37template<Po
int3Concept Po
intType>
41 const PointType& center,
43 Handedness handedness = RIGHT_HAND)
46 PointType zaxis = handedness == RIGHT_HAND ?
47 (eye - center).normalized() :
48 (center - eye).normalized();
50 PointType xaxis = up.cross(zaxis);
52 if (xaxis.dot(xaxis) == 0) {
53 xaxis = handedness == RIGHT_HAND ? PointType(1, 0, 0) :
57 xaxis = xaxis.normalized();
60 PointType yaxis = zaxis.cross(xaxis);
77 res[12] = -xaxis.dot(eye);
78 res[13] = -yaxis.dot(eye);
79 res[14] = -zaxis.dot(eye);
84template<
typename Scalar>
85void projectionMatrixXYWH(
94 Handedness handedness = RIGHT_HAND)
98 Scalar diff = farPlane - nearPlane;
99 Scalar a = homogeneousNDC ? (farPlane + nearPlane) / diff : farPlane / diff;
101 homogeneousNDC ? (2.0 * farPlane * nearPlane) / diff : nearPlane * a;
103 std::fill(res, res + 16, 0);
107 res[8] = handedness == RIGHT_HAND ? x : -x;
108 res[9] = handedness == RIGHT_HAND ? y : -y;
109 res[10] = handedness == RIGHT_HAND ? -a : a;
110 res[11] = handedness == RIGHT_HAND ? -1.0 : 1.0;
114template<
typename Scalar>
115void projectionMatrix(
122 Handedness handedness = RIGHT_HAND)
124 Scalar h = 1.0 / std::tan(
vcl::toRad(fov) * 0.5);
125 Scalar w = h * 1.0 / aspect;
126 detail::projectionMatrixXYWH(
138template<
typename Scalar>
139void orthoProjectionMatrix(
148 Handedness handedness = RIGHT_HAND)
152 Scalar c = homogeneousNDC ? 2.0 / (farPlane - nearPlane) :
153 1.0 / (farPlane - nearPlane);
154 Scalar f = homogeneousNDC ?
155 (farPlane + nearPlane) / (nearPlane - farPlane) :
156 nearPlane / (nearPlane - farPlane);
158 std::fill(res, res + 16, 0);
159 res[0] = 2.0 / (right - left);
160 res[5] = 2.0 / (top - bottom);
161 res[10] = RIGHT_HAND ? -c : c;
162 res[12] = (right + left) / (left - right);
163 res[13] = (bottom + top) / (bottom - top);
void lookAtMatrix(auto *res, const PointType &eye, const PointType ¢er, const PointType &up, Handedness handedness=RIGHT_HAND)
Creates a look at matrix.
Definition matrix_camera.h:47
Scalar toRad(const Scalar °)
Converts an angle in degrees to radians.
Definition math.h:81