drawDebugData method

void drawDebugData()

Call this to draw shapes and other debug draw data.

Implementation

void drawDebugData() {
  if (debugDraw == null) {
    return;
  }

  final flags = debugDraw!.drawFlags;
  final wireframe = (flags & DebugDraw.wireFrameDrawingBit) != 0;

  if ((flags & DebugDraw.shapeBit) != 0) {
    for (final body in bodies) {
      xf.setFrom(body.transform);
      for (final fixture in body.fixtures) {
        if (!body.isActive) {
          color.setFromRGBd(0.5, 0.5, 0.3);
          fixture.render(debugDraw!, xf, color, wireframe);
        } else if (body.bodyType == BodyType.static) {
          color.setFromRGBd(0.5, 0.9, 0.3);
          fixture.render(debugDraw!, xf, color, wireframe);
        } else if (body.bodyType == BodyType.kinematic) {
          color.setFromRGBd(0.5, 0.5, 0.9);
          fixture.render(debugDraw!, xf, color, wireframe);
        } else if (!body.isAwake) {
          color.setFromRGBd(0.5, 0.5, 0.5);
          fixture.render(debugDraw!, xf, color, wireframe);
        } else {
          color.setFromRGBd(0.9, 0.7, 0.7);
          fixture.render(debugDraw!, xf, color, wireframe);
        }
      }
    }
    particleSystem.render(debugDraw!);
  }

  if ((flags & DebugDraw.jointBit) != 0) {
    joints.forEach((j) => j.render(debugDraw!));
  }

  if ((flags & DebugDraw.pairBit) != 0) {
    color.setFromRGBd(0.3, 0.9, 0.9);
    for (final c in contactManager.contacts) {
      final fixtureA = c.fixtureA;
      final fixtureB = c.fixtureB;
      cA.setFrom(fixtureA.getAABB(c.indexA).center);
      cB.setFrom(fixtureB.getAABB(c.indexB).center);
      debugDraw!.drawSegment(cA, cB, color);
    }
  }

  if ((flags & DebugDraw.aabbBit) != 0) {
    color.setFromRGBd(0.9, 0.3, 0.9);

    for (final b in bodies) {
      if (b.isActive == false) {
        continue;
      }

      for (final f in b.fixtures) {
        for (var i = 0; i < f.proxyCount; ++i) {
          final proxy = f.proxies[i];
          final aabb = contactManager.broadPhase.fatAABB(proxy.proxyId);
          final vs = <Vector2>[
            Vector2(aabb.lowerBound.x, aabb.lowerBound.y),
            Vector2(aabb.upperBound.x, aabb.lowerBound.y),
            Vector2(aabb.upperBound.x, aabb.upperBound.y),
            Vector2(aabb.lowerBound.x, aabb.upperBound.y),
          ];
          debugDraw!.drawPolygon(vs, color);
        }
      }
    }
  }

  if ((flags & DebugDraw.centerOfMassBit) != 0) {
    final xfColor = Color3i(255, 0, 0);
    for (final b in bodies) {
      xf.setFrom(b.transform);
      xf.p.setFrom(b.worldCenter);
      debugDraw!.drawTransform(xf, xfColor);
    }
  }

  if ((flags & DebugDraw.dynamicTreeBit) != 0) {
    contactManager.broadPhase.drawTree(debugDraw!);
  }

  debugDraw!.flush();
}