| 194 | } |
| 195 | |
| 196 | void 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 | |
| 228 | void MeshData::TransformBuffer(const Matrix& matrix) |
| 229 | { |
no test coverage detected