Fixed mesh rigid body shape

This commit is contained in:
antopilo
2023-03-13 22:18:20 -04:00
parent e78edb7052
commit f9364d868f
2 changed files with 23 additions and 8 deletions

View File

@@ -313,24 +313,28 @@ namespace Nuake
JPH::TriangleList triangles;
triangles.reserve(indices.size());
for (int i = 0; i < indices.size(); i += 3)
for (int i = 0; i < indices.size() - 3; i += 3)
{
const Vector3& p1 = vertices[i].position;
const Vector3& p2 = vertices[i + 1].position;
const Vector3& p3 = vertices[i + 2].position;
const Vector3& p1 = vertices[indices[i]].position;
const Vector3& p2 = vertices[indices[i + 1]].position;
const Vector3& p3 = vertices[indices[i + 2]].position;
triangles.push_back(JPH::Triangle(JPH::Float3(p1.x, p1.y, p1.z), JPH::Float3(p2.x, p2.y, p2.z), JPH::Float3(p3.x, p3.y, p3.z)));
}
JPH::MeshShapeSettings shapeSettings(std::move(triangles));
shapeResult = shapeSettings.Create();
}
break;
}
const auto& startPos = rb->GetPosition();
JPH::BodyCreationSettings bodySettings(shapeResult.Get(), JPH::Vec3(startPos.x, startPos.y, startPos.z), JPH::Quat::sIdentity(), JPH::EMotionType::Dynamic, Layers::MOVING);
bodySettings.mUserData = rb->GetEntity().GetID();
bodySettings.mOverrideMassProperties = JPH::EOverrideMassProperties::CalculateInertia;
bodySettings.mMassPropertiesOverride.mMass = 10.0f;
bodySettings.mUserData = rb->GetEntity().GetID();
// Create the actual rigid body
JPH::BodyID floor = _JoltBodyInterface->CreateAndAddBody(bodySettings, JPH::EActivation::Activate); // Note that if we run out of bodies this can return nullptr
_registeredBodies.push_back((uint32_t)floor.GetIndexAndSequenceNumber());

View File

@@ -49,7 +49,12 @@ namespace Nuake
float Radius;
float Height;
public:
Capsule(float radius, float height) : Radius(radius), Height(height) {}
Capsule(float radius, float height) :
Radius(radius),
Height(height)
{
m_Type = CAPSULE;
}
float GetRadius() const { return Radius; }
void SetRadius(float radius) { Radius = radius; }
@@ -63,7 +68,10 @@ namespace Nuake
float Radius;
float Height;
public:
Cylinder(float radius, float height) : Radius(radius), Height(height) {}
Cylinder(float radius, float height) : Radius(radius), Height(height)
{
m_Type = CYLINDER;
}
float GetRadius() const { return Radius; }
void SetRadius(float radius) { Radius = radius; }
@@ -76,7 +84,10 @@ namespace Nuake
private:
Ref<Mesh> m_Mesh;
public:
MeshShape(Ref<Mesh> mesh) : m_Mesh(mesh) {}
MeshShape(Ref<Mesh> mesh) : m_Mesh(mesh)
{
m_Type = MESH;
}
void SetMesh(Ref<Mesh> mesh) { m_Mesh = mesh; }
Ref<Mesh> GetMesh() { return m_Mesh; }