Exemplo n.º 1
0
 public void ScaleDifferentials(float s)
 {
     this.rxOrigin = o + (rxOrigin - o) * s;
     this.ryOrigin = o + (ryOrigin - o) * s;
     this.rxDirection = d + (rxDirection - d) * s;
     this.ryDirection = d + (ryDirection - d) * s;
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Vector v = new Vector(1,2,3);
            Vector v2 = 5.0f * v;
            Vector v3 = v * 5.0f;

            Vector v4 = v3 / 5.0f;
            int x = 0;
            int y = 1;
            Utility.Swap<int>(ref x, ref y);

            Vector v5 = -v2;
            Point p =new Point(1,2,3);
            Ray r = new Ray(p, v, 0.0f);
            ;
            r.DoSomething();

            int[,] m = new int[4,4];
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    m[i, j] = i * j;
                }
            }
            int[,] n = new int[4, 4];
            Array.Copy(m, n,2);

            Utility.Swap<int>(ref m[0, 0], ref  m[3, 3]);
        }
Exemplo n.º 3
0
 public Ray(Point origin, Vector direction, float start, float end = float.PositiveInfinity, float t = 0.0f, int d = 0)
 {
     this.o = origin;
     this.d = direction;
     this.mint = start;
     this.maxt = end;
     this.time = t;
     this.depth = d;
 }
Exemplo n.º 4
0
 public Ray(Point origin, Vector direction, Ray parent, float start, float end = float.PositiveInfinity)
 {
     this.o = origin;
     this.d = direction;
     this.mint = start;
     this.maxt = end;
     this.time = parent.time;
     this.depth = parent.depth + 1;
 }
Exemplo n.º 5
0
 public static void CoordinateSystem(Vector v1, out Vector v2, out Vector v3)
 {
     if (Math.Abs(v1.x) > Math.Abs(v1.y))
     {
         float invLen = 1.0f / (float)Math.Sqrt(v1.x * v1.x + v1.z * v1.z);
         v2 = new Vector(-v1.z * invLen, 0.0f, v1.x * invLen);
     }
     else
     {
         float invLen = 1.0f / (float)Math.Sqrt(v1.y * v1.y + v1.z * v1.z);
         v2 = new Vector(0.0f, v1.z * invLen, -v1.y * invLen);
     }
     v3 = Cross(v1, v2);
 }
Exemplo n.º 6
0
 public RayDifferential(Point org, Vector dir, Ray parent, float start, float end = float.PositiveInfinity)
     : base(org, dir, start, end, parent.time, parent.depth + 1)
 {
     this.hasDifferentials = false;
 }
Exemplo n.º 7
0
 public static Vector Faceforward(Vector v, Normal n)
 {
     return (Dot(v, n) < 0.0f) ? -v : v;
 }
Exemplo n.º 8
0
 public Quaternion()
 {
     v = new Vector(0.0f, 0.0f, 0.0f); w = 1.0f;
 }
Exemplo n.º 9
0
 public Vector Apply(Vector v)
 {
     float x = v.x, y = v.y, z = v.z;
     return new Vector(m.m[0, 0] * x + m.m[0, 1] * y + m.m[0, 2] * z,
                   m.m[1, 0] * x + m.m[1, 1] * y + m.m[1, 2] * z,
                   m.m[2, 0] * x + m.m[2, 1] * y + m.m[2, 2] * z);
 }
Exemplo n.º 10
0
        public static Transform Rotate(float angle, Vector axis)
        {
            Vector a = Geometry.Geometry.Normalize(axis);
            float s = (float)Math.Sin(Utility.Radians(angle));
            float c = (float)Math.Cos(Utility.Radians(angle));
            float[,] m = new float[4, 4];

            m[0, 0] = a.x * a.x + (1.0f - a.x * a.x) * c;
            m[0, 1] = a.x * a.y * (1.0f - c) - a.z * s;
            m[0, 2] = a.x * a.z * (1.0f - c) + a.y * s;
            m[0, 3] = 0;

            m[1, 0] = a.x * a.y * (1.0f - c) + a.z * s;
            m[1, 1] = a.y * a.y + (1.0f - a.y * a.y) * c;
            m[1, 2] = a.y * a.z * (1.0f - c) - a.x * s;
            m[1, 3] = 0;

            m[2, 0] = a.x * a.z * (1.0f - c) - a.y * s;
            m[2, 1] = a.y * a.z * (1.0f - c) + a.x * s;
            m[2, 2] = a.z * a.z + (1.0f - a.z * a.z) * c;
            m[2, 3] = 0;

            m[3, 0] = 0;
            m[3, 1] = 0;
            m[3, 2] = 0;
            m[3, 3] = 1;

            Matrix4x4 mat = new Matrix4x4(m);
            return new Transform(mat, Transpose(mat));
        }
Exemplo n.º 11
0
 public static float SphericalTheta(Vector v)
 {
     return (float)Math.Acos(Utility.Clamp(v.z, -1.0f, 1.0f));
 }
