From 6085f14ff822f591e96b321aa26a5f0005cc1c01 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Tue, 22 Jan 2019 21:55:11 -0800 Subject: Moved math utils to Diligent namespace --- Common/interface/AdvancedMath.h | 22 +++++++++++------ Common/interface/BasicMath.h | 55 ++++++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 33 deletions(-) (limited to 'Common/interface') diff --git a/Common/interface/AdvancedMath.h b/Common/interface/AdvancedMath.h index 79cedf7e..0481b22e 100644 --- a/Common/interface/AdvancedMath.h +++ b/Common/interface/AdvancedMath.h @@ -26,6 +26,9 @@ #include "BasicMath.h" #include "../../Platforms/interface/PlatformDefinitions.h" +namespace Diligent +{ + // Structure describing a plane struct Plane3D { @@ -314,35 +317,38 @@ inline bool operator == (const ViewFrustumExt &f1, const ViewFrustumExt &f2) return true; } + +} // namespace Diligent + namespace std { template<> - struct hash + struct hash { - size_t operator()( const Plane3D &Plane ) const + size_t operator()( const Diligent::Plane3D &Plane ) const { return Diligent::ComputeHash(Plane.Normal, Plane.Distance); } }; template<> - struct hash + struct hash { - size_t operator()( const ViewFrustum &Frustum ) const + size_t operator()( const Diligent::ViewFrustum &Frustum ) const { return Diligent::ComputeHash(Frustum.LeftPlane, Frustum.RightPlane, Frustum.BottomPlane, Frustum.TopPlane, Frustum.NearPlane, Frustum.FarPlane); } }; template<> - struct hash + struct hash { - size_t operator()( const ViewFrustumExt &Frustum ) const + size_t operator()( const Diligent::ViewFrustumExt &Frustum ) const { - auto Seed = Diligent::ComputeHash(static_cast(Frustum)); + auto Seed = Diligent::ComputeHash(static_cast(Frustum)); for (int Corner = 0; Corner < _countof(Frustum.FrustumCorners); ++Corner) Diligent::HashCombine(Seed, Frustum.FrustumCorners[Corner]); return Seed; } }; -} +} // namespace std diff --git a/Common/interface/BasicMath.h b/Common/interface/BasicMath.h index c22ddf8b..49f3e3e9 100644 --- a/Common/interface/BasicMath.h +++ b/Common/interface/BasicMath.h @@ -39,6 +39,9 @@ #define PI_F 3.1415927f +namespace Diligent +{ + // Template Vector & Matrix Classes template struct Matrix4x4; template struct Vector4; @@ -1421,21 +1424,23 @@ inline float4x4 inverseMatrix(const float4x4& m) return inv; } +} // namespace Diligent + namespace std { template - Vector2 max( const Vector2 &Left, const Vector2 &Right ) + Diligent::Vector2 max( const Diligent::Vector2 &Left, const Diligent::Vector2 &Right ) { - return Vector2( + return Diligent::Vector2( std::max( Left.x, Right.x ), std::max( Left.y, Right.y ) ); } template - Vector3 max( const Vector3 &Left, const Vector3 &Right ) + Diligent::Vector3 max( const Diligent::Vector3 &Left, const Diligent::Vector3 &Right ) { - return Vector3( + return Diligent::Vector3( std::max( Left.x, Right.x ), std::max( Left.y, Right.y ), std::max( Left.z, Right.z ) @@ -1443,9 +1448,9 @@ namespace std } template - Vector4 max( const Vector4 &Left, const Vector4 &Right ) + Diligent::Vector4 max( const Diligent::Vector4 &Left, const Diligent::Vector4 &Right ) { - return Vector4( + return Diligent::Vector4( std::max( Left.x, Right.x ), std::max( Left.y, Right.y ), std::max( Left.z, Right.z ), @@ -1455,18 +1460,18 @@ namespace std template - Vector2 min( const Vector2 &Left, const Vector2 &Right ) + Diligent::Vector2 min( const Diligent::Vector2 &Left, const Diligent::Vector2 &Right ) { - return Vector2( + return Diligent::Vector2( std::min( Left.x, Right.x ), std::min( Left.y, Right.y ) ); } template - Vector3 min( const Vector3 &Left, const Vector3 &Right ) + Diligent::Vector3 min( const Diligent::Vector3 &Left, const Diligent::Vector3 &Right ) { - return Vector3( + return Diligent::Vector3( std::min( Left.x, Right.x ), std::min( Left.y, Right.y ), std::min( Left.z, Right.z ) @@ -1474,9 +1479,9 @@ namespace std } template - Vector4 min( const Vector4 &Left, const Vector4 &Right ) + Diligent::Vector4 min( const Diligent::Vector4 &Left, const Diligent::Vector4 &Right ) { - return Vector4( + return Diligent::Vector4( std::min( Left.x, Right.x ), std::min( Left.y, Right.y ), std::min( Left.z, Right.z ), @@ -1486,36 +1491,36 @@ namespace std template - struct hash> + struct hash> { - size_t operator()( const Vector2 &v2 ) const + size_t operator()( const Diligent::Vector2 &v2 ) const { return Diligent::ComputeHash(v2.x, v2.y); } }; template - struct hash> + struct hash> { - size_t operator()( const Vector3 &v3 ) const + size_t operator()( const Diligent::Vector3 &v3 ) const { return Diligent::ComputeHash(v3.x, v3.y, v3.z); } }; template - struct hash> + struct hash> { - size_t operator()( const Vector4 &v4 ) const + size_t operator()( const Diligent::Vector4 &v4 ) const { return Diligent::ComputeHash(v4.x, v4.y, v4.z, v4.w); } }; template - struct hash> + struct hash> { - size_t operator()(const Matrix2x2 &m) const + size_t operator()(const Diligent::Matrix2x2 &m) const { return Diligent::ComputeHash( m._m00, m._m01, @@ -1525,9 +1530,9 @@ namespace std }; template - struct hash> + struct hash> { - size_t operator()( const Matrix3x3 &m ) const + size_t operator()( const Diligent::Matrix3x3 &m ) const { return Diligent::ComputeHash( m._m00, m._m01, m._m02, @@ -1538,9 +1543,9 @@ namespace std }; template - struct hash> + struct hash> { - size_t operator()( const Matrix4x4 &m ) const + size_t operator()( const Diligent::Matrix4x4 &m ) const { return Diligent::ComputeHash( m._m00, m._m01, m._m02, m._m03, @@ -1550,7 +1555,7 @@ namespace std ); } }; -} +} // namespace std #ifdef _MSC_VER # pragma warning(pop) -- cgit v1.2.3