math::make_loot_at_XX

This commit is contained in:
2018-10-16 05:51:11 +07:00
parent 2fb8453473
commit 63dd2dd16d
2 changed files with 42 additions and 1 deletions

View File

@@ -457,6 +457,46 @@ namespace e2d { namespace math
axis_z); axis_z);
} }
//
// make_loot_at_lh_matrix4
//
template < typename T >
std::enable_if_t<std::is_floating_point<T>::value, mat4<T>>
make_loot_at_lh_matrix4(const vec3<T>& eye, const vec3<T>& at, const vec3<T>& up) noexcept {
const vec3<T> az = normalized(at - eye);
const vec3<T> ax = normalized(math::cross(up, az));
const vec3<T> 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<std::is_floating_point<T>::value, mat4<T>>
make_loot_at_rh_matrix4(const vec3<T>& eye, const vec3<T>& at, const vec3<T>& up) noexcept {
const vec3<T> az = normalized(eye - at);
const vec3<T> ax = normalized(math::cross(up, az));
const vec3<T> 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 // make_orthogonal_lh_matrix4
// //

View File

@@ -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, 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, 1.f, 0.f) *
math::make_rotation_matrix4(make_rad(game_time) * 0.001f, 0.f, 0.f, 1.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; projection;
material.properties() material.properties()