2 inline Matrix<4, 4, T>
translate(
const Vector<3, T>& direction) {
3 Matrix<4, 4, T> matrix = Matrix<4, 4, T>::identity();
5 matrix(0, 3) = direction(0);
6 matrix(1, 3) = direction(1);
7 matrix(2, 3) = direction(2);
13 inline Matrix<4, 4, T>
rotate(T angle,
const Vector<3, T>& a) {
18 Vector<3, T> tmp((T(1) - c) * axis);
20 return Matrix<4, 4, T> {
21 c + tmp.x() * axis.x(),
22 tmp.x() * axis.y() + s * axis.z(),
23 tmp.x() * axis.z() - s * axis.y(),
26 tmp.y() * axis.x() - s * axis.z(),
27 c + tmp.y() * axis.y(),
28 tmp.y() * axis.z() + s * axis.x(),
31 tmp.z() * axis.x() + s * axis.y(),
32 tmp.z() * axis.y() - s * axis.x(),
33 c + tmp.z() * axis.z(),
41 inline Matrix<4, 4, T>
scale(
const Vector<3, T>& factors) {
42 Matrix<4, 4, T> matrix = Matrix<4, 4, T>::identity();
44 matrix(0, 0) = factors(0);
45 matrix(1, 1) = factors(1);
46 matrix(2, 2) = factors(2);
52 inline Matrix<4, 4, T>
lookAt(
const Vector<3, T>& eye,
const Vector<3, T>& center,
const Vector<3, T>& up) {
53 const Vector<3, T> direction(
normalize(
static_cast<Vector<3, T>
>(eye - center)));
55 const Vector<3, T> newUp(
cross(direction, right));
57 return Matrix<4, 4, T> {
81 inline Matrix<4, 4, T>
ortho(T left, T right, T bottom, T top, T zNear, T zFar) {
82 Matrix<4, 4, T> matrix = Matrix<4, 4, T>::identity();
84 matrix(0, 0) = T(2) / (right - left);
85 matrix(0, 3) = -(right + left) / (right - left);
86 matrix(1, 1) = T(2) / (top - bottom);
87 matrix(1, 3) = -(top + bottom) / (top - bottom);
88 matrix(2, 2) = -T(1) / (zFar - zNear);
89 matrix(2, 3) = -zNear / (zFar - zNear);
95 inline Matrix<4, 4, T>
perspective(T fovy, T aspect, T zNear, T zFar) {
98 Matrix<4, 4, T> matrix(0);
100 matrix(0, 0) = T(1) / (aspect * tanHalfFovy);
101 matrix(1, 1) = T(1) / (tanHalfFovy);
102 matrix(2, 2) = zFar / (zNear - zFar);
103 matrix(2, 3) = -(zFar * zNear) / (zFar - zNear);
104 matrix(3, 2) = -T(1);
constexpr Vector< 3, T > cross(const Vector< 3, T > &lhs, const Vector< 3, T > &rhs)
Quaternion< T > normalize(const Quaternion< T > &lhs)
T dot(const Quaternion< T > &lhs, const Quaternion< T > &rhs)