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

Method CalculateBounds

Source/Engine/Graphics/Models/ModelData.cpp:196–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194}
195
196void MeshData::CalculateBounds(BoundingBox& box, BoundingSphere& sphere) const
197{
198 if (Positions.HasItems())
199 {
200 // Merged code of BoundingBox::FromPoints and BoundingSphere::FromPoints within a single loop
201 const Float3* points = Positions.Get();
202 const int32 pointsCount = Positions.Count();
203 Float3 min = points[0];
204 Float3 max = min;
205 Float3 center = min;
206 for (int32 i = 1; i < pointsCount; i++)
207 Float3::Add(points[i], center, center);
208 center /= (float)pointsCount;
209 float radiusSq = Float3::DistanceSquared(center, min);
210 for (int32 i = 1; i < pointsCount; i++)
211 {
212 Float3::Min(min, points[i], min);
213 Float3::Max(max, points[i], max);
214 const float distance = Float3::DistanceSquared(center, points[i]);
215 if (distance > radiusSq)
216 radiusSq = distance;
217 }
218 box = BoundingBox(min, max);
219 sphere = BoundingSphere(center, Math::Sqrt(radiusSq));
220 }
221 else
222 {
223 box = BoundingBox::Zero;
224 sphere = BoundingSphere::Empty;
225 }
226}
227
228void MeshData::TransformBuffer(const Matrix& matrix)
229{

Callers 2

SaveHeaderMethod · 0.80
SaveHeaderMethod · 0.80

Calls 9

AddFunction · 0.50
MinFunction · 0.50
MaxFunction · 0.50
BoundingBoxClass · 0.50
BoundingSphereClass · 0.50
SqrtFunction · 0.50
HasItemsMethod · 0.45
GetMethod · 0.45
CountMethod · 0.45

Tested by

no test coverage detected