| 21 | } |
| 22 | |
| 23 | void BoxCollider::AutoResize(bool globalOrientation = true) |
| 24 | { |
| 25 | Actor* parent = GetParent(); |
| 26 | if (parent == nullptr || Cast<Scene>(parent)) |
| 27 | return; |
| 28 | |
| 29 | // Get bounds of all siblings (excluding itself) |
| 30 | const Vector3 parentScale = parent->GetScale(); |
| 31 | if (parentScale.IsAnyZero()) |
| 32 | return; |
| 33 | |
| 34 | // Hacky way to get unrotated bounded box of parent |
| 35 | const Quaternion parentOrientation = parent->GetOrientation(); |
| 36 | parent->SetOrientation(Quaternion::Identity); |
| 37 | BoundingBox parentBox = parent->GetBox(); |
| 38 | parent->SetOrientation(parentOrientation); |
| 39 | |
| 40 | for (const Actor* sibling : parent->Children) |
| 41 | { |
| 42 | if (sibling != this) |
| 43 | BoundingBox::Merge(parentBox, sibling->GetBoxWithChildren(), parentBox); |
| 44 | } |
| 45 | const Vector3 parentSize = parentBox.GetSize(); |
| 46 | const Vector3 parentCenter = parentBox.GetCenter() - parent->GetPosition(); |
| 47 | |
| 48 | // Update bounds |
| 49 | SetLocalPosition(Vector3::Zero); |
| 50 | SetSize(parentSize / parentScale); |
| 51 | SetCenter(parentCenter / parentScale); |
| 52 | if (globalOrientation) |
| 53 | SetOrientation(GetOrientation() * Quaternion::Invert(GetOrientation())); |
| 54 | else |
| 55 | SetOrientation(parentOrientation); |
| 56 | } |
| 57 | |
| 58 | #if USE_EDITOR |
| 59 |
no test coverage detected