| 396 | _shape->InitPlanes(); |
| 397 | int index = _planes[i]; |
| 398 | return _shape->GetPlane(index); |
| 399 | } |
| 400 | const Poly& ConvexComponent::GetFace(int i) const |
| 401 | { |
| 402 | // note: this function needs BuildFaceIndexToOffset |
| 403 | // called on shape before using |
| 404 | int index = _planes[i]; |
| 405 | Offset o = _shape->FaceIndexToOffset(index); |
| 406 | return _shape->Face(o); |
| 407 | } |
| 408 | |
| 409 | void ConvexComponent::Init(Shape* shape, const char* name) |
| 410 | { |
| 411 | _shape = shape; |
| 412 | _minMax[0] = VZero; |
| 413 | _minMax[1] = VZero; |
| 414 | int index = shape->FindNamedSel(name); |
| 415 | if (index < 0) |
| 416 | { |
| 417 | return; |
| 418 | } |
| 419 | _minMax[0] = Vector3(+1e10, +1e10, +1e10); |
| 420 | _minMax[1] = Vector3(-1e10, -1e10, -1e10); |
| 421 | NamedSelection::DoDestruct(); |
| 422 | NamedSelection::DoConstruct(shape->NamedSel(index)); |
| 423 | |
| 424 | int size = Size(); |
| 425 | { |
| 426 | int index = (*this)[0]; |
| 427 | |
| 428 | Vector3Val p = _shape->Pos(index); |
| 429 | _minMax[0] = p; |
| 430 | _minMax[1] = p; |
| 431 | |
| 432 | for (int si = 1; si < size; si++) |
| 433 | { |
| 434 | int index = (*this)[si]; |
| 435 | CheckMinMaxIter(_minMax[0], _minMax[1], _shape->Pos(index)); |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | // find bounding center |
| 440 | _center = (_minMax[0] + _minMax[1]) * 0.5; |
| 441 | // find bounding sphere radius |
| 442 | float maxRadius2 = 0; |
| 443 | for (int si = 0; si < size; si++) |
| 444 | { |
| 445 | int index = (*this)[si]; |
| 446 | float radius2 = shape->Pos(index).Distance2(_center); |
| 447 | saturateMax(maxRadius2, radius2); |
| 448 | } |
| 449 | _radius = sqrt(maxRadius2); |
| 450 | // convert face representation to half space |
| 451 | const Selection& faces = Faces(); |
| 452 | // check first face of the selection |
| 453 | int faceIndex = faces[0]; |
no test coverage detected