mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-11-22 15:02:54 +08:00
Fixed BVH generation for BoundComposite
This commit is contained in:
parent
839c4fc71c
commit
5f481bfd6f
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user