diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-02-01 22:14:02 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-02-01 22:14:02 +0000 |
| commit | 3971db78c07230fe1afbb027c8df393f68b19b25 (patch) | |
| tree | 4cd29df56a6618ee3e5f0607263abb29a6ca0a0b /Common/interface | |
| parent | Fixed compiler warnings (diff) | |
| download | DiligentCore-3971db78c07230fe1afbb027c8df393f68b19b25.tar.gz DiligentCore-3971db78c07230fe1afbb027c8df393f68b19b25.zip | |
MathLib: added data() method to math objects
Diffstat (limited to 'Common/interface')
| -rw-r--r-- | Common/interface/BasicMath.hpp | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/Common/interface/BasicMath.hpp b/Common/interface/BasicMath.hpp index afc48ceb..9f748c78 100644 --- a/Common/interface/BasicMath.hpp +++ b/Common/interface/BasicMath.hpp @@ -211,14 +211,18 @@ template <class T> struct Vector2 y >= right.y ? static_cast<T>(1) : static_cast<T>(0)); } + T* data() { return reinterpret_cast<T*>(this); } + + const T* data() const { return reinterpret_cast<const T*>(this); } + T& operator[](size_t index) { - return reinterpret_cast<T*>(this)[index]; + return data()[index]; } const T& operator[](size_t index) const { - return reinterpret_cast<const T*>(this)[index]; + return data()[index]; } Vector2() : @@ -409,14 +413,18 @@ template <class T> struct Vector3 z >= right.z ? static_cast<T>(1) : static_cast<T>(0)); } + T* data() { return reinterpret_cast<T*>(this); } + + const T* data() const { return reinterpret_cast<const T*>(this); } + T& operator[](size_t index) { - return reinterpret_cast<T*>(this)[index]; + return data()[index]; } const T& operator[](size_t index) const { - return reinterpret_cast<const T*>(this)[index]; + return data()[index]; } Vector3() : @@ -621,14 +629,18 @@ template <class T> struct Vector4 w >= right.w ? static_cast<T>(1) : static_cast<T>(0)); } + T* data() { return reinterpret_cast<T*>(this); } + + const T* data() const { return reinterpret_cast<const T*>(this); } + T& operator[](size_t index) { - return reinterpret_cast<T*>(this)[index]; + return data()[index]; } const T& operator[](size_t index) const { - return reinterpret_cast<const T*>(this)[index]; + return data()[index]; } Vector4() : @@ -744,6 +756,11 @@ template <class T> struct Matrix2x2 return m[row]; } + T* data() { return (*this)[0]; } + + const T* data() const { return (*this)[0]; } + + Matrix2x2& operator*=(T s) { for (int i = 0; i < 4; ++i) @@ -906,6 +923,10 @@ template <class T> struct Matrix3x3 return m[row]; } + T* data() { return (*this)[0]; } + + const T* data() const { return (*this)[0]; } + Matrix3x3& operator*=(T s) { for (int i = 0; i < 9; ++i) @@ -1096,6 +1117,10 @@ template <class T> struct Matrix4x4 return m[row]; } + T* data() { return (*this)[0]; } + + const T* data() const { return (*this)[0]; } + Matrix4x4& operator*=(T s) { for (int i = 0; i < 16; ++i) |
