MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / AutoResize

Method AutoResize

Source/Engine/Physics/Colliders/BoxCollider.cpp:23–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23void 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

Callers 2

OnResizeClickedMethod · 0.80
PostSpawnMethod · 0.80

Calls 12

SetSizeFunction · 0.85
SetCenterFunction · 0.85
GetOrientationFunction · 0.85
SetOrientationMethod · 0.80
GetBoxWithChildrenMethod · 0.80
GetParentFunction · 0.50
MergeFunction · 0.50
InvertFunction · 0.50
IsAnyZeroMethod · 0.45
GetBoxMethod · 0.45
GetSizeMethod · 0.45
GetPositionMethod · 0.45

Tested by

no test coverage detected