ortho.h revision e4eec20f6263f4a42ae462456f60ea6c4518bb0a
1#ifndef ANDROID_DVR_ORTHO_H_
2#define ANDROID_DVR_ORTHO_H_
3
4#include <private/dvr/types.h>
5
6namespace android {
7namespace dvr {
8
9template <class T>
10Eigen::AffineMatrix<T, 4> OrthoMatrix(T left, T right, T bottom, T top,
11                                      T znear, T zfar) {
12  Eigen::AffineMatrix<T, 4> result;
13  const T t2 = static_cast<T>(2);
14  const T a = t2 / (right - left);
15  const T b = t2 / (top - bottom);
16  const T c = t2 / (zfar - znear);
17  const T xoff = -(right + left) / (right - left);
18  const T yoff = -(top + bottom) / (top - bottom);
19  const T zoff = -(zfar + znear) / (zfar - znear);
20  const T t1 = static_cast<T>(1);
21  result.matrix() << a, 0, 0, xoff,
22            0, b, 0, yoff,
23            0, 0, c, zoff,
24            0, 0, 0, t1;
25  return result;
26}
27
28}  // namespace android
29}  // namespace dvr
30
31#endif  // ANDROID_DVR_ORTHO_H_
32