| 14 | namespace TEN::Collision::Sphere |
| 15 | { |
| 16 | bool HandleItemSphereCollision(ItemInfo& item0, ItemInfo& item1) |
| 17 | { |
| 18 | auto spheres0 = item0.GetSpheres(); |
| 19 | auto spheres1 = item1.GetSpheres(); |
| 20 | |
| 21 | item1.TouchBits.ClearAll(); |
| 22 | |
| 23 | if (spheres0.empty()) |
| 24 | { |
| 25 | item0.TouchBits.ClearAll(); |
| 26 | return false; |
| 27 | } |
| 28 | |
| 29 | // Run through item 0 spheres. |
| 30 | bool isCollided = false; |
| 31 | for (int i = 0; i < spheres0.size(); i++) |
| 32 | { |
| 33 | // Get sphere 0. |
| 34 | const auto& sphere0 = spheres0[i]; |
| 35 | if (sphere0.Radius <= 0.0f) |
| 36 | continue; |
| 37 | |
| 38 | // Run through item 1 spheres. |
| 39 | for (int j = 0; j < spheres1.size(); j++) |
| 40 | { |
| 41 | // Get sphere 1. |
| 42 | const auto& sphere1 = spheres1[j]; |
| 43 | if (sphere1.Radius <= 0.0f) |
| 44 | continue; |
| 45 | |
| 46 | // Test sphere collision. |
| 47 | if (!sphere0.Intersects(sphere1)) |
| 48 | continue; |
| 49 | |
| 50 | // Set touch bits. |
| 51 | item0.TouchBits.Set(i); |
| 52 | item1.TouchBits.Set(j); |
| 53 | |
| 54 | isCollided = true; |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return isCollided; |
| 60 | } |
| 61 | } |
no test coverage detected