From 61ac6da31fbd34e7a0e00c3fbef668e56200f8eb Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Sun, 22 Jul 2018 12:08:03 +0800 Subject: [PATCH] fixed physics (#3003) * fixed rigidbody sycRotation * fixed physics debug draw --- cocos2d/core/physics/CCRigidBody.js | 4 +-- .../physics/platform/CCPhysicsDebugDraw.js | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/physics/CCRigidBody.js b/cocos2d/core/physics/CCRigidBody.js index db023932e0..de78ea7293 100644 --- a/cocos2d/core/physics/CCRigidBody.js +++ b/cocos2d/core/physics/CCRigidBody.js @@ -776,7 +776,7 @@ var RigidBody = cc.Class({ b2body.SetLinearVelocity(temp); } else { - b2body.SetTransform(temp, b2body.GetAngle()); + b2body.SetTransformVec(temp, b2body.GetAngle()); } }, /** @@ -802,7 +802,7 @@ var RigidBody = cc.Class({ b2body.SetAngularVelocity((rotation - b2Rotation)*timeStep); } else { - b2body.SetTransform(b2body.GetPosition(), rotation); + b2body.SetTransformVec(b2body.GetPosition(), rotation); } }, diff --git a/cocos2d/core/physics/platform/CCPhysicsDebugDraw.js b/cocos2d/core/physics/platform/CCPhysicsDebugDraw.js index b35bff845b..19bf79397b 100644 --- a/cocos2d/core/physics/platform/CCPhysicsDebugDraw.js +++ b/cocos2d/core/physics/platform/CCPhysicsDebugDraw.js @@ -27,6 +27,9 @@ const PTM_RATIO = require('../CCPhysicsTypes').PTM_RATIO; let _tmp_vec2 = cc.v2(); +let GREEN_COLOR = cc.Color.GREEN; +let RED_COLOR = cc.Color.RED; + function PhysicsDebugDraw (drawer) { b2.Draw.call(this); this._drawer = drawer; @@ -101,6 +104,34 @@ cc.js.mixin(PhysicsDebugDraw.prototype, { drawer.stroke(); }, + DrawTransform (xf) { + var drawer = this._drawer; + + drawer.strokeColor = RED_COLOR; + + _tmp_vec2.x = _tmp_vec2.y = 0; + b2.Transform.MulXV(xf, _tmp_vec2, _tmp_vec2); + drawer.moveTo(_tmp_vec2.x * PTM_RATIO, _tmp_vec2.y * PTM_RATIO); + + _tmp_vec2.x = 1; _tmp_vec2.y = 0; + b2.Transform.MulXV(xf, _tmp_vec2, _tmp_vec2); + drawer.lineTo(_tmp_vec2.x * PTM_RATIO, _tmp_vec2.y * PTM_RATIO); + + drawer.stroke(); + + drawer.strokeColor = GREEN_COLOR; + + _tmp_vec2.x = _tmp_vec2.y = 0; + b2.Transform.MulXV(xf, _tmp_vec2, _tmp_vec2); + drawer.moveTo(_tmp_vec2.x * PTM_RATIO, _tmp_vec2.y * PTM_RATIO); + + _tmp_vec2.x = 0; _tmp_vec2.y = 1; + b2.Transform.MulXV(xf, _tmp_vec2, _tmp_vec2); + drawer.lineTo(_tmp_vec2.x * PTM_RATIO, _tmp_vec2.y * PTM_RATIO); + + drawer.stroke(); + }, + DrawPoint (center, radius, color) { },