1#ifndef ANDROID_DVR_EIGEN_H_ 2#define ANDROID_DVR_EIGEN_H_ 3 4#include <Eigen/Core> 5#include <Eigen/Geometry> 6 7namespace Eigen { 8 9// Eigen doesn't take advantage of C++ template typedefs, but we can 10template <class T, int N> 11using Vector = Matrix<T, N, 1>; 12 13template <class T> 14using Vector2 = Vector<T, 2>; 15 16template <class T> 17using Vector3 = Vector<T, 3>; 18 19template <class T> 20using Vector4 = Vector<T, 4>; 21 22template <class T, int N> 23using RowVector = Matrix<T, 1, N>; 24 25template <class T> 26using RowVector2 = RowVector<T, 2>; 27 28template <class T> 29using RowVector3 = RowVector<T, 3>; 30 31template <class T> 32using 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. 52template <class T, int N> 53using AffineMatrix = Transform<T, N-1, Projective>; 54 55} // namespace Eigen 56 57#endif // ANDROID_DVR_EIGEN_H_ 58