Exemplo n.º 1
0
        public static OrthoNormalBasis makeFromW(Vector3 w)
        {
            OrthoNormalBasis onb = new OrthoNormalBasis();

            w.normalize(onb.w);
            if ((Math.Abs(onb.w.x) < Math.Abs(onb.w.y)) && (Math.Abs(onb.w.x) < Math.Abs(onb.w.z)))
            {
                onb.v.x = 0;
                onb.v.y = onb.w.z;
                onb.v.z = -onb.w.y;
            }
            else if (Math.Abs(onb.w.y) < Math.Abs(onb.w.z))
            {
                onb.v.x = onb.w.z;
                onb.v.y = 0;
                onb.v.z = -onb.w.x;
            }
            else
            {
                onb.v.x = onb.w.y;
                onb.v.y = -onb.w.x;
                onb.v.z = 0;
            }
            Vector3.cross(onb.v.normalize(), onb.w, onb.u);
            return(onb);
        }
Exemplo n.º 2
0
 public static OrthoNormalBasis makeFromW(Vector3 w)
 {
     OrthoNormalBasis onb = new OrthoNormalBasis();
     w.normalize(onb.w);
     if ((Math.Abs(onb.w.x) < Math.Abs(onb.w.y)) && (Math.Abs(onb.w.x) < Math.Abs(onb.w.z)))
     {
         onb.v.x = 0;
         onb.v.y = onb.w.z;
         onb.v.z = -onb.w.y;
     }
     else if (Math.Abs(onb.w.y) < Math.Abs(onb.w.z))
     {
         onb.v.x = onb.w.z;
         onb.v.y = 0;
         onb.v.z = -onb.w.x;
     }
     else
     {
         onb.v.x = onb.w.y;
         onb.v.y = -onb.w.x;
         onb.v.z = 0;
     }
     Vector3.cross(onb.v.normalize(), onb.w, onb.u);
     return onb;
 }
Exemplo n.º 3
0
 public static OrthoNormalBasis makeFromWV(Vector3 w, Vector3 v)
 {
     OrthoNormalBasis onb = new OrthoNormalBasis();
     w.normalize(onb.w);
     Vector3.cross(v, onb.w, onb.u).normalize();
     Vector3.cross(onb.w, onb.u, onb.v);
     return onb;
 }
Exemplo n.º 4
0
 public SunSkyLight()
 {
     numSkySamples = 64;
     sunDirWorld = new Vector3(1, 1, 1);
     turbidity = 6;
     basis = OrthoNormalBasis.makeFromWV(new Vector3(0, 0, 1), new Vector3(0, 1, 0));
     initSunSky();
 }
Exemplo n.º 5
0
        public static OrthoNormalBasis makeFromWV(Vector3 w, Vector3 v)
        {
            OrthoNormalBasis onb = new OrthoNormalBasis();

            w.normalize(onb.w);
            Vector3.cross(v, onb.w, onb.u).normalize();
            Vector3.cross(onb.w, onb.u, onb.v);
            return(onb);
        }
Exemplo n.º 6
0
 public DirectionalSpotlight()
 {
     src = new Point3(0, 0, 0);
     dir = new Vector3(0, 0, -1);
     dir.normalize();
     basis = OrthoNormalBasis.makeFromW(dir);
     r = 1;
     r2 = r * r;
     radiance = Color.WHITE;
 }
Exemplo n.º 7
0
 public SunSkyLight()
 {
     numSkySamples = 64;
     sunDirWorld = new Vector3(1, 1, 1);
     turbidity = 6;
     basis = OrthoNormalBasis.makeFromWV(new Vector3(0, 0, 1), new Vector3(0, 1, 0));
     groundExtendSky = false;
     groundColor = Color.BLACK;
     initSunSky();
 }
Exemplo n.º 8
0
 public Vector3 getBump(float x, float y, OrthoNormalBasis basis, float scale)
 {
     Bitmap bitmap = getBitmap();
     if (bitmap == null)
         return basis.transform(new Vector3(0, 0, 1));
     float dx = 1.0f / (bitmap.Width - 1);
     float dy = 1.0f / (bitmap.Height - 1);
     float b0 = getPixel(x, y).getLuminance();
     float bx = getPixel(x + dx, y).getLuminance();
     float by = getPixel(x, y + dy).getLuminance();
     return basis.transform(new Vector3(scale * (bx - b0) / dx, scale * (by - b0) / dy, 1)).normalize();
 }
