Esempio n. 1
0
 public Vector3D transform(Vector3D a, Vector3D dest)
 {
     dest.X = (a.x() * u.x()) + (a.y() * v.x()) + (a.z() * w.x());
     dest.Y = (a.x() * u.y()) + (a.y() * v.y()) + (a.z() * w.y());
     dest.Z = (a.x() * u.z()) + (a.y() * v.z()) + (a.z() * w.z());
     return(dest);
 }
Esempio n. 2
0
 /**
  * Changes the extents of the box as needed to include the given {@link org.sunflow.math.Vector3D point} into this box.
  * Does nothing if the parameter is <code>null</code>.
  *
  * @param p point to be included
  */
 public void include(Vector3D p)
 {
     if (p != null)
     {
         if (p.x() < minimum.x())
         {
             minimum.X = p.x();
         }
         if (p.x() > maximum.x())
         {
             maximum.X = p.x();
         }
         if (p.y() < minimum.y())
         {
             minimum.Y = p.y();
         }
         if (p.y() > maximum.y())
         {
             maximum.Y = p.y();
         }
         if (p.z() < minimum.z())
         {
             minimum.Z = p.z();
         }
         if (p.z() > maximum.z())
         {
             maximum.Z = p.z();
         }
     }
 }
Esempio n. 3
0
        public Vector3D transform(Vector3D a)
        {
            double x = (a.x() * u.x()) + (a.y() * v.x()) + (a.z() * w.x());
            double y = (a.x() * u.y()) + (a.y() * v.y()) + (a.z() * w.y());
            double z = (a.x() * u.z()) + (a.y() * v.z()) + (a.z() * w.z());

            a.set(x, y, z);

            return(new Vector3D(a));
        }
Esempio n. 4
0
        public Triangle(Vertex v0, Vertex v1, Vertex v2) : base()
        {
            this.v0 = v0;
            this.v1 = v1;
            this.v2 = v2;

            ng = v1.p.subNew(v0.p).cross(v2.p.subNew(v0.p));
            ng.normalize();

            d = -((ng.x() * v0.p.x()) + (ng.y() * v0.p.y()) + (ng.z() * v0.p.z()));
            if (Math.Abs(ng.y()) > Math.Abs(ng.x()))
            {
                dropAxis = (Math.Abs(ng.z()) > Math.Abs(ng.y())) ? 2 : 1;
            }
            else
            {
                dropAxis = (Math.Abs(ng.z()) > Math.Abs(ng.x())) ? 2 : 0;
            }
            switch (dropAxis)
            {
            case 0:
                edge1x = v0.p.y() - v1.p.y();
                edge2x = v0.p.y() - v2.p.y();
                edge1y = v0.p.z() - v1.p.z();
                edge2y = v0.p.z() - v2.p.z();
                break;

            case 1:
                edge1x = v0.p.x() - v1.p.x();
                edge2x = v0.p.x() - v2.p.x();
                edge1y = v0.p.z() - v1.p.z();
                edge2y = v0.p.z() - v2.p.z();
                break;

            default:
                edge1x = v0.p.x() - v1.p.x();
                edge2x = v0.p.x() - v2.p.x();
                edge1y = v0.p.y() - v1.p.y();
                edge2y = v0.p.y() - v2.p.y();
                break;
            }
            double s = 1.0 / ((edge1x * edge2y) - (edge2x * edge1y));

            edge1x *= s;
            edge1y *= s;
            edge2x *= s;
            edge2y *= s;
        }
Esempio n. 5
0
        /**
         * Scales the box up or down in all directions by a the given percentage. The routine only uses the magnitude of
         * the scale factor to avoid inversion of the minimum and maximum.
         *
         * @param s scale factor
         */
        public void scale(double s)
        {
            //Vector3D.mid(minimum, maximum, center);
            //Vector3D.sub(maximum, minimum, extents);
            getCenter();
            getExtents();

            s *= ((s > 0.0) ? 0.5 : (-0.5));

            minimum.X = center.x() - (extents.x() * s);
            minimum.Y = center.y() - (extents.y() * s);
            minimum.Z = center.z() - (extents.z() * s);
            maximum.X = center.x() + (extents.x() * s);
            maximum.Y = center.y() + (extents.y() * s);
            maximum.Z = center.z() + (extents.z() * s);
        }
Esempio n. 6
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());
        }
        public IrradianceCache(double tolerance, double minSpacing, BoundingBox sceneBounds)
        {
            this.tolerance  = tolerance;
            invTolerance    = 1.0 / tolerance;
            this.minSpacing = minSpacing;
            maxSpacing      = 100.0 * minSpacing;
            Vector3D ext = sceneBounds.getExtents();

            root = new Node(sceneBounds.getCenter(), 1.0001 * Math.Max(ext.x(), Math.Max(ext.y(), ext.z())));
        }
Esempio n. 8
0
        public override Vector3D mapTextureCoordinate(Vector3D localPoint)
        {
            double x = localPoint.x();
            double y = localPoint.y();
            double z = localPoint.z();

            double elev = System.Math.Atan2(y, System.Math.Sqrt(x * x + z * z)) * invPI;
            double ang  = System.Math.Atan2(z, x) * invPI;

            return(new Vector3D(ang, elev, 0));
        }
