ChipmunkPhysics2D: Fix kinematic body handling
This commit is contained in:
parent
0d3a9547fc
commit
9da6e2ef8c
|
|
@ -296,11 +296,17 @@ namespace Nz
|
||||||
cpFloat mass = cpBodyGetMass(m_handle);
|
cpFloat mass = cpBodyGetMass(m_handle);
|
||||||
cpFloat moment = cpBodyGetMoment(m_handle);
|
cpFloat moment = cpBodyGetMoment(m_handle);
|
||||||
|
|
||||||
cpBody* newHandle = cpBodyNew(static_cast<float>(mass), static_cast<float>(moment));
|
cpBody* newHandle = cpBodyNew(1.f, 0.f);
|
||||||
cpBodySetUserData(newHandle, this);
|
cpBodySetUserData(newHandle, this);
|
||||||
|
|
||||||
CopyBodyData(m_handle, newHandle);
|
CopyBodyData(m_handle, newHandle);
|
||||||
|
|
||||||
|
if (cpBodyGetType(m_handle) == CP_BODY_TYPE_DYNAMIC)
|
||||||
|
{
|
||||||
|
cpBodySetMass(m_handle, mass);
|
||||||
|
cpBodySetMoment(m_handle, moment);
|
||||||
|
}
|
||||||
|
|
||||||
DestroyBody();
|
DestroyBody();
|
||||||
|
|
||||||
m_handle = newHandle;
|
m_handle = newHandle;
|
||||||
|
|
@ -575,10 +581,8 @@ namespace Nz
|
||||||
|
|
||||||
m_bodyIndex = m_world->RegisterBody(*this);
|
m_bodyIndex = m_world->RegisterBody(*this);
|
||||||
|
|
||||||
m_handle = cpBodyNew(m_mass, 0.f); // moment will be recomputed by SetGeom
|
m_handle = (m_mass > 0.f) ? cpBodyNew(m_mass, 0.f) : cpBodyNewKinematic(); // moment will be recomputed by SetGeom
|
||||||
cpBodySetUserData(m_handle, this);
|
cpBodySetUserData(m_handle, this);
|
||||||
if (m_mass <= 0.f)
|
|
||||||
cpBodySetType(m_handle, CP_BODY_TYPE_KINEMATIC);
|
|
||||||
|
|
||||||
SetGeom(settings.geom);
|
SetGeom(settings.geom);
|
||||||
SetAngularVelocity(settings.angularVelocity);
|
SetAngularVelocity(settings.angularVelocity);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue