Example #1
0
        /**
         * Generate a ray passing though the specified point on the image plane.
         * Additional random variables are provided for the lens to optionally
         * compute depth-of-field or motion blur effects. Note that the camera may
         * return <code>null</code> for invalid arguments or for pixels which
         * don't project to anything.
         *
         * @param x x pixel coordinate
         * @param y y pixel coordinate
         * @param imageWidth width of the image in pixels
         * @param imageHeight height of the image in pixels
         * @param lensX a random variable in [0,1) to be used for DOF sampling
         * @param lensY a random variable in [0,1) to be used for DOF sampling
         * @param time a random variable in [0,1) to be used for motion blur
         *            sampling
         * @return a ray passing through the specified pixel, or <code>null</code>
         */
        public Ray getRay(float x, float y, int imageWidth, int imageHeight, double lensX, double lensY, float time)
        {
            Ray r = lens.getRay(x, y, imageWidth, imageHeight, lensX, lensY, time);

            if (r != null)
            {
                // transform from camera space to world space
                r = r.transform(c2w.sample((float)time));
                // renormalize to account for scale factors embeded in the transform
                r.normalize();
            }
            return(r);
        }
Example #2
0
        /**
         * Generate a ray passing though the specified point on the image plane.
         * Additional random variables are provided for the lens to optionally
         * compute depth-of-field or motion blur effects. Note that the camera may
         * return <code>null</code> for invalid arguments or for pixels which
         * don't project to anything.
         *
         * @param x x pixel coordinate
         * @param y y pixel coordinate
         * @param imageWidth width of the image in pixels
         * @param imageHeight height of the image in pixels
         * @param lensX a random variable in [0,1) to be used for DOF sampling
         * @param lensY a random variable in [0,1) to be used for DOF sampling
         * @param time a random variable in [0,1) to be used for motion blur
         *            sampling
         * @return a ray passing through the specified pixel, or <code>null</code>
         */
        public Ray getRay(float x, float y, int imageWidth, int imageHeight, double lensX, double lensY, double time)
        {
            Ray r = lens.getRay(x, y, imageWidth, imageHeight, lensX, lensY, time);

            if (r != null)
            {
                if (c2w.Length == 1)
                {
                    // regular sampling
                    r = r.transform(c2w[0]);
                }
                else
                {
                    // motion blur
                    double nt   = time * (c2w.Length - 1);
                    int    idx0 = (int)nt;
                    int    idx1 = Math.Min(idx0 + 1, c2w.Length - 1);
                    r = r.transform(Matrix4.blend(c2w[idx0], c2w[idx1], (float)(nt - idx0)));
                }
                // renormalize to account for scale factors embeded in the transform
                r.normalize();
            }
            return(r);
        }