Exemplo n.º 12
0
 public static float SphericalPhi(Vector v)
 {
     float p = (float)Math.Atan2(v.y, v.x);
     return (float)((p < 0.0f) ? p + 2.0f * Math.PI : p);
 }
Exemplo n.º 13
0
 public static Vector SphericalDirection(float sintheta, float costheta,
                                  float phi, Vector x,
                                    Vector y, Vector z)
 {
     return sintheta * (float)Math.Cos(phi) * x +
            sintheta * (float)Math.Sin(phi) * y + costheta * z;
 }
Exemplo n.º 14
0
 public static float AbsDot(Vector v1, Vector v2)
 {
     if (v1.HasNaNs() || v2.HasNaNs()) throw new InvalidOperationException();
     return Math.Abs(Dot(v1, v2));
 }
Exemplo n.º 15
0
 public static Vector Normalize(Vector v)
 {
     return v / v.Length();
 }
Exemplo n.º 16
0
 public void Expand(float delta)
 {
     pMin -= new Vector(delta, delta, delta);
     pMax += new Vector(delta, delta, delta);
 }
Exemplo n.º 17
0
 public static Vector Cross(Vector v1, Vector v2)
 {
     if (v1.HasNaNs() || v2.HasNaNs()) throw new InvalidOperationException();
     return new Vector((v1.y * v2.z) - (v1.z * v2.y), (v1.z * v2.x) - (v1.x * v2.z), (v1.x * v2.y) - (v1.y * v2.x));
 }
Exemplo n.º 18
0
        public static Transform LookAt(Point pos, Point look, Vector up)
        {
            float[,] m = new float[4, 4];
            // Initialize fourth column of viewing matrix
            m[0, 3] = pos.x;
            m[1, 3] = pos.y;
            m[2, 3] = pos.z;
            m[3, 3] = 1;

            // Initialize first three columns of viewing matrix
            Vector dir = Geometry.Geometry.Normalize(look - pos);
            Vector left = Geometry.Geometry.Normalize(Geometry.Geometry.Cross(Geometry.Geometry.Normalize(up), dir));
            Vector newUp = Geometry.Geometry.Cross(dir, left);
            m[0, 0] = left.x;
            m[1, 0] = left.y;
            m[2, 0] = left.z;
            m[3, 0] = 0.0f;
            m[0, 1] = newUp.x;
            m[1, 1] = newUp.y;
            m[2, 1] = newUp.z;
            m[3, 1] = 0.0f;
            m[0, 2] = dir.x;
            m[1, 2] = dir.y;
            m[2, 2] = dir.z;
            m[3, 2] = 0.0f;
            Matrix4x4 camToWorld = new Matrix4x4(m);
            return new Transform(Inverse(camToWorld), camToWorld);
        }
Exemplo n.º 19
0
 public static float Dot(Vector v1, Vector v2)
 {
     if (v1.HasNaNs() || v2.HasNaNs()) throw new InvalidOperationException();
     return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
 }
Exemplo n.º 20
0
 public static Transform Translate(Vector delta)
 {
     Matrix4x4 m = new Matrix4x4(1, 0, 0, delta.x,
                 0, 1, 0, delta.y,
                 0, 0, 1, delta.z,
                 0, 0, 0, 1);
     Matrix4x4 minv = new Matrix4x4(1, 0, 0, -delta.x,
                    0, 1, 0, -delta.y,
                    0, 0, 1, -delta.z,
                    0, 0, 0, 1);
     return new Transform(m, minv);
 }
Exemplo n.º 21
0
 public static float Dot(Normal n, Vector v)
 {
     if (n.HasNaNs() || v.HasNaNs()) throw new InvalidOperationException();
     return n.x * v.x + n.y * v.y + n.z * v.z;
 }
Exemplo n.º 22
0
 public void Apply(Vector v, ref Vector vt)
 {
     float x = v.x, y = v.y, z = v.z;
     vt.x = m.m[0, 0] * x + m.m[0, 1] * y + m.m[0, 2] * z;
     vt.y = m.m[1, 0] * x + m.m[1, 1] * y + m.m[1, 2] * z;
     vt.z = m.m[2, 0] * x + m.m[2, 1] * y + m.m[2, 2] * z;
 }
Exemplo n.º 23
0
 public static float Dot(Vector v, Normal n)
 {
     if (v.HasNaNs() || n.HasNaNs()) throw new InvalidOperationException();
     return v.x * n.x + v.y * n.y + v.z * n.z;
 }
Exemplo n.º 24
0
 public static Normal Faceforward(Normal n, Vector v)
 {
     return (Dot(n, v) < 0.0f) ? -n : n;
 }
Exemplo n.º 25
0
 public RayDifferential(Point org, Vector dir, float start, float end = float.PositiveInfinity, float t = 0.0f, int d = 0)
     : base(org, dir, start, end, t, d)
 {
     this.hasDifferentials = false;
 }
Exemplo n.º 26
0
 public Quaternion(Vector v, float w)
 {
     this.v = v;
     this.w = w;
 }
Exemplo n.º 27
0
 public static Vector Faceforward(Vector v1, Vector v2)
 {
     return (Dot(v1, v2) < 0.0f) ? -v1 : v1;
 }