Esempio n. 9
0
        private RGBColor lerpTexel(Vector3D uvcoord)
        {
            RGBColor lerpColor;
            float    u, v;
            int      iu, iv, iu2, iv2;
            float    uv, iuv, uiv, iuiv;
            //float iiu, iiv;
            float fu, fv;
            bool  uWrapped  = false;
            bool  u2Wrapped = false;
            bool  vWrapped  = false;
            bool  v2Wrapped = false;

            u = (float)uvcoord.x() * fTextureWidth;
            v = (float)uvcoord.y() * fTextureHeight;

            iu = (int)u;
            iv = (int)v;

            fu = u - iu;
            fv = v - iv;

            iu2 = correctTexel(iu + 1, ref u2Wrapped, textureWidth);
            iv2 = correctTexel(iv + 1, ref v2Wrapped, textureHeight);
            iu  = correctTexel(iu, ref uWrapped, textureWidth);
            iv  = correctTexel(iv, ref vWrapped, textureHeight);

            if (fu < 0.0f)
            {
                fu += 1.0f;
            }
            if (fv < 0.0f)
            {
                fv += 1.0f;
            }

            uv   = fu * fv;
            iuv  = (1.0f - fu) * fv;
            uiv  = fu * (1 - fv);
            iuiv = (1.0f - fu) * (1.0f - fv);

            lerpColor = getColor((uWrapped | vWrapped), iu, iv).scaleNew(iuiv);
            lerpColor.add(getColor((u2Wrapped | vWrapped), iu2, iv).scaleNew(uiv));
            lerpColor.add(getColor((uWrapped | v2Wrapped), iu, iv2).scaleNew(iuv));
            lerpColor.add(getColor((u2Wrapped | v2Wrapped), iu2, iv2).scaleNew(uv));

            return(lerpColor);
        }
            internal RGBColor getIrradiance(Sample x)
            {
                RGBColor temp = new RGBColor(irr);


                temp.addLerp((float)(x.pi.x() - pi.x()), transGradient[0]);
                temp.addLerp((float)(x.pi.y() - pi.y()), transGradient[1]);
                temp.addLerp((float)(x.pi.z() - pi.z()), transGradient[2]);

                Vector3D cross = ni.cross(x.ni);

                temp.addLerp((float)cross.x(), rotGradient[0]);
                temp.addLerp((float)cross.y(), rotGradient[1]);
                temp.addLerp((float)cross.z(), rotGradient[2]);


                return(temp);
            }
        public void insert(Vector3D p, Vector3D n, double r0, RGBColor irr, RGBColor[] rotGradient, RGBColor[] transGradient, int depth)
        {
            Node node = root;

            //r0 = MathUtils.clamp(r0 * tolerance, minSpacing, maxSpacing) * invTolerance;
            r0 = r0 * tolerance;

            if (r0 > minSpacing)
            {
                //	System.Diagnostics.Trace.WriteLine ("jatak");
            }

            r0 = (r0 < minSpacing) ? minSpacing : r0;
            r0 = (r0 > maxSpacing) ? maxSpacing : r0;

            r0 *= invTolerance;

            if (root.isInside(p))
            {
                while (node.sideLength >= (4.0 * r0 * tolerance))
                {
                    int k = 0;
                    k |= (p.x() > node.center.x()) ? 1 : 0;
                    k |= (p.y() > node.center.y()) ? 2 : 0;
                    k |= (p.z() > node.center.z()) ? 4 : 0;
                    if (node.children[k] == null)
                    {
                        Vector3D c = new Vector3D(node.center);
                        c.X = c.x() + (((k & 1) == 0) ? -node.quadSideLength : node.quadSideLength);
                        c.Y = c.y() + (((k & 2) == 0) ? -node.quadSideLength : node.quadSideLength);
                        c.Z = c.z() + (((k & 4) == 0) ? -node.quadSideLength : node.quadSideLength);
                        //c.X +=
                        //c.Y += ((k & 2) == 0) ? -node.quadSideLength : node.quadSideLength;
                        //c.Z += ((k & 4) == 0) ? -node.quadSideLength : node.quadSideLength;
                        node.children[k] = new Node(c, node.halfSideLength);
                    }
                    node = node.children[k];
                }
            }
            Sample s = new Sample(p, n, r0, irr, rotGradient, transGradient, depth);

            s.next     = node.first;
            node.first = s;
        }
Esempio n. 12
0
 public virtual void  surfaceToSpherical(Vector3D direction)
 {
     surfaceTheta = (float)System.Math.Acos(direction.z());
     surfacePhi   = (float)System.Math.Atan2(direction.y(), direction.x());
 }
Esempio n. 13
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());
 }
Esempio n. 14
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];
                }
            }
        }
Esempio n. 15
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 > -RaytracerPhotonmapping.SceneConstants.EPSILON) && (vd < RaytracerPhotonmapping.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 < RaytracerPhotonmapping.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);
        }
Esempio n. 16
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()));
 }
 internal bool isInside(Vector3D p)
 {
     return((Math.Abs(p.x() - center.x()) < halfSideLength) &&
            (Math.Abs(p.y() - center.y()) < halfSideLength) &&
            (Math.Abs(p.z() - center.z()) < halfSideLength));
 }
Esempio n. 18
0
 public RGBColor(Vector3D source)
 {
     set((float)source.x(), (float)source.y(), (float)source.z());
 }
Esempio n. 19
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()));
 }