scale3, scale4 ext functions

This commit is contained in:
BlackMATov
2021-02-27 06:13:06 +07:00
parent 0ea995d32f
commit 9c70e2d40c
4 changed files with 115 additions and 92 deletions

View File

@@ -389,24 +389,14 @@ namespace vmath_hpp
// scale
template < typename T >
[[nodiscard]] constexpr mat<T, 3> scale(T x, T y, T z) {
[[nodiscard]] constexpr mat<T, 3> scale(const vec<T, 3>& v) {
/// REFERENCE:
/// https://en.wikipedia.org/wiki/Scaling_(geometry)
return {
{ x, T{0}, T{0} },
{ T{0}, y, T{0} },
{ T{0}, T{0}, z }};
}
template < typename T >
[[nodiscard]] constexpr mat<T, 3> scale(const mat<T, 3>& m, T x, T y, T z) {
return m * scale(x, y, z);
}
template < typename T >
[[nodiscard]] constexpr mat<T, 3> scale(const vec<T, 3>& v) {
return scale(v.x, v.y, v.z);
{ v.x, T{0}, T{0} },
{ T{0}, v.y, T{0} },
{ T{0}, T{0}, v.z }};
}
template < typename T >
@@ -414,6 +404,25 @@ namespace vmath_hpp
return m * scale(v);
}
// scale4
template < typename T >
[[nodiscard]] constexpr mat<T, 4> scale4(const vec<T, 3>& v) {
/// REFERENCE:
/// https://en.wikipedia.org/wiki/Scaling_(geometry)
return {
{ v.x, T{0}, T{0}, T{0} },
{ T{0}, v.y, T{0}, T{0} },
{ T{0}, T{0}, v.z, T{0} },
{ T{0}, T{0}, T{0}, T{1} }};
}
template < typename T >
[[nodiscard]] constexpr mat<T, 4> scale4(const mat<T, 4>& m, const vec<T, 3>& v) {
return m * scale4(v);
}
// look_at
template < typename T >
@@ -557,23 +566,13 @@ namespace vmath_hpp
// scale
template < typename T >
[[nodiscard]] constexpr mat<T, 2> scale(T x, T y) {
[[nodiscard]] constexpr mat<T, 2> scale(const vec<T, 2>& v) {
/// REFERENCE:
/// https://en.wikipedia.org/wiki/Scaling_(geometry)
return {
{ x, T{0} },
{ T{0}, y }};
}
template < typename T >
[[nodiscard]] constexpr mat<T, 2> scale(const mat<T, 2>& m, T x, T y) {
return m * scale(x, y);
}
template < typename T >
[[nodiscard]] constexpr mat<T, 2> scale(const vec<T, 2>& v) {
return scale(v.x, v.y);
{ v.x, T{0} },
{ T{0}, v.y }};
}
template < typename T >
@@ -581,6 +580,24 @@ namespace vmath_hpp
return m * scale(v);
}
// scale3
template < typename T >
[[nodiscard]] constexpr mat<T, 3> scale3(const vec<T, 2>& v) {
/// REFERENCE:
/// https://en.wikipedia.org/wiki/Scaling_(geometry)
return {
{ v.x, T{0}, T{0} },
{ T{0}, v.y, T{0} },
{ T{0}, T{0}, T{1} }};
}
template < typename T >
[[nodiscard]] constexpr mat<T, 3> scale3(const mat<T, 3>& m, const vec<T, 2>& v) {
return m * scale3(v);
}
// shear
template < typename T >