addSphere method

void addSphere(
  1. Vector3 centre,
  2. double radius,
  3. Vector4 color, {
  4. int segments = 24,
})

A wire sphere as three orthogonal rings.

Implementation

void addSphere(
  Vector3 centre,
  double radius,
  Vector4 color, {
  int segments = 24,
}) {
  if (radius <= 0.0 || segments < 3) return;
  final step = (2 * math.pi) / segments;

  // One ring per coordinate plane: XY, XZ, YZ.
  for (var plane = 0; plane < 3; plane++) {
    var px = 0.0, py = 0.0, pz = 0.0;
    for (var i = 0; i <= segments; i++) {
      final a = i * step;
      final c = math.cos(a) * radius;
      final s = math.sin(a) * radius;
      final x = plane == 2 ? 0.0 : c;
      final y = plane == 0 ? s : (plane == 1 ? 0.0 : c);
      final z = plane == 0 ? 0.0 : s;
      if (i > 0) {
        addLineXyz(
          centre.x + px,
          centre.y + py,
          centre.z + pz,
          centre.x + x,
          centre.y + y,
          centre.z + z,
          color,
        );
      }
      px = x;
      py = y;
      pz = z;
    }
  }
}