getTriangle method

void getTriangle(
  1. int xi,
  2. int yi,
  3. bool upper,
  4. Vec3 a,
  5. Vec3 b,
  6. Vec3 c,
)

Get a triangle from the heightfield

Implementation

void getTriangle(int xi, int yi, bool upper, Vec3 a, Vec3 b, Vec3 c) {
  final data = this.data;
  final elementSize = this.elementSize.toDouble();

  if (upper) {
    // Top triangle verts
    a.set((xi + 1) * elementSize, (yi + 1) * elementSize, data[xi + 1][yi + 1]);
    b.set(xi * elementSize, (yi + 1) * elementSize, data[xi][yi + 1]);
    c.set((xi + 1) * elementSize, yi * elementSize, data[xi + 1][yi]);
  } else {
    // Top triangle verts
    a.set(xi * elementSize, yi * elementSize, data[xi][yi]);
    b.set((xi + 1) * elementSize, yi * elementSize, data[xi + 1][yi]);
    c.set(xi * elementSize, (yi + 1) * elementSize, data[xi][yi + 1]);
  }
}