Example #1
0
  /**
   * Get the Zone under the specified coordinates.
   *
   * @param x x coordinate of the specified pixel
   * @param y y coordinate of the specified pixel
   * @return If there is a Zone at the specified coordinates, that zone, otherwise null.
   */
  public Zone pick(int x, int y) {
    // clamp x and y
    if (y >= picking_context.height) y = picking_context.height - 1;
    if (x >= picking_context.width) x = picking_context.width - 1;
    if (y < 0) y = 0;
    if (x < 0) x = 0;

    PGL pgl = picking_context.beginPGL();
    int pixel;
    // force fallback until 2.0b10
    if (!SMT.fastPickingEnabled() || pgl == null) {
      // really slow way(max 70 fps on a high end card vs 200+ fps with readPixels), with loadPixels
      // at the end of render()
      pixel = picking_context.pixels[x + y * picking_context.width];
    } else {
      buffer.clear();
      pgl.readPixels(x, picking_context.height - y, 1, 1, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, buffer);
      pixel = buffer.getInt();
    }
    picking_context.endPGL();

    if (zoneMap.containsKey(pixel)) {
      // if mapped it is either a Zone or null (background)
      Zone picked = zoneMap.get(pixel);
      Zone current = picked;
      while (current != null) {
        if (current.stealChildrensTouch) return current;
        current = current.getParent();
      }
      return picked;
    } else return null;
  }
Example #2
0
  protected void drawForPicker(PGraphics3D pickBuffer, MeshSection section) {
    pickBuffer.pushMatrix();
    pickBuffer.translate(pos.x, pos.y, pos.z);
    pickBuffer.rotateX(rot.x);
    pickBuffer.rotateY(rot.y);
    pickBuffer.rotateZ(rot.z);
    pickBuffer.scale(shapeScale);
    pickBuffer.noStroke();

    PVector c;
    for (int p = section.sNS; p < section.eNS - 1; p++) {
      pickBuffer.beginShape(TRIANGLE_STRIP);
      pickBuffer.fill(pickColor);
      for (int t = section.sEW; t < section.eEW; t++) {
        c = coord[t][p];
        pickBuffer.vertex(c.x, c.y, c.z);
        c = coord[t][p + 1];
        pickBuffer.vertex(c.x, c.y, c.z);
      }
      pickBuffer.endShape();
    }

    pickBuffer.popMatrix();
  }