コード例 #1
0
ファイル: Ray.java プロジェクト: hakurai/kvs4j
  public final boolean isIntersected(final Vector3f v0, final Vector3f v1, final Vector3f v2) {
    final Vector3f v01 = v1.sub(v0);
    final Vector3f v02 = v2.sub(v0);

    final Vector3f pvec = this.direction().cross(v02);

    final float det = v01.dot(pvec);

    if (det > 1e-6f) {
      final Vector3f tvec = this.from().sub(v0);
      final float u = tvec.dot(pvec);
      if (u < 0.0f || u > det) {
        return (false);
      }

      final Vector3f qvec = tvec.cross(v01);
      final float v = this.direction().dot(qvec);
      if (v < 0.0f || u + v > det) {
        return (false);
      }

      final float t = v02.dot(qvec) / det;
      this.setT(t);

      return (true); // hit!!
    }

    return (false);
  }