| 1589 | } |
| 1590 | |
| 1591 | int Skeleton::CheckRayCollisionBone(const vec3 &start, const vec3 &end) { |
| 1592 | SimpleRayResultCallbackInfo cb; |
| 1593 | col_bullet_world->CheckRayCollisionInfo(start, end, cb, false); |
| 1594 | if (cb.contact_info.size() == 0) { |
| 1595 | LOGI << "Did not hit anything!" << std::endl; |
| 1596 | return -1; |
| 1597 | } |
| 1598 | float closest_dist = FLT_MAX; |
| 1599 | int closest_hit = -1; |
| 1600 | for (int contact_index = 0, len = cb.contact_info.size(); contact_index < len; ++contact_index) { |
| 1601 | BulletObject *bo = cb.contact_info[contact_index].object; |
| 1602 | for (unsigned bone_index = 0; bone_index < physics_bones.size(); ++bone_index) { |
| 1603 | if (physics_bones[bone_index].col_bullet_object == bo) { |
| 1604 | float dist = distance_squared(start, cb.contact_info[contact_index].point); |
| 1605 | if (dist < closest_dist) { |
| 1606 | closest_hit = bone_index; |
| 1607 | closest_dist = dist; |
| 1608 | } |
| 1609 | } |
| 1610 | } |
| 1611 | } |
| 1612 | if (closest_hit != -1) { |
| 1613 | return closest_hit; |
| 1614 | } |
| 1615 | |
| 1616 | LOGI << "Hit unknown bone!" << std::endl; |
| 1617 | return -1; |
| 1618 | } |
| 1619 | |
| 1620 | PhysicsBone::PhysicsBone() : bone(0), |
| 1621 | bullet_object(NULL), |
no test coverage detected