Added convex hull collision shape

This commit is contained in:
antopilo
2023-03-14 22:38:04 -04:00
parent 31a4ac5e2e
commit 763a4905d0
2 changed files with 40 additions and 5 deletions

View File

@@ -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;
}

View File

@@ -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;
}
};
}
}