Improved ray shape (2D and 3D) by addiing the possibility to act as regular shape
This commit is contained in:
parent
cbdd410a6f
commit
ffc3ef8677
15 changed files with 117 additions and 20 deletions
|
|
@ -54,6 +54,11 @@ void btRayShape::setLength(btScalar p_length) {
|
|||
reload_cache();
|
||||
}
|
||||
|
||||
void btRayShape::setSlipsOnSlope(bool p_slipsOnSlope) {
|
||||
|
||||
slipsOnSlope = p_slipsOnSlope;
|
||||
}
|
||||
|
||||
btVector3 btRayShape::localGetSupportingVertex(const btVector3 &vec) const {
|
||||
return localGetSupportingVertexWithoutMargin(vec) + (m_shapeAxis * m_collisionMargin);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ ATTRIBUTE_ALIGNED16(class)
|
|||
btRayShape : public btConvexInternalShape {
|
||||
|
||||
btScalar m_length;
|
||||
bool slipsOnSlope;
|
||||
/// The default axis is the z
|
||||
btVector3 m_shapeAxis;
|
||||
|
||||
|
|
@ -59,6 +60,9 @@ public:
|
|||
void setLength(btScalar p_length);
|
||||
btScalar getLength() const { return m_length; }
|
||||
|
||||
void setSlipsOnSlope(bool p_slipOnSlope);
|
||||
bool getSlipsOnSlope() const { return slipsOnSlope; }
|
||||
|
||||
const btTransform &getSupportPoint() const { return m_cacheSupportPoint; }
|
||||
const btScalar &getScaledLength() const { return m_cacheScaledLength; }
|
||||
|
||||
|
|
|
|||
|
|
@ -100,14 +100,16 @@ void GodotRayWorldAlgorithm::processCollision(const btCollisionObjectWrapper *bo
|
|||
|
||||
if (btResult.hasHit()) {
|
||||
|
||||
btVector3 ray_normal(ray_transform.getOrigin() - to.getOrigin());
|
||||
ray_normal.normalize();
|
||||
btScalar depth(ray_shape->getScaledLength() * (btResult.m_closestHitFraction - 1));
|
||||
|
||||
if (depth >= -RAY_STABILITY_MARGIN)
|
||||
depth = 0;
|
||||
|
||||
resultOut->addContactPoint(ray_normal, btResult.m_hitPointWorld, depth);
|
||||
if (ray_shape->getSlipsOnSlope())
|
||||
resultOut->addContactPoint(btResult.m_hitNormalWorld, btResult.m_hitPointWorld, depth);
|
||||
else {
|
||||
resultOut->addContactPoint((ray_transform.getOrigin() - to.getOrigin()).normalize(), btResult.m_hitPointWorld, depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -135,8 +135,10 @@ btHeightfieldTerrainShape *ShapeBullet::create_shape_height_field(PoolVector<rea
|
|||
return bulletnew(btHeightfieldTerrainShape(p_width, p_depth, heightsPtr, ignoredHeightScale, -fieldHeight, fieldHeight, YAxis, PHY_FLOAT, flipQuadEdges));
|
||||
}
|
||||
|
||||
btRayShape *ShapeBullet::create_shape_ray(real_t p_length) {
|
||||
return bulletnew(btRayShape(p_length));
|
||||
btRayShape *ShapeBullet::create_shape_ray(real_t p_length, bool p_slips_on_slope) {
|
||||
btRayShape *r(bulletnew(btRayShape(p_length)));
|
||||
r->setSlipsOnSlope(p_slips_on_slope);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* PLANE */
|
||||
|
|
@ -435,25 +437,33 @@ btCollisionShape *HeightMapShapeBullet::create_bt_shape(const btVector3 &p_impli
|
|||
/* Ray shape */
|
||||
RayShapeBullet::RayShapeBullet() :
|
||||
ShapeBullet(),
|
||||
length(1) {}
|
||||
length(1),
|
||||
slips_on_slope(false) {}
|
||||
|
||||
void RayShapeBullet::set_data(const Variant &p_data) {
|
||||
setup(p_data);
|
||||
|
||||
Dictionary d = p_data;
|
||||
setup(d["length"], d["slips_on_slope"]);
|
||||
}
|
||||
|
||||
Variant RayShapeBullet::get_data() const {
|
||||
return length;
|
||||
|
||||
Dictionary d;
|
||||
d["length"] = length;
|
||||
d["slips_on_slope"] = slips_on_slope;
|
||||
return d;
|
||||
}
|
||||
|
||||
PhysicsServer::ShapeType RayShapeBullet::get_type() const {
|
||||
return PhysicsServer::SHAPE_RAY;
|
||||
}
|
||||
|
||||
void RayShapeBullet::setup(real_t p_length) {
|
||||
void RayShapeBullet::setup(real_t p_length, bool p_slips_on_slope) {
|
||||
length = p_length;
|
||||
slips_on_slope = p_slips_on_slope;
|
||||
notifyShapeChanged();
|
||||
}
|
||||
|
||||
btCollisionShape *RayShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) {
|
||||
return prepare(ShapeBullet::create_shape_ray(length * p_implicit_scale[1] + p_margin));
|
||||
return prepare(ShapeBullet::create_shape_ray(length * p_implicit_scale[1] + p_margin, slips_on_slope));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public:
|
|||
static class btConvexPointCloudShape *create_shape_convex(btAlignedObjectArray<btVector3> &p_vertices, const btVector3 &p_local_scaling = btVector3(1, 1, 1));
|
||||
static class btScaledBvhTriangleMeshShape *create_shape_concave(btBvhTriangleMeshShape *p_mesh_shape, const btVector3 &p_local_scaling = btVector3(1, 1, 1));
|
||||
static class btHeightfieldTerrainShape *create_shape_height_field(PoolVector<real_t> &p_heights, int p_width, int p_depth, real_t p_cell_size);
|
||||
static class btRayShape *create_shape_ray(real_t p_length);
|
||||
static class btRayShape *create_shape_ray(real_t p_length, bool p_slips_on_slope);
|
||||
};
|
||||
|
||||
class PlaneShapeBullet : public ShapeBullet {
|
||||
|
|
@ -216,6 +216,7 @@ class RayShapeBullet : public ShapeBullet {
|
|||
|
||||
public:
|
||||
real_t length;
|
||||
bool slips_on_slope;
|
||||
|
||||
RayShapeBullet();
|
||||
|
||||
|
|
@ -225,6 +226,6 @@ public:
|
|||
virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin = 0);
|
||||
|
||||
private:
|
||||
void setup(real_t p_length);
|
||||
void setup(real_t p_length, bool p_slips_on_slope);
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue