Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions include/eigen_graphics/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,52 +399,52 @@ Eigen::Matrix<typename Derived::Scalar, 4, 4, Derived::Options> rotateLh(const E
// BEGIN: view matrix creation functions
// ----------------------------------------------------------------------------

template <typename Derived>
Eigen::Matrix<typename Derived::Scalar, 4, 4, Derived::Options> lookAtRh(const Eigen::MatrixBase<Derived>& eye,
const Eigen::MatrixBase<Derived>& target,
const Eigen::MatrixBase<Derived>& worldUp) {
template <typename Derived, StorageOptions Options = StorageOptions::ColMajor>
Eigen::Matrix<typename Derived::Scalar, 4, 4, Options> lookAtRh(const Eigen::MatrixBase<Derived>& eye,
const Eigen::MatrixBase<Derived>& target,
const Eigen::MatrixBase<Derived>& worldUp) {
static_assert(Derived::RowsAtCompileTime == 3 && Derived::ColsAtCompileTime == 1, "lookAtRh requires 3x1 vectors.");

using Scalar = typename Derived::Scalar;
using Vector3 = Eigen::Matrix<Scalar, 3, 1, Derived::Options>;
using Matrix4 = Eigen::Matrix<Scalar, 4, 4, Derived::Options>;
using Vector3 = Eigen::Matrix<Scalar, 3, 1, ::Eigen::ColMajor>;
using Matrix4 = Eigen::Matrix<Scalar, 4, 4, Options>;

Vector3 f = (target - eye).normalized();
Vector3 f = (eye - target).normalized();
Vector3 r = worldUp.cross(f).normalized();
Vector3 u = f.cross(r);

Matrix4 viewMatrix;

if constexpr (Derived::Options == Eigen::RowMajor) {
if constexpr (Options == Eigen::RowMajor) {
// clang-format off
viewMatrix <<
r.x(), u.x(), -f.x(), Scalar(0),
r.y(), u.y(), -f.y(), Scalar(0),
r.z(), u.z(), -f.z(), Scalar(0),
r.x(), u.x(), f.x(), Scalar(0),
r.y(), u.y(), f.y(), Scalar(0),
r.z(), u.z(), f.z(), Scalar(0),
-r.dot(eye), -u.dot(eye), -f.dot(eye), Scalar(1);
// clang-format on
} else if constexpr (Derived::Options == Eigen::ColMajor) {
} else if constexpr (Options == Eigen::ColMajor) {
// clang-format off
viewMatrix <<
r.x(), r.y(), r.z(), -r.dot(eye),
u.x(), u.y(), u.z(), -u.dot(eye),
-f.x(), -f.y(), -f.z(), -f.dot(eye),
f.x(), f.y(), f.z(), -f.dot(eye),
Scalar(0), Scalar(0), Scalar(0), Scalar(1);
// clang-format on
}

return viewMatrix;
}

template <typename Derived>
template <typename Derived, StorageOptions Options = StorageOptions::ColMajor>
Eigen::Matrix<typename Derived::Scalar, 4, 4, Derived::Options> lookAtLh(const Eigen::MatrixBase<Derived>& eye,
const Eigen::MatrixBase<Derived>& target,
const Eigen::MatrixBase<Derived>& worldUp) {
static_assert(Derived::RowsAtCompileTime == 3 && Derived::ColsAtCompileTime == 1, "lookAtLh requires 3x1 vectors.");

using Scalar = typename Derived::Scalar;
using Vector3 = Eigen::Matrix<Scalar, 3, 1, Derived::Options>;
using Matrix4 = Eigen::Matrix<Scalar, 4, 4, Derived::Options>;
using Vector3 = Eigen::Matrix<Scalar, 3, 1, ::Eigen::ColMajor>;
using Matrix4 = Eigen::Matrix<Scalar, 4, 4, Options>;

Vector3 f = (target - eye).normalized();
Vector3 r = worldUp.cross(f).normalized();
Expand Down Expand Up @@ -1448,4 +1448,4 @@ Eigen::Matrix<T, 3, 1, Options> transformVector(const Eigen::Matrix<T, 3, 1, Opt
} // namespace Graphics
} // namespace Eigen

#endif // EIGEN_GRAPHICS_MODULE_H
#endif // EIGEN_GRAPHICS_MODULE_H