Merge pull request #1833 from vlidholt/master
Improves physics debug drawing
This commit is contained in:
@@ -53,6 +53,7 @@ class TestBed extends NodeWithSize {
|
|||||||
|
|
||||||
TestBed() : super(new Size(1024.0, 1024.0)) {
|
TestBed() : super(new Size(1024.0, 1024.0)) {
|
||||||
_world = new PhysicsWorld(new Offset(0.0, 100.0));
|
_world = new PhysicsWorld(new Offset(0.0, 100.0));
|
||||||
|
_world.drawDebug = true;
|
||||||
_group = new PhysicsGroup();
|
_group = new PhysicsGroup();
|
||||||
_group2 = new PhysicsGroup();
|
_group2 = new PhysicsGroup();
|
||||||
_group2.position = new Point(50.0, 50.0);
|
_group2.position = new Point(50.0, 50.0);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class _PhysicsCollisionGroups {
|
|||||||
List<Object> getKeysForBitmask(int bitmask) {
|
List<Object> getKeysForBitmask(int bitmask) {
|
||||||
List<Object> keys = [];
|
List<Object> keys = [];
|
||||||
keyLookup.forEach((Object key, int value) {
|
keyLookup.forEach((Object key, int value) {
|
||||||
if (value & bitmask != null) {
|
if (value & bitmask != 0) {
|
||||||
keys.add(key);
|
keys.add(key);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ class PhysicsWorld extends Node {
|
|||||||
|
|
||||||
List<PhysicsBody> _bodiesScheduledForUpdate = <PhysicsBody>[];
|
List<PhysicsBody> _bodiesScheduledForUpdate = <PhysicsBody>[];
|
||||||
|
|
||||||
|
bool drawDebug = false;
|
||||||
|
|
||||||
|
Matrix4 _debugDrawTransform ;
|
||||||
|
|
||||||
_PhysicsDebugDraw _debugDraw;
|
_PhysicsDebugDraw _debugDraw;
|
||||||
|
|
||||||
double b2WorldToNodeConversionFactor = 10.0;
|
double b2WorldToNodeConversionFactor = 10.0;
|
||||||
@@ -228,8 +232,10 @@ class PhysicsWorld extends Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void paint(PaintingCanvas canvas) {
|
void paint(PaintingCanvas canvas) {
|
||||||
|
if (drawDebug) {
|
||||||
|
_debugDrawTransform = new Matrix4.fromFloat64List(canvas.getTotalMatrix());
|
||||||
|
}
|
||||||
super.paint(canvas);
|
super.paint(canvas);
|
||||||
paintDebug(canvas);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void paintDebug(PaintingCanvas canvas) {
|
void paintDebug(PaintingCanvas canvas) {
|
||||||
|
|||||||
@@ -347,6 +347,14 @@ class SpriteBox extends RenderBox {
|
|||||||
Matrix4 totalMatrix = new Matrix4.fromFloat64List(canvas.getTotalMatrix());
|
Matrix4 totalMatrix = new Matrix4.fromFloat64List(canvas.getTotalMatrix());
|
||||||
_rootNode._visit(canvas, totalMatrix);
|
_rootNode._visit(canvas, totalMatrix);
|
||||||
|
|
||||||
|
// Draw physics debug
|
||||||
|
for (PhysicsWorld world in _physicsNodes) {
|
||||||
|
if (world.drawDebug) {
|
||||||
|
canvas.setMatrix(world._debugDrawTransform.storage);
|
||||||
|
world.paintDebug(canvas);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user