Ejemplo n.º 1
0
 public static uint4 hashwide(quaternion4 q)
 {
     return((math.asuint(q.x) * math.uint4(0xCF286E83u, 0xE121E6ADu, 0xC9CA1249u, 0x69B60C81u) +
             math.asuint(q.y) * math.uint4(0xE0EB6C25u, 0xF648BEABu, 0x6BDB2B07u, 0xEF63C699u) +
             math.asuint(q.z) * math.uint4(0x9001903Fu, 0xA895B9CDu, 0x9D23B201u, 0x4B01D3E1u) +
             math.asuint(q.w) * math.uint4(0x7461CA0Du, 0x79725379u, 0xD6258E5Bu, 0xEE390C97u)) + 0x9C8A2F05u);
 }
Ejemplo n.º 2
0
 public static uint hash(quaternion4 q)
 {
     return(math.csum(
                math.asuint(q.x) * math.uint4(0xC4B1493Fu, 0xBA0966D3u, 0xAFBEE253u, 0x5B419C01u) +
                math.asuint(q.y) * math.uint4(0x515D90F5u, 0xEC9F68F3u, 0xF9EA92D5u, 0xC2FAFCB9u) +
                math.asuint(q.z) * math.uint4(0x616E9CA1u, 0xC5C5394Bu, 0xCAE78587u, 0x7A1541C9u) +
                math.asuint(q.w) * math.uint4(0xF83BD927u, 0x6A243BCBu, 0x509B84C9u, 0x91D13847u)) + 0x52F7230Fu);
 }
Ejemplo n.º 3
0
        static quaternion4 chgsign(quaternion4 q, float4 sign)
        {
            uint4 sign_bits = math.asuint(sign) & 0x80000000;

            return(quaternion4(
                       math.asfloat(math.asuint(q.x) ^ sign_bits),
                       math.asfloat(math.asuint(q.y) ^ sign_bits),
                       math.asfloat(math.asuint(q.z) ^ sign_bits),
                       math.asfloat(math.asuint(q.w) ^ sign_bits)
                       ));
        }
Ejemplo n.º 4
0
        public static quaternion4 mul(quaternion4 lhs, quaternion4 rhs)
        {
            var a = transpose(float4x4(lhs));
            var b = transpose(float4x4(rhs));

            a.c0 = mul(math.quaternion(a.c0), math.quaternion(b.c0)).value;
            a.c1 = mul(math.quaternion(a.c1), math.quaternion(b.c1)).value;
            a.c2 = mul(math.quaternion(a.c2), math.quaternion(b.c2)).value;
            a.c3 = mul(math.quaternion(a.c3), math.quaternion(b.c3)).value;
            return(quaternion4(transpose(a)));
        }
Ejemplo n.º 5
0
 public static quaternion4 lerp(quaternion4 q1, quaternion4 q2, float4 blend)
 {
     q2 = chgsign(q2, dot(q1, q2));
     return(normalize(
                quaternion4(
                    math.lerp(q1.x, q2.x, blend),
                    math.lerp(q1.y, q2.y, blend),
                    math.lerp(q1.z, q2.z, blend),
                    math.lerp(q1.w, q2.w, blend)
                    )
                ));
 }
Ejemplo n.º 6
0
        static unsafe void InitializeDefaultRotationValues(int index, ref BlobBuilderArray <float> arrayBuilder, List <LocalRotationChannel> rotationChannels)
        {
            if (rotationChannels.Count == 0)
            {
                return;
            }

            // Fill as SOA 4-wide quaternions
            quaternion4 *dataPtr = (quaternion4 *)((float *)arrayBuilder.GetUnsafePtr() + index);
            int          length  = rotationChannels.Count >> 2;

            for (int i = 0; i < length; ++i)
            {
                int idx = i << 2;
                *(dataPtr + i) = mathex.quaternion4(
                    rotationChannels[idx + 0].DefaultValue,
                    rotationChannels[idx + 1].DefaultValue,
                    rotationChannels[idx + 2].DefaultValue,
                    rotationChannels[idx + 3].DefaultValue
                    );
            }

            // Fill remaining rotations
            for (int i = length << 2; i < rotationChannels.Count; ++i)
            {
                int chunkIdx = i >> 2;
                int subIdx   = i & 0x3; // equivalent to % 4;

                quaternion      q  = rotationChannels[i].DefaultValue;
                ref quaternion4 q4 = ref UnsafeUtilityEx.AsRef <quaternion4>(dataPtr + chunkIdx);

                q4.x[subIdx] = q.value.x;
                q4.y[subIdx] = q.value.y;
                q4.z[subIdx] = q.value.z;
                q4.w[subIdx] = q.value.w;
            }
Ejemplo n.º 7
0
 public static quaternion4 conjugate(quaternion4 q)
 {
     return(quaternion4(q.x * -1f, q.y * -1f, q.z * -1f, q.w));
 }
Ejemplo n.º 8
0
 public static quaternion4 quatWeight(quaternion4 q, float4 weight)
 {
     q.x *= weight; q.y *= weight; q.z *= weight;
     return(normalizesafe(q));
 }
Ejemplo n.º 9
0
 public static quaternion4 add(quaternion4 q1, quaternion4 q2) =>
 q1 + chgsign(q2, dot(q1, q2));
Ejemplo n.º 10
0
        public static quaternion4 normalizesafe(quaternion4 q)
        {
            float4 lensq = dot(q, q);

            return(select(Animation.quaternion4.identity, q * math.rsqrt(lensq), lensq > math.FLT_MIN_NORMAL));
        }
Ejemplo n.º 11
0
 public static quaternion4 normalize(quaternion4 q) =>
 q *math.rsqrt(dot(q, q));
Ejemplo n.º 12
0
 public static float4 dot(quaternion4 q1, quaternion4 q2) =>
 q1.x * q2.x + q1.y * q2.y + q1.z * q2.z + q1.w * q2.w;
Ejemplo n.º 13
0
 public static quaternion4 select(quaternion4 a, quaternion4 b, bool4 c)
 {
     return(quaternion4(math.select(a.x, b.x, c), math.select(a.y, b.y, c), math.select(a.z, b.z, c), math.select(a.w, b.w, c)));
 }
Ejemplo n.º 14
0
 public static float4x4 float4x4(quaternion4 q)
 {
     return(new float4x4(q.x, q.y, q.z, q.w));
 }