Home | History | Annotate | Download | only in dvr
      1 #ifndef ANDROID_DVR_EIGEN_H_
      2 #define ANDROID_DVR_EIGEN_H_
      3 
      4 #include <Eigen/Core>
      5 #include <Eigen/Geometry>
      6 
      7 namespace Eigen {
      8 
      9 // Eigen doesn't take advantage of C++ template typedefs, but we can
     10 template <class T, int N>
     11 using Vector = Matrix<T, N, 1>;
     12 
     13 template <class T>
     14 using Vector2 = Vector<T, 2>;
     15 
     16 template <class T>
     17 using Vector3 = Vector<T, 3>;
     18 
     19 template <class T>
     20 using Vector4 = Vector<T, 4>;
     21 
     22 template <class T, int N>
     23 using RowVector = Matrix<T, 1, N>;
     24 
     25 template <class T>
     26 using RowVector2 = RowVector<T, 2>;
     27 
     28 template <class T>
     29 using RowVector3 = RowVector<T, 3>;
     30 
     31 template <class T>
     32 using RowVector4 = RowVector<T, 4>;
     33 
     34 // In Eigen, the type you should be using for transformation matrices is the
     35 // `Transform` class, instead of a raw `Matrix`.
     36 // The `Projective` option means this will not make any assumptions about the
     37 // last row of the object, making this suitable for use as general OpenGL
     38 // projection matrices (which is the most common use-case). The one caveat
     39 // is that in order to apply this transformation to non-homogeneous vectors
     40 // (e.g., vec3), you must use the `.linear()` method to get the affine part of
     41 // the matrix.
     42 //
     43 // Example:
     44 //   mat4 transform;
     45 //   vec3 position;
     46 //   vec3 transformed = transform.linear() * position;
     47 //
     48 // Note, the use of N-1 is because the parameter passed to Eigen is the ambient
     49 // dimension of the transformation, not the size of the matrix iself.
     50 // However graphics programmers sometimes get upset when they see a 3 next
     51 // to a matrix when they expect a 4, so I'm hoping this will avoid that.
     52 template <class T, int N>
     53 using AffineMatrix = Transform<T, N-1, Projective>;
     54 
     55 }  // namespace Eigen
     56 
     57 #endif  // ANDROID_DVR_EIGEN_H_
     58