mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
fixed physics (#3003)
* fixed rigidbody sycRotation * fixed physics debug draw
This commit is contained in:
@@ -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) {
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user