diff --git a/CodeWalker.Core/GameFiles/Resources/Bounds.cs b/CodeWalker.Core/GameFiles/Resources/Bounds.cs index 9b157d2..719d3f6 100644 --- a/CodeWalker.Core/GameFiles/Resources/Bounds.cs +++ b/CodeWalker.Core/GameFiles/Resources/Bounds.cs @@ -2726,9 +2726,11 @@ namespace CodeWalker.GameFiles var child = Children.data_items[i]; if (child != null) { + var cbox = new BoundingBox(child.BoxMin, child.BoxMax); + var tcbox = cbox.Transform(child.Position, child.Orientation, child.Scale); var it = new BVHBuilderItem(); - it.Min = child.BoxMin; - it.Max = child.BoxMax; + it.Min = tcbox.Minimum; + it.Max = tcbox.Maximum; it.Index = i; it.Bounds = child; items.Add(it); diff --git a/CodeWalker.Core/Utils/Vectors.cs b/CodeWalker.Core/Utils/Vectors.cs index 0ce5b3e..0327f6b 100644 --- a/CodeWalker.Core/Utils/Vectors.cs +++ b/CodeWalker.Core/Utils/Vectors.cs @@ -121,6 +121,26 @@ namespace CodeWalker + public static class BoundingBoxMath + { + + public static BoundingBox Transform(this BoundingBox b, Vector3 position, Quaternion orientation, Vector3 scale) + { + var mat = Matrix.Transformation(Vector3.Zero, Quaternion.Identity, scale, Vector3.Zero, orientation, position); + var matabs = mat; + matabs.Column1 = mat.Column1.Abs(); + matabs.Column2 = mat.Column2.Abs(); + matabs.Column3 = mat.Column3.Abs(); + matabs.Column4 = mat.Column4.Abs(); + var bbcenter = (b.Maximum + b.Minimum) * 0.5f; + var bbextent = (b.Maximum - b.Minimum) * 0.5f; + var ncenter = Vector3.TransformCoordinate(bbcenter, mat); + var nextent = Vector3.TransformNormal(bbextent, matabs).Abs(); + return new BoundingBox(ncenter - nextent, ncenter + nextent); + } + + } + public struct BoundingCapsule