Beispiel #1
0
 /**
  * Copy the specified vertex into this one.
  *
  * @param v vertex to be copied.
  */
 public void set(Vertex v)
 {
     p.set(v.p);
     n.set(v.n);
     tex.X = v.tex.X;
     tex.Y = v.tex.Y;
 }
        /**
         * Gets the extents vector for the box. This vector is computed as (max - min). Its coordinates are always positive
         * and represent the dimensions of the box along the three axes.
         *
         * @return a refreence to the extent vector
         * @see org.sunflow.math.Vector3#length()
         */
        public Vector3D getExtents()
        {
            extents.set(maximum);
            extents.sub(minimum);

            return(extents);
        }
        /**
         * Gets the center of the box, computed as (min + max) / 2.
         *
         * @return a reference to the center of the box
         */
        public Vector3D getCenter()
        {
            center.set(minimum);
            center.add(maximum);
            center.scale(1.0 / 2.0);

            return(center);
        }
        public void recalcMinMax()
        {
            Vector3D halfExtents = extents.scaleNew(1.0 / 2.0);

            minimum.set(center);
            minimum.sub(halfExtents);

            maximum.set(minimum);
            maximum.add(extents);
        }
Beispiel #5
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));
        }
Beispiel #6
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];
                }
            }
        }