BulletPhysics3D: Fix movement
This commit is contained in:
parent
6447686ad9
commit
efc81ff508
|
|
@ -49,6 +49,8 @@ namespace Nz
|
|||
template<typename T> const T* GetConstraint() const;
|
||||
|
||||
private:
|
||||
void Destroy();
|
||||
|
||||
std::unique_ptr<btTypedConstraint> m_constraint;
|
||||
bool m_bodyCollisionEnabled;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ namespace Nz
|
|||
m_constraint(std::move(constraint)),
|
||||
m_bodyCollisionEnabled(!disableCollisions)
|
||||
{
|
||||
m_constraint->setUserConstraintPtr(this);
|
||||
|
||||
btDynamicsWorld* world = GetWorld().GetDynamicsWorld();
|
||||
world->addConstraint(m_constraint.get(), disableCollisions);
|
||||
}
|
||||
|
|
@ -28,11 +30,7 @@ namespace Nz
|
|||
|
||||
BulletConstraint3D::~BulletConstraint3D()
|
||||
{
|
||||
if (m_constraint)
|
||||
{
|
||||
btDynamicsWorld* world = GetWorld().GetDynamicsWorld();
|
||||
world->removeConstraint(m_constraint.get());
|
||||
}
|
||||
Destroy();
|
||||
}
|
||||
|
||||
BulletRigidBody3D& BulletConstraint3D::GetBodyA()
|
||||
|
|
@ -74,7 +72,7 @@ namespace Nz
|
|||
|
||||
BulletConstraint3D& BulletConstraint3D::operator=(BulletConstraint3D&& constraint) noexcept
|
||||
{
|
||||
m_constraint.reset();
|
||||
Destroy();
|
||||
|
||||
m_constraint = std::move(constraint.m_constraint);
|
||||
m_bodyCollisionEnabled = constraint.m_bodyCollisionEnabled;
|
||||
|
|
@ -85,6 +83,17 @@ namespace Nz
|
|||
return *this;
|
||||
}
|
||||
|
||||
void BulletConstraint3D::Destroy()
|
||||
{
|
||||
if (m_constraint)
|
||||
{
|
||||
btDynamicsWorld* world = GetWorld().GetDynamicsWorld();
|
||||
world->removeConstraint(m_constraint.get());
|
||||
|
||||
m_constraint.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BulletPivotConstraint3D::BulletPivotConstraint3D(BulletRigidBody3D& first, const Vector3f& pivot) :
|
||||
BulletConstraint3D(std::make_unique<btPoint2PointConstraint>(*first.GetRigidBody(), ToBullet(first.ToLocal(pivot))))
|
||||
|
|
|
|||
Loading…
Reference in New Issue