Esempio n. 1
0
  /**
   * Check for all intersections against this geometry using a line ray and return the exact
   * distance away of the closest picking point.
   *
   * @param origin The start point of the ray
   * @param direction The direction vector of the ray
   * @param findAny True if it only has to find a single intersection and can exit as soon as it
   *     finds the first intersection. False if it must find the closest polygon
   * @param dataOut An array to put the data in for the intersection. Exact format is described by
   *     the flags
   * @param dataOutFlags A set of derived-class specific flags describing what data should be
   *     included in the output array
   * @return True if an intersection was found according to the input request
   * @throws NotPickableException This object has been marked as non pickable, but you decided to
   *     try to call the method anyway
   */
  @Override
  public boolean pickLineRay(
      float[] origin, float[] direction, boolean findAny, float[] dataOut, int dataOutFlags)
      throws NotPickableException {
    // Call the super version to do our basic checking for us. Ignore the
    // return value as we're about to go calculate that ourselves.
    super.pickLineRay(origin, direction, findAny, dataOut, dataOutFlags);

    float shortest_length = Float.POSITIVE_INFINITY;
    float this_length;
    boolean found = false;
    float out_x = 0;
    float out_y = 0;
    float out_z = 0;

    int num_quads = numCoords / 4;
    vertexBuffer.rewind();

    for (int i = 0; i < num_quads; i++) {
      vertexBuffer.get(wkPolygon, 0, 12);

      if (ray3DQuadChecked(origin, direction, 0, dataOut)) {
        found = true;

        if (findAny) break;

        float l_x = origin[0] - dataOut[0];
        float l_y = origin[1] - dataOut[1];
        float l_z = origin[2] - dataOut[2];

        this_length = l_x * l_x + l_y * l_y + l_z * l_z;

        if (this_length < shortest_length) {
          shortest_length = this_length;
          out_x = dataOut[0];
          out_y = dataOut[1];
          out_z = dataOut[2];
        }
      }
    }

    dataOut[0] = out_x;
    dataOut[1] = out_y;
    dataOut[2] = out_z;

    return found;
  }
Esempio n. 2
0
  /**
   * Check for all intersections against this geometry using a line segment and return the exact
   * distance away of the closest picking point.
   *
   * @param start The start point of the segment
   * @param end The end point of the segment
   * @param findAny True if it only has to find a single intersection and can exit as soon as it
   *     finds the first intersection. False if it must find the closest polygon
   * @param dataOut An array to put the data in for the intersection. Exact format is described by
   *     the flags
   * @param dataOutFlags A set of derived-class specific flags describing what data should be
   *     included in the output array
   * @return True if an intersection was found according to the input request
   * @throws NotPickableException This object has been marked as non pickable, but you decided to
   *     try to call the method anyway
   */
  @Override
  public boolean pickLineSegment(
      float[] start, float[] end, boolean findAny, float[] dataOut, int dataOutFlags)
      throws NotPickableException {
    // Call the super version to do our basic checking for us. Ignore the
    // return value as we're about to go calculate that ourselves.
    super.pickLineSegment(start, end, findAny, dataOut, dataOutFlags);

    float shortest_length = Float.POSITIVE_INFINITY;
    float this_length;
    boolean found = false;
    float out_x = 0;
    float out_y = 0;
    float out_z = 0;

    // copy the end var to a local for the time being as we're going to
    // reuse end as a direction vector.
    float end_x = end[0];
    float end_y = end[1];
    float end_z = end[2];

    float x = end[0] - start[0];
    float y = end[1] - start[1];
    float z = end[2] - start[2];

    float vec_len = (float) Math.sqrt(x * x + y * y + z * z);
    end[0] = x;
    end[1] = y;
    end[2] = z;

    int num_quads = numCoords / 4;

    vertexBuffer.rewind();

    for (int i = 0; i < num_quads; i++) {
      vertexBuffer.get(wkPolygon, 0, 12);

      if (ray3DQuadChecked(start, end, vec_len, dataOut)) {
        found = true;

        if (findAny) break;

        float l_x = start[0] - dataOut[0];
        float l_y = start[1] - dataOut[1];
        float l_z = start[2] - dataOut[2];

        this_length = l_x * l_x + l_y * l_y + l_z * l_z;

        if (this_length < shortest_length) {
          shortest_length = this_length;
          out_x = dataOut[0];
          out_y = dataOut[1];
          out_z = dataOut[2];
        }
      }
    }

    dataOut[0] = out_x;
    dataOut[1] = out_y;
    dataOut[2] = out_z;

    // Copy it back again.
    end[0] = end_x;
    end[1] = end_y;
    end[2] = end_z;

    return found;
  }