Merge branch 'master' into nazara-next

This commit is contained in:
Jérôme Leclercq
2020-09-17 20:28:11 +02:00
270 changed files with 106800 additions and 334 deletions

View File

@@ -71,7 +71,7 @@ namespace Nz
* \brief Closes the socket
*/
void AbstractSocket::Close()
void AbstractSocket::Close() noexcept
{
if (m_handle != SocketImpl::InvalidHandle)
{
@@ -237,7 +237,7 @@ namespace Nz
* \param abstractSocket AbstractSocket to move in this
*/
AbstractSocket& AbstractSocket::operator=(AbstractSocket&& abstractSocket)
AbstractSocket& AbstractSocket::operator=(AbstractSocket&& abstractSocket) noexcept
{
Close();

View File

@@ -695,6 +695,8 @@ namespace Nz
cpBodySetVelocity(to, cpBodyGetVelocity(from));
cpBodySetType(to, cpBodyGetType(from));
to->velocity_func = from->velocity_func;
}
void RigidBody2D::CopyShapeData(cpShape* from, cpShape* to)

View File

@@ -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 **********************************/

View File

@@ -93,11 +93,6 @@ namespace Nz
m_maxStepCount = maxStepCount;
}
void PhysWorld3D::SetSolverModel(unsigned int model)
{
NewtonSetSolverModel(m_world, model);
}
void PhysWorld3D::SetStepSize(float stepSize)
{
m_stepSize = stepSize;
@@ -116,7 +111,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);
@@ -163,17 +159,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)

View File

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

View File

@@ -53,11 +53,11 @@ namespace Ndk
*
* \param geom Geometry used for collisions
*/
void CollisionComponent2D::SetGeom(Nz::Collider2DRef geom)
void CollisionComponent2D::SetGeom(Nz::Collider2DRef geom, bool recomputeMoment, bool recomputeMassCenter)
{
m_geom = std::move(geom);
GetRigidBody()->SetGeom(m_geom);
GetRigidBody()->SetGeom(m_geom, recomputeMoment, recomputeMassCenter);
}
/*!

View File

@@ -77,7 +77,7 @@ namespace Ndk
if (IsComponent<CollisionComponent2D>(component))
{
NazaraAssert(m_object, "Invalid object");
m_object->SetGeom(static_cast<CollisionComponent2D&>(component).GetGeom());
m_object->SetGeom(static_cast<CollisionComponent2D&>(component).GetGeom(), false, false);
}
}
@@ -94,7 +94,7 @@ namespace Ndk
if (IsComponent<CollisionComponent2D>(component))
{
NazaraAssert(m_object, "Invalid object");
m_object->SetGeom(Nz::NullCollider2D::New());
m_object->SetGeom(Nz::NullCollider2D::New(), false, false);
}
}