Move managed code into native impl for #2063
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "BoxCollider.h"
|
||||
#include "Engine/Physics/PhysicsBackend.h"
|
||||
#include "Engine/Level/Scene/Scene.h"
|
||||
|
||||
BoxCollider::BoxCollider(const SpawnParams& params)
|
||||
: Collider(params)
|
||||
@@ -19,6 +20,32 @@ void BoxCollider::SetSize(const Float3& value)
|
||||
UpdateBounds();
|
||||
}
|
||||
|
||||
void BoxCollider::AutoResize()
|
||||
{
|
||||
Actor* parent = GetParent();
|
||||
if (Cast<Scene>(parent))
|
||||
return;
|
||||
|
||||
// Get bounds of all siblings (excluding itself)
|
||||
const Vector3 parentScale = parent->GetScale();
|
||||
if (parentScale.IsAnyZero())
|
||||
return; // Avoid division by zero
|
||||
BoundingBox parentBox = parent->GetBox();
|
||||
for (const Actor* sibling : parent->Children)
|
||||
{
|
||||
if (sibling != this)
|
||||
BoundingBox::Merge(parentBox, sibling->GetBoxWithChildren(), parentBox);
|
||||
}
|
||||
const Vector3 parentSize = parentBox.GetSize();
|
||||
const Vector3 parentCenter = parentBox.GetCenter() - parent->GetPosition();
|
||||
|
||||
// Update bounds
|
||||
SetLocalPosition(Vector3::Zero);
|
||||
SetSize(parentSize / parentScale);
|
||||
SetCenter(parentCenter / parentScale);
|
||||
SetOrientation(GetOrientation() * Quaternion::Invert(GetOrientation()));
|
||||
}
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
#include "Engine/Debug/DebugDraw.h"
|
||||
|
||||
@@ -43,6 +43,11 @@ public:
|
||||
return _bounds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes the collider based on the bounds of it's parent to contain it whole (including any siblings).
|
||||
/// </summary>
|
||||
API_FUNCTION() void AutoResize();
|
||||
|
||||
public:
|
||||
// [Collider]
|
||||
#if USE_EDITOR
|
||||
|
||||
Reference in New Issue
Block a user