summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-12-10 12:28:34 +0100
committerGitHub <noreply@github.com>2017-12-10 12:28:34 +0100
commitdefeb49b01544af99cab4de08cbc989b8d87d63b (patch)
treee6c6e53720f9288a5d16d041ee3264a6fb7d7f86
parent7d735da6aa86861c4d0ba81ec769d3b6d7dad3c0 (diff)
parent785173e899862bfa9ce65ee4cd8c718d120d2c0f (diff)
Merge pull request #14498 from AndreaCatania/patch-1
Ray cast return correct shape id. Fixes #14473
-rw-r--r--modules/bullet/godot_result_callbacks.h9
-rw-r--r--modules/bullet/space_bullet.cpp2
2 files changed, 9 insertions, 2 deletions
diff --git a/modules/bullet/godot_result_callbacks.h b/modules/bullet/godot_result_callbacks.h
index 5750dc2acd..9d2fb1fce4 100644
--- a/modules/bullet/godot_result_callbacks.h
+++ b/modules/bullet/godot_result_callbacks.h
@@ -50,14 +50,21 @@ struct GodotFilterCallback : public btOverlapFilterCallback {
struct GodotClosestRayResultCallback : public btCollisionWorld::ClosestRayResultCallback {
const Set<RID> *m_exclude;
bool m_pickRay;
+ int m_shapeId;
public:
GodotClosestRayResultCallback(const btVector3 &rayFromWorld, const btVector3 &rayToWorld, const Set<RID> *p_exclude) :
btCollisionWorld::ClosestRayResultCallback(rayFromWorld, rayToWorld),
m_exclude(p_exclude),
- m_pickRay(false) {}
+ m_pickRay(false),
+ m_shapeId(0) {}
virtual bool needsCollision(btBroadphaseProxy *proxy0) const;
+
+ virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult &rayResult, bool normalInWorldSpace) {
+ m_shapeId = rayResult.m_localShapeInfo->m_triangleIndex; // "m_triangleIndex" Is a odd name but contains the compound shape ID
+ return btCollisionWorld::ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
+ }
};
// store all colliding object
diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp
index c1f6e81734..3ce4b294db 100644
--- a/modules/bullet/space_bullet.cpp
+++ b/modules/bullet/space_bullet.cpp
@@ -97,7 +97,7 @@ bool BulletPhysicsDirectSpaceState::intersect_ray(const Vector3 &p_from, const V
B_TO_G(btResult.m_hitNormalWorld.normalize(), r_result.normal);
CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btResult.m_collisionObject->getUserPointer());
if (gObj) {
- r_result.shape = 0;
+ r_result.shape = btResult.m_shapeId;
r_result.rid = gObj->get_self();
r_result.collider_id = gObj->get_instance_id();
r_result.collider = 0 == r_result.collider_id ? NULL : ObjectDB::get_instance(r_result.collider_id);