summaryrefslogtreecommitdiffstats
path: root/Common/interface
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-06-28 02:51:50 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-06-28 02:51:50 +0000
commit23583ced0fbb484c97deb2b7abb3a5d594eaee56 (patch)
treebcab12bc3e473807841fc349b56a2aa84da96697 /Common/interface
parentMathLib: updated ViewFrustum struct (diff)
downloadDiligentCore-23583ced0fbb484c97deb2b7abb3a5d594eaee56.tar.gz
DiligentCore-23583ced0fbb484c97deb2b7abb3a5d594eaee56.zip
MathLib: added bound box transform function
Diffstat (limited to 'Common/interface')
-rw-r--r--Common/interface/AdvancedMath.hpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/Common/interface/AdvancedMath.hpp b/Common/interface/AdvancedMath.hpp
index 21a633cc..b48da1bc 100644
--- a/Common/interface/AdvancedMath.hpp
+++ b/Common/interface/AdvancedMath.hpp
@@ -175,6 +175,38 @@ struct BoundBox
{
float3 Min;
float3 Max;
+
+ // Computes new bounding box by applying transform matrix m to the box
+ BoundBox Transform(const float4x4& m) const
+ {
+ BoundBox NewBB;
+ NewBB.Min = float3::MakeVector(m[3]);
+ NewBB.Max = NewBB.Min;
+ float3 v0, v1;
+
+ float3 right = float3::MakeVector(m[0]);
+
+ v0 = right * Min.x;
+ v1 = right * Max.x;
+ NewBB.Min += std::min(v0, v1);
+ NewBB.Max += std::max(v0, v1);
+
+ float3 up = float3::MakeVector(m[1]);
+
+ v0 = up * Min.y;
+ v1 = up * Max.y;
+ NewBB.Min += std::min(v0, v1);
+ NewBB.Max += std::max(v0, v1);
+
+ float3 back = float3::MakeVector(m[2]);
+
+ v0 = back * Min.z;
+ v1 = back * Max.z;
+ NewBB.Min += std::min(v0, v1);
+ NewBB.Max += std::max(v0, v1);
+
+ return NewBB;
+ }
};
enum class BoxVisibility