Physics3D: Fix movement

This commit is contained in:
Jérôme Leclercq
2021-06-20 13:29:58 +02:00
parent 1ac0b2e11a
commit 3ef3580ee7
4 changed files with 59 additions and 28 deletions

View File

@@ -22,9 +22,22 @@ namespace Nz
m_materialIds.emplace("default", NewtonMaterialGetDefaultGroupID(m_world));
}
PhysWorld3D::PhysWorld3D(PhysWorld3D&& physWorld) noexcept :
m_callbacks(std::move(physWorld.m_callbacks)),
m_materialIds(std::move(physWorld.m_materialIds)),
m_maxStepCount(std::move(physWorld.m_maxStepCount)),
m_world(std::move(physWorld.m_world)),
m_gravity(std::move(physWorld.m_gravity)),
m_stepSize(std::move(physWorld.m_stepSize)),
m_timestepAccumulator(std::move(physWorld.m_timestepAccumulator))
{
NewtonWorldSetUserData(m_world, this);
}
PhysWorld3D::~PhysWorld3D()
{
NewtonDestroy(m_world);
if (m_world)
NewtonDestroy(m_world);
}
int PhysWorld3D::CreateMaterial(std::string name)
@@ -159,6 +172,24 @@ namespace Nz
}
}
PhysWorld3D& PhysWorld3D::operator=(PhysWorld3D&& physWorld) noexcept
{
if (m_world)
NewtonDestroy(m_world);
m_callbacks = std::move(physWorld.m_callbacks);
m_materialIds = std::move(physWorld.m_materialIds);
m_maxStepCount = std::move(physWorld.m_maxStepCount);
m_world = std::move(physWorld.m_world);
m_gravity = std::move(physWorld.m_gravity);
m_stepSize = std::move(physWorld.m_stepSize);
m_timestepAccumulator = std::move(physWorld.m_timestepAccumulator);
NewtonWorldSetUserData(m_world, this);
return *this;
}
int PhysWorld3D::OnAABBOverlap(const NewtonJoint* const contactJoint, float /*timestep*/, int /*threadIndex*/)
{
RigidBody3D* bodyA = static_cast<RigidBody3D*>(NewtonBodyGetUserData(NewtonJointGetBody0(contactJoint)));

View File

@@ -61,17 +61,17 @@ namespace Nz
SetRotation(object.GetRotation());
}
RigidBody3D::RigidBody3D(RigidBody3D&& object) :
RigidBody3D::RigidBody3D(RigidBody3D&& object) noexcept :
m_geom(std::move(object.m_geom)),
m_matrix(std::move(object.m_matrix)),
m_forceAccumulator(std::move(object.m_forceAccumulator)),
m_torqueAccumulator(std::move(object.m_torqueAccumulator)),
m_body(object.m_body),
m_body(std::move(object.m_body)),
m_world(object.m_world),
m_gravityFactor(object.m_gravityFactor),
m_mass(object.m_mass)
{
object.m_body = nullptr;
NewtonBodySetUserData(m_body, this);
}
RigidBody3D::~RigidBody3D()
@@ -380,6 +380,24 @@ namespace Nz
return operator=(std::move(physObj));
}
RigidBody3D& RigidBody3D::operator=(RigidBody3D&& object) noexcept
{
if (m_body)
NewtonDestroyBody(m_body);
m_body = std::move(object.m_body);
m_forceAccumulator = std::move(object.m_forceAccumulator);
m_geom = std::move(object.m_geom);
m_gravityFactor = object.m_gravityFactor;
m_mass = object.m_mass;
m_matrix = std::move(object.m_matrix);
m_torqueAccumulator = std::move(object.m_torqueAccumulator);
m_world = object.m_world;
NewtonBodySetUserData(m_body, this);
return *this;
}
void RigidBody3D::UpdateBody()
{
NewtonBodySetMatrix(m_body, m_matrix);
@@ -401,25 +419,6 @@ namespace Nz
}
}
RigidBody3D& RigidBody3D::operator=(RigidBody3D&& object)
{
if (m_body)
NewtonDestroyBody(m_body);
m_body = object.m_body;
m_forceAccumulator = std::move(object.m_forceAccumulator);
m_geom = std::move(object.m_geom);
m_gravityFactor = object.m_gravityFactor;
m_mass = object.m_mass;
m_matrix = std::move(object.m_matrix);
m_torqueAccumulator = std::move(object.m_torqueAccumulator);
m_world = object.m_world;
object.m_body = nullptr;
return *this;
}
void RigidBody3D::ForceAndTorqueCallback(const NewtonBody* body, float timeStep, int threadIndex)
{
NazaraUnused(timeStep);