Merge branch 'coll-resize-orient' of https://github.com/Tryibion/FlaxEngine into Tryibion-coll-resize-orient

This commit is contained in:
Wojtek Figat
2024-02-20 11:07:12 +01:00
3 changed files with 19 additions and 5 deletions

View File

@@ -20,7 +20,7 @@ void BoxCollider::SetSize(const Float3& value)
UpdateBounds();
}
void BoxCollider::AutoResize()
void BoxCollider::AutoResize(bool globalOrientation = true)
{
Actor* parent = GetParent();
if (Cast<Scene>(parent))
@@ -30,7 +30,13 @@ void BoxCollider::AutoResize()
const Vector3 parentScale = parent->GetScale();
if (parentScale.IsAnyZero())
return; // Avoid division by zero
// Hacky way to get unrotated bounded box of parent.
const Quaternion parentOrientation = parent->GetOrientation();
parent->SetOrientation(Quaternion::Identity);
BoundingBox parentBox = parent->GetBox();
parent->SetOrientation(parentOrientation);
for (const Actor* sibling : parent->Children)
{
if (sibling != this)
@@ -43,7 +49,10 @@ void BoxCollider::AutoResize()
SetLocalPosition(Vector3::Zero);
SetSize(parentSize / parentScale);
SetCenter(parentCenter / parentScale);
SetOrientation(GetOrientation() * Quaternion::Invert(GetOrientation()));
if (globalOrientation)
SetOrientation(GetOrientation() * Quaternion::Invert(GetOrientation()));
else
SetOrientation(parentOrientation);
}
#if USE_EDITOR

View File

@@ -46,7 +46,7 @@ public:
/// <summary>
/// Resizes the collider based on the bounds of it's parent to contain it whole (including any siblings).
/// </summary>
API_FUNCTION() void AutoResize();
API_FUNCTION() void AutoResize(bool globalOrientation);
public:
// [Collider]