示例#1
0
        public static Mat3 FromQuaternion(Quat quaternion)
        {
            var   squared     = new Vec4(quaternion.x * quaternion.x, quaternion.y * quaternion.y, quaternion.z * quaternion.z, quaternion.w * quaternion.w);
            float invSqLength = 1 / (squared.x + squared.y + squared.z + squared.w);

            float temp1 = quaternion.x * quaternion.y;
            float temp2 = quaternion.z * quaternion.w;
            float temp3 = quaternion.x * quaternion.z;
            float temp4 = quaternion.y * quaternion.w;
            float temp5 = quaternion.y * quaternion.z;
            float temp6 = quaternion.x * quaternion.w;

            return(new Mat3
                   (
                       new Vec3((squared.x - squared.y - squared.z + squared.w) * invSqLength, 2 * (temp1 - temp2) * invSqLength, 2 * (temp3 + temp4) * invSqLength),
                       new Vec3(2 * (temp1 + temp2) * invSqLength, (-squared.x + squared.y - squared.z + squared.w) * invSqLength, 2 * (temp5 - temp6) * invSqLength),
                       new Vec3(2 * (temp3 - temp4) * invSqLength, 2 * (temp5 + temp6) * invSqLength, (-squared.x - squared.y + squared.z + squared.w) * invSqLength)
                   ));
        }
示例#2
0
 public bool ApproxEquals(Vec4 vector, float tolerance)
 {
     return(Distance(vector) <= tolerance);
 }
示例#3
0
 public float Dot(Vec4 vector)
 {
     return((x * vector.x) + (y * vector.y) + (z * vector.z) + (w * vector.w));
 }
示例#4
0
 public float DistanceSquared(Vec4 vector)
 {
     return((vector - this).Dot());
 }
示例#5
0
 public float Distance(Vec4 vector)
 {
     return((vector - this).Length());
 }
示例#6
0
 public Vec4 Min(Vec4 values)
 {
     return(new Vec4(Math.Min(x, values.x), Math.Min(y, values.y), Math.Min(z, values.z), Math.Min(w, values.w)));
 }
示例#7
0
 public Vec4 Max(Vec4 values)
 {
     return(new Vec4(Math.Max(x, values.x), Math.Max(y, values.y), Math.Max(z, values.z), Math.Max(w, values.w)));
 }