diff --git a/headers/enduro2d/math/mat4.hpp b/headers/enduro2d/math/mat4.hpp index 3e3c9139..50cd3907 100644 --- a/headers/enduro2d/math/mat4.hpp +++ b/headers/enduro2d/math/mat4.hpp @@ -457,6 +457,46 @@ namespace e2d { namespace math axis_z); } + // + // make_loot_at_lh_matrix4 + // + + template < typename T > + std::enable_if_t::value, mat4> + make_loot_at_lh_matrix4(const vec3& eye, const vec3& at, const vec3& up) noexcept { + const vec3 az = normalized(at - eye); + const vec3 ax = normalized(math::cross(up, az)); + const vec3 ay = math::cross(az, ax); + const T dx = math::dot(ax, eye); + const T dy = math::dot(ay, eye); + const T dz = math::dot(az, eye); + return { + ax.x, ay.x, az.x, T(0), + ax.y, ay.y, az.y, T(0), + ax.z, ay.z, az.z, T(0), + -dx, -dy, -dz, T(1)}; + } + + // + // make_loot_at_rh_matrix4 + // + + template < typename T > + std::enable_if_t::value, mat4> + make_loot_at_rh_matrix4(const vec3& eye, const vec3& at, const vec3& up) noexcept { + const vec3 az = normalized(eye - at); + const vec3 ax = normalized(math::cross(up, az)); + const vec3 ay = math::cross(az, ax); + const T dx = math::dot(ax, eye); + const T dy = math::dot(ay, eye); + const T dz = math::dot(az, eye); + return { + ax.x, ay.x, az.x, T(0), + ax.y, ay.y, az.y, T(0), + ax.z, ay.z, az.z, T(0), + dx, dy, dz, T(1)}; + } + // // make_orthogonal_lh_matrix4 // diff --git a/samples/sources/sample_01/sample_01.cpp b/samples/sources/sample_01/sample_01.cpp index 3488d1cd..e3c647d1 100644 --- a/samples/sources/sample_01/sample_01.cpp +++ b/samples/sources/sample_01/sample_01.cpp @@ -238,7 +238,8 @@ int e2d_main() { math::make_rotation_matrix4(make_rad(game_time) * 0.001f, 1.f, 0.f, 0.f) * math::make_rotation_matrix4(make_rad(game_time) * 0.001f, 0.f, 1.f, 0.f) * math::make_rotation_matrix4(make_rad(game_time) * 0.001f, 0.f, 0.f, 1.f) * - math::make_translation_matrix4(0.f,0.f,3.f) * + math::make_translation_matrix4(0.f, 0.f, 0.f) * + math::make_loot_at_lh_matrix4({0.f,0.f,-3.f}, v3f::zero(), v3f::unit_y()) * projection; material.properties()