Upgrade to Newton 3.14 and make it a thirdparty lib
This commit is contained in:
@@ -259,7 +259,7 @@ namespace Nz
|
||||
|
||||
NewtonCollision* CapsuleCollider3D::CreateHandle(PhysWorld3D* world) const
|
||||
{
|
||||
return NewtonCreateCapsule(world->GetHandle(), m_radius, m_length, 0, m_matrix);
|
||||
return NewtonCreateCapsule(world->GetHandle(), m_radius, m_radius, m_length, 0, m_matrix);
|
||||
}
|
||||
|
||||
/******************************* CompoundCollider3D ********************************/
|
||||
@@ -396,7 +396,7 @@ namespace Nz
|
||||
|
||||
NewtonCollision* CylinderCollider3D::CreateHandle(PhysWorld3D* world) const
|
||||
{
|
||||
return NewtonCreateCylinder(world->GetHandle(), m_radius, m_length, 0, m_matrix);
|
||||
return NewtonCreateCylinder(world->GetHandle(), m_radius, m_radius, m_length, 0, m_matrix);
|
||||
}
|
||||
|
||||
/********************************* NullCollider3D **********************************/
|
||||
|
||||
@@ -91,11 +91,6 @@ namespace Nz
|
||||
m_maxStepCount = maxStepCount;
|
||||
}
|
||||
|
||||
void PhysWorld3D::SetSolverModel(unsigned int model)
|
||||
{
|
||||
NewtonSetSolverModel(m_world, model);
|
||||
}
|
||||
|
||||
void PhysWorld3D::SetStepSize(float stepSize)
|
||||
{
|
||||
m_stepSize = stepSize;
|
||||
@@ -114,7 +109,8 @@ namespace Nz
|
||||
callbackPtr->aabbOverlapCallback = std::move(aabbOverlapCallback);
|
||||
callbackPtr->collisionCallback = std::move(collisionCallback);
|
||||
|
||||
NewtonMaterialSetCollisionCallback(m_world, firstMaterial, secondMaterial, callbackPtr.get(), (callbackPtr->aabbOverlapCallback) ? OnAABBOverlap : nullptr, (callbackPtr->collisionCallback) ? ProcessContact : nullptr);
|
||||
NewtonMaterialSetCollisionCallback(m_world, firstMaterial, secondMaterial, (callbackPtr->aabbOverlapCallback) ? OnAABBOverlap : nullptr, (callbackPtr->collisionCallback) ? ProcessContact : nullptr);
|
||||
NewtonMaterialSetCallbackUserData(m_world, firstMaterial, secondMaterial, callbackPtr.get());
|
||||
|
||||
UInt64 firstMaterialId(firstMaterial);
|
||||
UInt64 secondMaterialId(secondMaterial);
|
||||
@@ -161,17 +157,31 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
int PhysWorld3D::OnAABBOverlap(const NewtonMaterial* const material, const NewtonBody* const body0, const NewtonBody* const body1, int threadIndex)
|
||||
int PhysWorld3D::OnAABBOverlap(const NewtonJoint* const contactJoint, dFloat timestep, int threadIndex)
|
||||
{
|
||||
RigidBody3D* bodyA = static_cast<RigidBody3D*>(NewtonBodyGetUserData(body0));
|
||||
RigidBody3D* bodyB = static_cast<RigidBody3D*>(NewtonBodyGetUserData(body1));
|
||||
RigidBody3D* bodyA = static_cast<RigidBody3D*>(NewtonBodyGetUserData(NewtonJointGetBody0(contactJoint)));
|
||||
RigidBody3D* bodyB = static_cast<RigidBody3D*>(NewtonBodyGetUserData(NewtonJointGetBody1(contactJoint)));
|
||||
assert(bodyA && bodyB);
|
||||
|
||||
Callback* callbackData = static_cast<Callback*>(NewtonMaterialGetMaterialPairUserData(material));
|
||||
assert(callbackData);
|
||||
assert(callbackData->aabbOverlapCallback);
|
||||
using ContactJoint = void*;
|
||||
|
||||
return callbackData->aabbOverlapCallback(*bodyA, *bodyB);
|
||||
// Query all joints first, to prevent removing a joint from the list while iterating on it
|
||||
StackVector<ContactJoint> contacts = NazaraStackVector(ContactJoint, NewtonContactJointGetContactCount(contactJoint));
|
||||
for (ContactJoint contact = NewtonContactJointGetFirstContact(contactJoint); contact; contact = NewtonContactJointGetNextContact(contactJoint, contact))
|
||||
contacts.push_back(contact);
|
||||
|
||||
for (ContactJoint contact : contacts)
|
||||
{
|
||||
NewtonMaterial* material = NewtonContactGetMaterial(contact);
|
||||
Callback* callbackData = static_cast<Callback*>(NewtonMaterialGetMaterialPairUserData(material));
|
||||
assert(callbackData);
|
||||
assert(callbackData->collisionCallback);
|
||||
|
||||
if (!callbackData->collisionCallback(*bodyA, *bodyB))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void PhysWorld3D::ProcessContact(const NewtonJoint* const contactJoint, float timestep, int threadIndex)
|
||||
|
||||
@@ -315,7 +315,7 @@ namespace Nz
|
||||
{
|
||||
// If we already have a mass, we already have an inertial matrix as well, just rescale it
|
||||
float Ix, Iy, Iz;
|
||||
NewtonBodyGetMassMatrix(m_body, &m_mass, &Ix, &Iy, &Iz);
|
||||
NewtonBodyGetMass(m_body, &m_mass, &Ix, &Iy, &Iz);
|
||||
|
||||
float scale = mass / m_mass;
|
||||
NewtonBodySetMassMatrix(m_body, mass, Ix*scale, Iy*scale, Iz*scale);
|
||||
|
||||
Reference in New Issue
Block a user