|
@@ -150,14 +150,14 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra
|
|
|
return btQuery.m_count;
|
|
|
}
|
|
|
|
|
|
-bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, ShapeRestInfo *r_info) {
|
|
|
+bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &r_closest_safe, float &r_closest_unsafe, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, ShapeRestInfo *r_info) {
|
|
|
ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape);
|
|
|
|
|
|
btCollisionShape *btShape = shape->create_bt_shape(p_xform.basis.get_scale(), p_margin);
|
|
|
if (!btShape->isConvex()) {
|
|
|
bulletdelete(btShape);
|
|
|
ERR_PRINTS("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type()));
|
|
|
- return 0;
|
|
|
+ return false;
|
|
|
}
|
|
|
btConvexShape *bt_convex_shape = static_cast<btConvexShape *>(btShape);
|
|
|
|
|
@@ -177,10 +177,13 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf
|
|
|
|
|
|
space->dynamicsWorld->convexSweepTest(bt_convex_shape, bt_xform_from, bt_xform_to, btResult, 0.002);
|
|
|
|
|
|
+ r_closest_unsafe = 1.0;
|
|
|
+ r_closest_safe = 1.0;
|
|
|
+
|
|
|
if (btResult.hasHit()) {
|
|
|
const btScalar l = bt_motion.length();
|
|
|
- p_closest_unsafe = btResult.m_closestHitFraction;
|
|
|
- p_closest_safe = MAX(p_closest_unsafe - (1 - ((l - 0.01) / l)), 0);
|
|
|
+ r_closest_unsafe = btResult.m_closestHitFraction;
|
|
|
+ r_closest_safe = MAX(r_closest_unsafe - (1 - ((l - 0.01) / l)), 0);
|
|
|
if (r_info) {
|
|
|
if (btCollisionObject::CO_RIGID_BODY == btResult.m_hitCollisionObject->getInternalType()) {
|
|
|
B_TO_G(static_cast<const btRigidBody *>(btResult.m_hitCollisionObject)->getVelocityInLocalPoint(btResult.m_hitPointWorld), r_info->linear_velocity);
|
|
@@ -195,7 +198,7 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf
|
|
|
}
|
|
|
|
|
|
bulletdelete(bt_convex_shape);
|
|
|
- return btResult.hasHit();
|
|
|
+ return true; // Mean success
|
|
|
}
|
|
|
|
|
|
/// Returns the list of contacts pairs in this order: Local contact, other body contact
|