MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / GetDisplayItemBounds

Method GetDisplayItemBounds

TombEngine/Renderer/RendererHelper.cpp:692–834  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

690 }
691
692 std::optional<std::pair<Vector2, Vector2>> Renderer::GetDisplayItemBounds(const DisplayItem& item) const
693 {
694 float alpha = GetInterpolationFactor();
695
696 // World transforms.
697 auto pos = item.GetInterpolatedPosition(alpha);
698 auto orient = item.GetInterpolatedOrientation(alpha);
699 float scale = item.GetInterpolatedScale(alpha).x;
700 auto objectID = item.GetObjectID();
701
702 // Find largest visible mesh sphere.
703 auto& moveable = _moveableObjects[item.GetObjectID()];
704
705 float radiusMax = 0.0f;
706 auto worldCenter = Vector3::Zero;
707
708 const auto& object = Objects[objectID];
709
710 // Loop through meshes.
711 for (int i = 0; i < moveable->ObjectMeshes.size(); ++i)
712 {
713 if (item.GetMeshBits() && !item.GetMeshVisible(i))
714 continue;
715
716 const auto& s = moveable->ObjectMeshes[i]->Sphere;
717
718 // World matrix per mesh (animation or bind-pose).
719 auto meshWorldMatrix = Matrix::Identity;
720 if (!object.Animations.empty())
721 {
722 meshWorldMatrix = moveable->AnimationTransforms[i] * Matrix::CreateScale(scale) * orient.ToRotationMatrix() * Matrix::CreateTranslation(pos);
723 }
724 else
725 {
726 meshWorldMatrix = moveable->BindPoseTransforms[i] * Matrix::CreateScale(scale) * orient.ToRotationMatrix() * Matrix::CreateTranslation(pos);
727 }
728
729 // Transform center.
730 auto meshWorldCenter = Vector3::Transform(s.Center, meshWorldMatrix);
731 float meshWorldRadius = s.Radius * scale;
732
733 // Keep largest for bounding approximation.
734 if (meshWorldRadius > radiusMax)
735 {
736 radiusMax = meshWorldRadius;
737 worldCenter = meshWorldCenter;
738 }
739 }
740
741 // Use default minimum radius if none found.
742 if (radiusMax <= 0.0f)
743 radiusMax = 10.0f;
744
745 // Build camera matrices.
746 auto camPos = g_DrawItems.GetInterpolatedCameraPosition(alpha);
747 auto camTarget = g_DrawItems.GetInterpolatedCameraTargetPosition(alpha);
748 auto camForward = (camTarget - camPos);
749 camForward.Normalize();

Callers 1

GetBoundsMethod · 0.80

Calls 15

GetInterpolatedScaleMethod · 0.80
GetMeshBitsMethod · 0.80
Vector4Function · 0.50
Vector2Function · 0.50
GetObjectIDMethod · 0.45
sizeMethod · 0.45
GetMeshVisibleMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected