Package ca.eandb.jmist.framework

Examples of ca.eandb.jmist.framework.Intersection


  /* (non-Javadoc)
   * @see ca.eandb.jmist.framework.RayShader#shadeRay(ca.eandb.jmist.math.Ray3, ca.eandb.jmist.framework.color.WavelengthPacket)
   */
  public Color shadeRay(Ray3 ray, WavelengthPacket lambda) {
    Intersection x = NearestIntersectionRecorder.computeNearestIntersection(ray, root);
    ColorModel cm = lambda.getColorModel();

    return (x != null) ? cm.getGray(x.getDistance(), lambda) : (missValue != null) ? missValue.sample(lambda) : cm.getBlack(lambda);
  }
View Full Code Here


        if (recorder.interval().contains(t[i])) {
          Point3 p = ray.pointAt(t[i]);
          if (MathUtil.inRangeCC(p.y(),
              Math.min(height1, height2),
              Math.max(height1, height2))) {
            Intersection x = super.newIntersection(ray, t[i], i == 0, TAPERED_CYLINDER_SURFACE_BODY)
              .setLocation(p);
            recorder.record(x);
          }
        }
      }
View Full Code Here

        if (u.dot(v) < 0.0) {
          return;
        }
      }

      Intersection x = super.newIntersection(ray, t, ray.direction().dot(n) < 0.0, faceIndex)
        .setLocation(p)
        .setPrimitiveIndex(faceIndex);

      recorder.record(x);
View Full Code Here

   * @see ca.eandb.jmist.framework.geometry.AbstractGeometry#generateRandomSurfacePoint(int, ca.eandb.jmist.framework.ShadingContext)
   */
  @Override
  public void generateRandomSurfacePoint(int index, ShadingContext context, double ru, double rv, double rj) {
    Point3 p = faces.get(index).generateRandomSurfacePoint(ru, rv, rj);
    Intersection x = super.newSurfacePoint(p, index).setPrimitiveIndex(index);
    x.prepareShadingContext(context);
  }
View Full Code Here

    public void intersect(final Ray3 ray, IntersectionRecorder recorder) {
      for (int i = 0; i < vertices.length - 3; i++) {
        final double t = GeometryUtil.rayIntersectTriangle(ray, vertices[i], vertices[i+1], vertices[i+2]);
        final int vertexIndex = i;
        if (!Double.isNaN(t)) {
          recorder.record(new Intersection() {
            public double getDistance() {
              return t;
            }
            public double getTolerance() {
              return MathUtil.SMALL_EPSILON;
View Full Code Here

  /* (non-Javadoc)
   * @see ca.eandb.jmist.framework.SceneElement#visibility(ca.eandb.jmist.math.Ray3)
   */
  public boolean visibility(Ray3 ray) {
    Intersection x = NearestIntersectionRecorder.computeNearestIntersection(ray, this);
    return (x == null);
  }
View Full Code Here

   * @see ca.eandb.jmist.framework.geometry.PrimitiveGeometry#generateRandomSurfacePoint(ca.eandb.jmist.framework.ShadingContext)
   */
  @Override
  public void generateRandomSurfacePoint(ShadingContext context, double ru, double rv, double rj) {
    Point3 p = sphere.center().plus(RandomUtil.uniformOnSphere(sphere.radius(), ru, rv).toCartesian());
    Intersection x = newSurfacePoint(p);
    x.prepareShadingContext(context);
  }
View Full Code Here

    {
      p = ray.pointAt(t);

      if (this.base.squaredDistanceTo(p) < this.radius * this.radius)
      {
        Intersection x = super.newIntersection(ray, t, (ray.direction().y() > 0.0), CYLINDER_SURFACE_BASE)
          .setLocation(p);

        recorder.record(x);
      }
    }

    // check top cap
    t = (this.base.y() + this.height - ray.origin().y()) / ray.direction().y();
    if (I.contains(t))
    {
      p = ray.pointAt(t);

      double r = (p.x() - this.base.x()) * (p.x() - this.base.x()) + (p.z() - this.base.z()) * (p.z() - this.base.z());

      if (r < this.radius * this.radius)
      {
        Intersection x = super.newIntersection(ray, t, (ray.direction().y() < 0.0), CYLINDER_SURFACE_TOP)
          .setLocation(p);

        recorder.record(x);
      }
    }

    // now check for intersection of ray with the body
    Vector3    orig  = this.base.vectorTo(ray.origin());
    Vector3    dir    = ray.direction();

    Polynomial  f    = new Polynomial(
                orig.x() * orig.x() + orig.z() * orig.z() - this.radius * this.radius,
                2.0 * (orig.x() * dir.x() + orig.z() * dir.z()),
                dir.x() * dir.x() + dir.z() * dir.z()
              );
    double[]  x    = f.roots();

    if (x.length == 2)
    {
      // for each solution, make sure the point lies between the base and the apex
      p = ray.pointAt(x[0]);
      if (MathUtil.inRangeOO(p.y(), this.base.y(), this.base.y() + this.height))
      {
        Intersection isect = super.newIntersection(ray, x[0], (x[0] < x[1]), CYLINDER_SURFACE_BODY)
          .setLocation(p);

        recorder.record(isect);
      }

      p = ray.pointAt(x[1]);
      if (MathUtil.inRangeOO(p.y(), this.base.y(), this.base.y() + this.height))
      {
        Intersection isect = super.newIntersection(ray, x[1], (x[0] > x[1]), CYLINDER_SURFACE_BODY)
          .setLocation(p);

        recorder.record(isect);
      }
    }
View Full Code Here

   * @param ray The <code>Ray3</code> to intersect with.
   * @return A value indicating if the ray intersects this
   *     <code>PrimitiveGeometry</code>.
   */
  public boolean visibility(Ray3 ray) {
    Intersection x = NearestIntersectionRecorder
        .computeNearestIntersection(ray, this);
    return (x == null);
  }
View Full Code Here

      double t = Plane3.XZ.intersect(ray);

      if (recorder.interval().contains(t)) {
        Point3 p = ray.pointAt(t);
        if (p.distanceToOrigin() <= radius) {
          Intersection x = super.newIntersection(ray, t, ray.origin().y() < 0.0, CONE_SURFACE_BASE)
            .setLocation(p);
          recorder.record(x);
        }
      }
    }

    Point3 org = ray.origin();
    Vector3 dir = ray.direction();

    double x0 = org.x() / radius;
    double y0 = org.y() / height - 1.0;
    double z0 = org.z() / radius;
    double x1 = dir.x() / radius;
    double y1 = dir.y() / height;
    double z1 = dir.z() / radius;

    Polynomial f = new Polynomial(
        x0 * x0 - y0 * y0 + z0 * z0,
        2.0 * (x0 * x1 - y0 * y1 + z0 * z1),
        x1 * x1 - y1 * y1 + z1 * z1);

    double[] t = f.roots();

    if (t.length == 2) {
      for (int i = 0; i < 2; i++) {
        if (recorder.interval().contains(t[i])) {
          Point3 p = ray.pointAt(t[i]);
          if (0.0 <= p.y() && p.y() <= height) {
            Intersection x = super.newIntersection(ray, t[i], i == 0, CONE_SURFACE_BODY)
              .setLocation(p);
            recorder.record(x);
          }
        }
      }
View Full Code Here

TOP

Related Classes of ca.eandb.jmist.framework.Intersection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.