Merge pull request #21843 from AndreaCatania/bugfix1
Fixed crash during raycast and CCD radius calculation
This commit is contained in:
commit
df39a034dc
2 changed files with 13 additions and 5 deletions
|
@ -74,7 +74,10 @@ public:
|
||||||
virtual bool needsCollision(btBroadphaseProxy *proxy0) const;
|
virtual bool needsCollision(btBroadphaseProxy *proxy0) const;
|
||||||
|
|
||||||
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult &rayResult, bool normalInWorldSpace) {
|
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
|
if (rayResult.m_localShapeInfo)
|
||||||
|
m_shapeId = rayResult.m_localShapeInfo->m_triangleIndex; // "m_triangleIndex" Is a odd name but contains the compound shape ID
|
||||||
|
else
|
||||||
|
m_shapeId = 0;
|
||||||
return btCollisionWorld::ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
|
return btCollisionWorld::ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -316,6 +316,7 @@ void RigidBodyBullet::destroy_kinematic_utilities() {
|
||||||
|
|
||||||
void RigidBodyBullet::main_shape_resetted() {
|
void RigidBodyBullet::main_shape_resetted() {
|
||||||
btBody->setCollisionShape(get_main_shape());
|
btBody->setCollisionShape(get_main_shape());
|
||||||
|
set_continuous_collision_detection(is_continuous_collision_detection_enabled()); // Reset
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBodyBullet::reload_body() {
|
void RigidBodyBullet::reload_body() {
|
||||||
|
@ -716,15 +717,19 @@ void RigidBodyBullet::set_continuous_collision_detection(bool p_enable) {
|
||||||
if (p_enable) {
|
if (p_enable) {
|
||||||
// This threshold enable CCD if the object moves more than
|
// This threshold enable CCD if the object moves more than
|
||||||
// 1 meter in one simulation frame
|
// 1 meter in one simulation frame
|
||||||
btBody->setCcdMotionThreshold(1);
|
btBody->setCcdMotionThreshold(0.1);
|
||||||
|
|
||||||
/// Calculate using the rule writte below the CCD swept sphere radius
|
/// Calculate using the rule writte below the CCD swept sphere radius
|
||||||
/// CCD works on an embedded sphere of radius, make sure this radius
|
/// CCD works on an embedded sphere of radius, make sure this radius
|
||||||
/// is embedded inside the convex objects, preferably smaller:
|
/// is embedded inside the convex objects, preferably smaller:
|
||||||
/// for an object of dimensions 1 meter, try 0.2
|
/// for an object of dimensions 1 meter, try 0.2
|
||||||
btVector3 center;
|
|
||||||
btScalar radius;
|
btScalar radius;
|
||||||
btBody->getCollisionShape()->getBoundingSphere(center, radius);
|
if (btBody->getCollisionShape()) {
|
||||||
|
btVector3 center;
|
||||||
|
btBody->getCollisionShape()->getBoundingSphere(center, radius);
|
||||||
|
} else {
|
||||||
|
radius = 0;
|
||||||
|
}
|
||||||
btBody->setCcdSweptSphereRadius(radius * 0.2);
|
btBody->setCcdSweptSphereRadius(radius * 0.2);
|
||||||
} else {
|
} else {
|
||||||
btBody->setCcdMotionThreshold(0.);
|
btBody->setCcdMotionThreshold(0.);
|
||||||
|
@ -733,7 +738,7 @@ void RigidBodyBullet::set_continuous_collision_detection(bool p_enable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RigidBodyBullet::is_continuous_collision_detection_enabled() const {
|
bool RigidBodyBullet::is_continuous_collision_detection_enabled() const {
|
||||||
return 0. != btBody->getCcdMotionThreshold();
|
return 0. < btBody->getCcdMotionThreshold();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBodyBullet::set_linear_velocity(const Vector3 &p_velocity) {
|
void RigidBodyBullet::set_linear_velocity(const Vector3 &p_velocity) {
|
||||||
|
|
Loading…
Reference in a new issue