Merge pull request #7495 from boyu0/physics_flip_bug

Fix the bug: flip scale for physics body make it's size incorrect.
This commit is contained in:
minggo 2014-07-17 17:28:03 +08:00
commit 1f4b516f66
1 changed files with 12 additions and 1 deletions

View File

@ -453,7 +453,7 @@ void PhysicsShapeCircle::update(float delta)
if (_dirty)
{
cpFloat factor = PhysicsHelper::float2cpfloat( _newScaleX / _scaleX );
cpFloat factor = std::abs(PhysicsHelper::float2cpfloat( _newScaleX / _scaleX ));
cpShape* shape = _info->getShapes().front();
cpVect v = cpCircleShapeGetOffset(shape);
@ -710,6 +710,17 @@ void PhysicsShapePolygon::update(float delta)
vects[i].y *= factorY;
}
// convert hole to clockwise
if ( factorX * factorY < 0 )
{
for (int i = 0; i < count / 2; ++i)
{
cpVect v = vects[i];
vects[i] = vects[count - i - 1];
vects[count - i - 1] = v;
}
}
for (int i = 0; i < count; ++i)
{
cpVect n = cpvnormalize(cpvperp(cpvsub(vects[i], vects[(i + 1) % count])));