| 378 | } |
| 379 | |
| 380 | Vec2 Attack::getHitPoint(Body* self, Body* target, const pd::Shape& selfShape) { |
| 381 | Vec2 hitPoint{}; |
| 382 | float distance = -1; |
| 383 | auto selfB = self->getPrBody(); |
| 384 | auto targetB = target->getPrBody(); |
| 385 | if (target->getPhysicsWorld() && target->getPhysicsWorld()->getPrWorld()) { |
| 386 | auto& world = *target->getPhysicsWorld()->getPrWorld(); |
| 387 | const auto transformA = pd::GetTransformation(world, selfB); |
| 388 | for (pr::ShapeID f : pd::GetShapes(world, targetB)) { |
| 389 | if (!pd::IsSensor(world, f)) { |
| 390 | const auto proxyA = pd::GetChild(selfShape, 0); |
| 391 | const auto shapeB = pd::GetShape(world, f); |
| 392 | const auto proxyB = pd::GetChild(shapeB, 0); |
| 393 | const auto transformB = pd::GetTransformation(world, targetB); |
| 394 | pd::DistanceOutput output = Distance(proxyA, transformA, proxyB, transformB); |
| 395 | const auto witnessPoints = pd::GetWitnessPoints(output.simplex); |
| 396 | const auto outputDistance = pr::GetMagnitude(std::get<0>(witnessPoints) - std::get<1>(witnessPoints)); |
| 397 | if (distance == -1 || distance > outputDistance) { |
| 398 | distance = outputDistance; |
| 399 | hitPoint = PhysicsWorld::Val(std::get<1>(witnessPoints)); |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | return hitPoint; |
| 405 | } |
| 406 | |
| 407 | // MeleeAttack |
| 408 |
nothing calls this directly
no test coverage detected