Exemplo n.º 1
0
 public RGBColor(Vector3D source)
 {
     set((float)source.x(), (float)source.y(), (float)source.z());
 }
Exemplo n.º 2
0
        public override RGBColor diffuseColor(Vector3D localPoint)
        {
            int value;

            value = (int)System.Math.Round(localPoint.x() / spacing_) + (int)System.Math.Round(localPoint.y() / spacing_) + (int)System.Math.Round(localPoint.z() / spacing_);

            return(((value & 1) == 0)?diffuseColor():otherDiffuseColor());
        }
Exemplo n.º 3
0
        private void  balanceSegment(Photon[] pbal, Photon[] porg, int index, int start, int end)
        {
            // compute new median
            int median = 1;

            while ((4 * median) <= (end - start + 1))
            {
                median += median;
            }

            if ((3 * median) <= (end - start + 1))
            {
                median += median;
                median += start - 1;
            }
            else
            {
                median = end - median + 1;
            }

            // find axis to split along
            short axis = 2;

            if ((bboxMax.x() - bboxMin.x()) > (bboxMax.y() - bboxMin.y()) && (bboxMax.x() - bboxMin.x()) > (bboxMax.z() - bboxMin.z()))
            {
                axis = 0;
            }
            else if ((bboxMax.y() - bboxMin.y()) > (bboxMax.z() - bboxMin.z()))
            {
                axis = 1;
            }

            // partition photon block around the median

            medianSplit(porg, start, end, median, axis);

            pbal[index]       = porg[median];
            pbal[index].plane = axis;

            // recursively balance the left and right block

            if (median > start)
            {
                // balance left segment
                if (start < (median - 1))
                {
                    double temp = bboxMax.get(axis);

                    bboxMax.set(axis, pbal[index].position.get(axis));
                    balanceSegment(pbal, porg, (2 * index), start, (median - 1));
                    bboxMax.set(axis, temp);
                }
                else
                {
                    pbal[2 * index] = porg[start];
                }
            }

            if (median < end)
            {
                // balance right segment
                if ((median + 1) < end)
                {
                    double temp = bboxMin.get(axis);

                    bboxMin.set(axis, pbal[index].position.get(axis));
                    balanceSegment(pbal, porg, (2 * index) + 1, (median + 1), end);
                    bboxMin.set(axis, temp);
                }
                else
                {
                    pbal[(2 * index) + 1] = porg[end];
                }
            }
        }
Exemplo n.º 4
0
        public override bool intersect(Ray ray, Intersection intersection)
        {
            double   vd;
            double   vx;
            double   vy;
            Vector3D orig = ray.Location.subNew(position());;
            Vector3D dir  = ray.direction();

            /* Check if the ray lies parallel to the plane */
            vd = ng.dot(dir);
            if ((vd > -photontracer.SceneConstants.EPSILON) && (vd < photontracer.SceneConstants.EPSILON))
            {
                return(false);
            }
            /* Check if ray intersects plane */
            double t = -((ng.x() * orig.x()) + (ng.y() * orig.y()) + (ng.z() * orig.z()) + d) / vd;

            if (t < photontracer.SceneConstants.EPSILON)
            {
                return(false);
            }
            /* Check if intersection is inside the triangle */
            switch (dropAxis)
            {
            case 0:
                vx = (orig.y() + (dir.y() * t)) - v0.p.y();
                vy = (orig.z() + (dir.z() * t)) - v0.p.z();
                break;

            case 1:
                vx = (orig.x() + (dir.x() * t)) - v0.p.x();
                vy = (orig.z() + (dir.z() * t)) - v0.p.z();
                break;

            default:
                vx = (orig.x() + (dir.x() * t)) - v0.p.x();
                vy = (orig.y() + (dir.y() * t)) - v0.p.y();
                break;
            }
            double u = (edge2x * vy) - (edge2y * vx);

            if ((u < 0.0) || (u > 1.0))
            {
                return(false);
            }
            double v = (edge1y * vx) - (edge1x * vy);

            if ((v < 0.0) || ((u + v) > 1.0))
            {
                return(false);
            }

            Vector3D intersectionPoint;

            intersectionPoint = ray.direction().scaleNew(t);
            intersectionPoint.add(ray.Location);

            intersection.IntersectionPoint = intersectionPoint;
            intersection.IntersectedObject = this;
            intersection.Lambda            = t;

            return(true);
        }
Exemplo n.º 5
0
 /**
  * Checks to see if the specified {@link org.sunflow.math.Vector3D point} is inside the volume defined by this box. Returns <code>false</code> if the
  * parameter is <code>null</code>.
  *
  * @param p point to be tested for containment
  * @return <code>true</code> if the point is inside the box, <code>false</code> otherwise
  */
 public bool contains(Vector3D p)
 {
     return((p != null) && (p.x() >= minimum.x()) && (p.x() <= maximum.x()) && (p.y() >= minimum.y()) && (p.y() <= maximum.y()) && (p.z() >= minimum.z()) && (p.z() <= maximum.z()));
 }
Exemplo n.º 6
0
 /**
  * Returns <code>true</code> when the box has just been initialized, and is still empty. This method might also
  * return true if the state of the box becomes inconsistent and some component of the minimum corner is larger than
  * the corresponding coordinate of the maximum corner.
  *
  * @return <code>true</code> if the box is empty, <code>false</code> otherwise
  */
 public bool isEmpty()
 {
     return((maximum.x() < minimum.x()) || (maximum.y() < minimum.y()) || (maximum.z() < minimum.z()));
 }
Exemplo n.º 7
0
 public virtual void  surfaceToSpherical(Vector3D direction)
 {
     surfaceTheta = (float)System.Math.Acos(direction.z());
     surfacePhi   = (float)System.Math.Atan2(direction.y(), direction.x());
 }
Exemplo n.º 8
0
 // direction->spherical
 public virtual void  toSpherical(Vector3D direction)
 {
     theta = (float)System.Math.Acos(direction.z());
     phi   = (float)System.Math.Atan2(direction.y(), direction.x());
 }
Exemplo n.º 9
0
        public override Vector3D mapTextureCoordinate(Vector3D localPoint)
        {
            double ang = System.Math.Atan2(localPoint.z(), localPoint.x()) * invPI;

            return(new Vector3D(ang, localPoint.y() * invPI * invRadius(), 0));
        }