Exemplo n.º 9
0
        /**
         * Creates a rotation matrix from an OrthonormalBasis.
         *
         * @param basis
         */
        public static Matrix4 fromBasis(OrthoNormalBasis basis)
        {
            Matrix4 m = new Matrix4();
            Vector3 u = basis.transform(new Vector3(1, 0, 0));
            Vector3 v = basis.transform(new Vector3(0, 1, 0));
            Vector3 w = basis.transform(new Vector3(0, 0, 1));

            m.m00 = u.x;
            m.m01 = v.x;
            m.m02 = w.x;
            m.m10 = u.y;
            m.m11 = v.y;
            m.m12 = w.y;
            m.m20 = u.z;
            m.m21 = v.z;
            m.m22 = w.z;
            return(m);
        }
Exemplo n.º 10
0
 private void updateBasis(Vector3 center, Vector3 up)
 {
     if (center != null && up != null)
     {
         basis = OrthoNormalBasis.makeFromWV(center, up);
         basis.swapWU();
         basis.flipV();
     }
 }
Exemplo n.º 11
0
 public bool update(ParameterList pl, SunflowAPI api)
 {
     src = pl.getPoint("source", src);
     dir = pl.getVector("dir", dir);
     dir.normalize();
     r = pl.getFloat("radius", r);
     basis = OrthoNormalBasis.makeFromW(dir);
     r2 = r * r;
     radiance = pl.getColor("radiance", radiance);
     return true;
 }
Exemplo n.º 12
0
 public bool update(ParameterList pl, SunflowAPI api)
 {
     Vector3 up = pl.getVector("up", null);
     Vector3 east = pl.getVector("east", null);
     if (up != null && east != null)
         basis = OrthoNormalBasis.makeFromWV(up, east);
     else if (up != null)
         basis = OrthoNormalBasis.makeFromW(up);
     numSkySamples = pl.getInt("samples", numSkySamples);
     sunDirWorld = pl.getVector("sundir", sunDirWorld);
     turbidity = pl.getFloat("turbidity", turbidity);
     // recompute model
     initSunSky();
     return true;
 }
Exemplo n.º 13
0
 private float brdf(Vector3 i, Vector3 o, OrthoNormalBasis basis)
 {
     float fr = 4 * (float)Math.PI * alphaX * alphaY;
     fr *= (float)Math.Sqrt(basis.untransformZ(i) * basis.untransformZ(o));
     Vector3 h = Vector3.add(i, o, new Vector3());
     basis.untransform(h);
     float hx = h.x / alphaX;
     hx *= hx;
     float hy = h.y / alphaY;
     hy *= hy;
     float hn = h.z * h.z;
     fr = (float)Math.Exp(-(hx + hy) / hn) / fr;
     return fr;
 }
Exemplo n.º 14
0
 public Vector3 getNormal(float x, float y, OrthoNormalBasis basis)
 {
     float[] rgb = getPixel(x, y).getRGB();
     return basis.transform(new Vector3(2 * rgb[0] - 1, 2 * rgb[1] - 1, 2 * rgb[2] - 1)).normalize();
 }
Exemplo n.º 15
0
        /**
         * Creates a camera positioning matrix from the given eye and target points
         * and up vector.
         *
         * @param eye location of the eye
         * @param target location of the target
         * @param up vector pointing upwards
         * @return
         */
        public static Matrix4 lookAt(Point3 eye, Point3 target, Vector3 up)
        {
            Matrix4 m = Matrix4.fromBasis(OrthoNormalBasis.makeFromWV(Point3.sub(eye, target, new Vector3()), up));

            return(Matrix4.translation(eye.x, eye.y, eye.z).multiply(m));
        }
Exemplo n.º 16
0
 /**
  * Creates a rotation matrix from an OrthonormalBasis.
  *
  * @param basis
  */
 public static Matrix4 fromBasis(OrthoNormalBasis basis)
 {
     Matrix4 m = new Matrix4();
     Vector3 u = basis.transform(new Vector3(1, 0, 0));
     Vector3 v = basis.transform(new Vector3(0, 1, 0));
     Vector3 w = basis.transform(new Vector3(0, 0, 1));
     m.m00 = u.x;
     m.m01 = v.x;
     m.m02 = w.x;
     m.m10 = u.y;
     m.m11 = v.y;
     m.m12 = w.y;
     m.m20 = u.z;
     m.m21 = v.z;
     m.m22 = w.z;
     m.m33 = 1;
     return m;
 }