summaryrefslogtreecommitdiffstats
path: root/Common/interface
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-06-16 05:45:36 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-06-16 05:45:36 +0000
commit26e9e9e7602fed809c838161e656e1f26d5adf0a (patch)
tree1b83ef2bb186ba3d7f3f4ac4ad411ed7fbb0c79e /Common/interface
parentMat lib: added floor & ceil vector operations (diff)
downloadDiligentCore-26e9e9e7602fed809c838161e656e1f26d5adf0a.tar.gz
DiligentCore-26e9e9e7602fed809c838161e656e1f26d5adf0a.zip
Few updates/fixes to math lib
Diffstat (limited to 'Common/interface')
-rw-r--r--Common/interface/BasicMath.h28
1 files changed, 27 insertions, 1 deletions
diff --git a/Common/interface/BasicMath.h b/Common/interface/BasicMath.h
index e41e6f9f..d98d623d 100644
--- a/Common/interface/BasicMath.h
+++ b/Common/interface/BasicMath.h
@@ -63,6 +63,8 @@ static constexpr double PI = 3.14159265358979323846;
static constexpr float PI_F = 3.1415927f;
// Template Vector & Matrix Classes
+template <class T> struct Matrix2x2;
+template <class T> struct Matrix3x3;
template <class T> struct Matrix4x4;
template <class T> struct Vector4;
@@ -141,6 +143,14 @@ template <class T> struct Vector2
return *this;
}
+ Vector2 operator*(const Matrix2x2<T>& m)const
+ {
+ Vector2 out;
+ out[0] = x * m[0][0] + y * m[1][0];
+ out[1] = x * m[0][1] + y * m[1][1];
+ return out;
+ }
+
Vector2 operator/(const Vector2 &right)const
{
return Vector2(x / right.x, y / right.y);
@@ -328,6 +338,15 @@ template <class T> struct Vector3
return *this;
}
+ Vector3 operator*(const Matrix3x3<T>& m)const
+ {
+ Vector3 out;
+ out[0] = x * m[0][0] + y * m[1][0] + z * m[2][0];
+ out[1] = x * m[0][1] + y * m[1][1] + z * m[2][1];
+ out[2] = x * m[0][2] + y * m[1][2] + z * m[2][2];
+ return out;
+ }
+
Vector3 operator/ ( T s)const
{
return Vector3(x / s, y / s, z / s);
@@ -1730,11 +1749,18 @@ inline Quaternion slerp(Quaternion v0, Quaternion v1, float t, bool DoNotNormali
template<typename T>
-T lerp(const T& Left, T& Right, float w)
+T lerp(const T& Left, const T& Right, float w)
{
return Left * (1.f - w) + Right * w;
}
+template<typename T>
+T SmoothStep(T Left, T Right, T w)
+{
+ auto t = clamp((w - Left) / (Right - Left), static_cast<T>(0), static_cast<T>(1));
+ return t * t * (static_cast<T>(3) - static_cast<T>(2) * t);
+}
+
} // namespace Diligent
namespace std