Physics3D/Collider3D: Add ForEachPolygon method
This commit is contained in:
parent
271565d1b9
commit
554fcd6492
|
|
@ -75,6 +75,7 @@ Nazara Engine:
|
||||||
- ⚠️ Renamed Bitset::Read to Bitset::Write
|
- ⚠️ Renamed Bitset::Read to Bitset::Write
|
||||||
- Fixed ENetCompressor class destructor not being virtual
|
- Fixed ENetCompressor class destructor not being virtual
|
||||||
- ⚠️ Added a type tag parameter to Serialize and Unserialize functions, to prevent implicit conversions with overloads
|
- ⚠️ Added a type tag parameter to Serialize and Unserialize functions, to prevent implicit conversions with overloads
|
||||||
|
- Added Collider3D::ForEachPolygon method, allowing construction of a debug mesh based on the physics collider
|
||||||
|
|
||||||
Nazara Development Kit:
|
Nazara Development Kit:
|
||||||
- Added ImageWidget (#139)
|
- Added ImageWidget (#139)
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,8 @@ namespace Nz
|
||||||
virtual void ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const;
|
virtual void ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const;
|
||||||
virtual float ComputeVolume() const;
|
virtual float ComputeVolume() const;
|
||||||
|
|
||||||
|
virtual void ForEachPolygon(const std::function<void(const float* vertices, std::size_t vertexCount)>& callback) const;
|
||||||
|
|
||||||
NewtonCollision* GetHandle(PhysWorld3D* world) const;
|
NewtonCollision* GetHandle(PhysWorld3D* world) const;
|
||||||
virtual ColliderType3D GetType() const = 0;
|
virtual ColliderType3D GetType() const = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
Vector3f min, max;
|
Vector3f min, max;
|
||||||
|
|
||||||
// Si nous n'avons aucune instance, nous en cr<63>ons une temporaire
|
// Check for existing collision handles, and create a temporary one if none is available
|
||||||
if (m_handles.empty())
|
if (m_handles.empty())
|
||||||
{
|
{
|
||||||
PhysWorld3D world;
|
PhysWorld3D world;
|
||||||
|
|
@ -61,7 +61,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
NewtonDestroyCollision(collision);
|
NewtonDestroyCollision(collision);
|
||||||
}
|
}
|
||||||
else // Sinon on utilise une instance au hasard (elles sont toutes identiques de toute fa<66>on)
|
else
|
||||||
NewtonCollisionCalculateAABB(m_handles.begin()->second, offsetMatrix, min, max);
|
NewtonCollisionCalculateAABB(m_handles.begin()->second, offsetMatrix, min, max);
|
||||||
|
|
||||||
return Boxf(scale * min, scale * max);
|
return Boxf(scale * min, scale * max);
|
||||||
|
|
@ -72,7 +72,7 @@ namespace Nz
|
||||||
float inertiaMatrix[3];
|
float inertiaMatrix[3];
|
||||||
float origin[3];
|
float origin[3];
|
||||||
|
|
||||||
// Si nous n'avons aucune instance, nous en cr<63>ons une temporaire
|
// Check for existing collision handles, and create a temporary one if none is available
|
||||||
if (m_handles.empty())
|
if (m_handles.empty())
|
||||||
{
|
{
|
||||||
PhysWorld3D world;
|
PhysWorld3D world;
|
||||||
|
|
@ -83,7 +83,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
NewtonDestroyCollision(collision);
|
NewtonDestroyCollision(collision);
|
||||||
}
|
}
|
||||||
else // Sinon on utilise une instance au hasard (elles sont toutes identiques de toute fa<66>on)
|
else
|
||||||
NewtonConvexCollisionCalculateInertialMatrix(m_handles.begin()->second, inertiaMatrix, origin);
|
NewtonConvexCollisionCalculateInertialMatrix(m_handles.begin()->second, inertiaMatrix, origin);
|
||||||
|
|
||||||
if (inertia)
|
if (inertia)
|
||||||
|
|
@ -97,7 +97,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
float volume;
|
float volume;
|
||||||
|
|
||||||
// Si nous n'avons aucune instance, nous en cr<63>ons une temporaire
|
// Check for existing collision handles, and create a temporary one if none is available
|
||||||
if (m_handles.empty())
|
if (m_handles.empty())
|
||||||
{
|
{
|
||||||
PhysWorld3D world;
|
PhysWorld3D world;
|
||||||
|
|
@ -108,12 +108,35 @@ namespace Nz
|
||||||
}
|
}
|
||||||
NewtonDestroyCollision(collision);
|
NewtonDestroyCollision(collision);
|
||||||
}
|
}
|
||||||
else // Sinon on utilise une instance au hasard (elles sont toutes identiques de toute fa<66>on)
|
else
|
||||||
volume = NewtonConvexCollisionCalculateVolume(m_handles.begin()->second);
|
volume = NewtonConvexCollisionCalculateVolume(m_handles.begin()->second);
|
||||||
|
|
||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Collider3D::ForEachPolygon(const std::function<void(const float* vertices, std::size_t vertexCount)>& callback) const
|
||||||
|
{
|
||||||
|
auto newtCallback = [](void* const userData, int vertexCount, const dFloat* const faceArray, int /*faceId*/)
|
||||||
|
{
|
||||||
|
const auto& cb = *static_cast<std::add_pointer_t<decltype(callback)>>(userData);
|
||||||
|
cb(faceArray, vertexCount);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check for existing collision handles, and create a temporary one if none is available
|
||||||
|
if (m_handles.empty())
|
||||||
|
{
|
||||||
|
PhysWorld3D world;
|
||||||
|
|
||||||
|
NewtonCollision* collision = CreateHandle(&world);
|
||||||
|
{
|
||||||
|
NewtonCollisionForEachPolygonDo(collision, Nz::Matrix4f::Identity(), newtCallback, const_cast<void*>(static_cast<const void*>(&callback))); //< This isn't that bad; pointer will not be used for writing
|
||||||
|
}
|
||||||
|
NewtonDestroyCollision(collision);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
NewtonCollisionForEachPolygonDo(m_handles.begin()->second, Nz::Matrix4f::Identity(), newtCallback, const_cast<void*>(static_cast<const void*>(&callback))); //< This isn't that bad; pointer will not be used for writing
|
||||||
|
}
|
||||||
|
|
||||||
NewtonCollision* Collider3D::GetHandle(PhysWorld3D* world) const
|
NewtonCollision* Collider3D::GetHandle(PhysWorld3D* world) const
|
||||||
{
|
{
|
||||||
auto it = m_handles.find(world);
|
auto it = m_handles.find(world);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue