示例#1
0
        public NuGenRot3F(NuGenVec3F from, NuGenVec3F to)
        {
            from.Normalize();
            to.Normalize();

            float cost =
                NuGenVec3F.Dot(from, to) /
                (float)Math.Sqrt(NuGenVec3F.Dot(from, to) * NuGenVec3F.Dot(to, to));

            if (cost > 0.99999)
            {
                r = 1;
                v = new NuGenVec3F(0, 0, 0);
            }

            else if (cost < -0.99999)
            {
                NuGenVec3F frm = from.Normalized;
                v = NuGenVec3F.Cross(frm, NuGenVec3F.UnitX);

                if (v.Length < 0.00001)
                {
                    v = NuGenVec3F.Cross(frm, NuGenVec3F.UnitY);
                }
                r = 0;
                v.Normalize();
            }

            else
            {
                r  = (float)Math.Sqrt(0.5 * (1.0 + cost));
                v  = NuGenVec3F.Cross(from, to);
                v *= (float)Math.Sqrt((0.5 * (1.0 - cost)) / NuGenVec3F.Dot(v, v));
            }
        }
示例#2
0
 public static bool ApproxEquals(NuGenVec3F a, NuGenVec3F b)
 {
     return
         (Math.Abs(a._x[0] - b._x[0]) < NuGenVector.TINY_FLOAT &&
          Math.Abs(a._x[1] - b._x[1]) < NuGenVector.TINY_FLOAT &&
          Math.Abs(a._x[2] - b._x[2]) < NuGenVector.TINY_FLOAT);
 }
示例#3
0
 public static NuGenVec3F Max(NuGenVec3F a, NuGenVec3F b)
 {
     return(new NuGenVec3F(
                Math.Max(a._x[0], b._x[0]),
                Math.Max(a._x[1], b._x[1]),
                Math.Max(a._x[2], b._x[2])
                ));
 }
示例#4
0
 public static NuGenVec3F Cross(NuGenVec3F a, NuGenVec3F b)
 {
     return(new NuGenVec3F(
                a.y * b.z - a.z * b.y,
                a.z * b.x - a.x * b.z,
                a.x * b.y - a.y * b.x
                ));
 }
示例#5
0
        public override bool Equals(object obj)
        {
            NuGenVec3F x = (NuGenVec3F)obj;

            return(
                _x[0] == x._x[0] &&
                _x[1] == x._x[1] &&
                _x[2] == x._x[2]
                );
        }
示例#6
0
 public NuGenScale3F(NuGenVec3F shift)
 {
     v = shift;
 }
示例#7
0
 public NuGenScale3F(float x, float y, float z)
 {
     v = new NuGenVec3F(x, y, z);
 }
示例#8
0
 public NuGenRay3F(NuGenPnt3F p, NuGenVec3F v)
 {
     this.p = p;
     this.v = v;
 }
示例#9
0
 public NuGenShift3F(NuGenVec3F shift)
 {
     v = shift;
 }
示例#10
0
 public NuGenShift3F(float x, float y, float z)
 {
     v = new NuGenVec3F(x, y, z);
 }
示例#11
0
 public static float Dot(NuGenVec3F u, NuGenVec3F v)
 {
     return(u[0] * v[0] + u[1] * v[1] + u[2] * v[2]);
 }
示例#12
0
 public NuGenRot3F(float radians, NuGenVec3F axis)
 {
     axis.Normalize();
     r = (float)Math.Cos(radians / 2.0);
     v = axis.Normalized * (float)Math.Sin(radians / 2.0);
 }