fixed physics (#3003)

* fixed rigidbody sycRotation

* fixed physics debug draw
This commit is contained in:
yinkaile
2018-07-22 12:08:03 +08:00
committed by pandamicro
parent 0a4ede7521
commit 61ac6da31f
2 changed files with 33 additions and 2 deletions
+2 -2
View File
@@ -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);
}
},
@@ -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) {
},