Fixed BVH generation for BoundComposite

This commit is contained in:
dexy 2020-01-27 16:58:53 +11:00
parent 839c4fc71c
commit 5f481bfd6f
2 changed files with 24 additions and 2 deletions

View File

@ -2726,9 +2726,11 @@ namespace CodeWalker.GameFiles
var child = Children.data_items[i]; var child = Children.data_items[i];
if (child != null) 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(); var it = new BVHBuilderItem();
it.Min = child.BoxMin; it.Min = tcbox.Minimum;
it.Max = child.BoxMax; it.Max = tcbox.Maximum;
it.Index = i; it.Index = i;
it.Bounds = child; it.Bounds = child;
items.Add(it); items.Add(it);

View File

@ -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 public struct BoundingCapsule