mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Added convex hull collision shape
This commit is contained in:
@@ -330,12 +330,30 @@ namespace Nuake
|
||||
|
||||
shapeResult = shapeSettings.Create();
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case CONVEX_HULL:
|
||||
{
|
||||
ConvexHullShape* shape = (ConvexHullShape*)rbShape.get();
|
||||
|
||||
const auto& hullPoints = shape->GetPoints();
|
||||
JPH::Array<JPH::Vec3> points;
|
||||
points.reserve(std::size(hullPoints));
|
||||
for (const auto& p : hullPoints)
|
||||
{
|
||||
points.push_back(JPH::Vec3(p.x, p.y, p.z));
|
||||
}
|
||||
|
||||
JPH::ConvexHullShapeSettings shapeSettings(points);
|
||||
shapeResult = shapeSettings.Create();
|
||||
}
|
||||
break;
|
||||
}
|
||||
float mass = rb->_mass;
|
||||
|
||||
JPH::EMotionType motionType = JPH::EMotionType::Static;
|
||||
if (mass > 0.0f)
|
||||
|
||||
float mass = rb->_mass;
|
||||
// According to jolt documentation, Mesh shapes should only be static.
|
||||
if (mass > 0.0f && rb->GetShape()->GetType() != MESH)
|
||||
{
|
||||
motionType = JPH::EMotionType::Dynamic;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Nuake
|
||||
{
|
||||
enum RigidbodyShapes
|
||||
{
|
||||
BOX, SPHERE, CAPSULE, MESH, CYLINDER
|
||||
BOX, SPHERE, CAPSULE, MESH, CYLINDER, CONVEX_HULL
|
||||
};
|
||||
|
||||
class PhysicShape
|
||||
@@ -92,6 +92,23 @@ namespace Nuake
|
||||
void SetMesh(Ref<Mesh> mesh) { m_Mesh = mesh; }
|
||||
Ref<Mesh> GetMesh() { return m_Mesh; }
|
||||
};
|
||||
}
|
||||
|
||||
class ConvexHullShape : public PhysicShape
|
||||
{
|
||||
private:
|
||||
std::vector<Vector3> _points;
|
||||
|
||||
public:
|
||||
ConvexHullShape(const std::vector<Vector3>& points) : _points(points)
|
||||
{
|
||||
m_Type = CONVEX_HULL;
|
||||
}
|
||||
|
||||
std::vector<Vector3> GetPoints() const { return _points; }
|
||||
void SetPoints(const std::vector<Vector3>& points)
|
||||
{
|
||||
_points = points;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user