Beispiel #1
0
 public static void AreEqual(float2x4 a, float2x4 b, int maxUlp, bool signedZeroEqual)
 {
     AreEqual(a.c0, b.c0, maxUlp, signedZeroEqual);
     AreEqual(a.c1, b.c1, maxUlp, signedZeroEqual);
     AreEqual(a.c2, b.c2, maxUlp, signedZeroEqual);
     AreEqual(a.c3, b.c3, maxUlp, signedZeroEqual);
 }
 public static void AreEqual(float2x4 expected, float2x4 actual, int maxUlp, bool signedZeroEqual)
 {
     AreEqual(expected.c0, actual.c0, maxUlp, signedZeroEqual);
     AreEqual(expected.c1, actual.c1, maxUlp, signedZeroEqual);
     AreEqual(expected.c2, actual.c2, maxUlp, signedZeroEqual);
     AreEqual(expected.c3, actual.c3, maxUlp, signedZeroEqual);
 }
Beispiel #3
0
 public static void AreEqual(float2x4 a, float2x4 b, float delta = 0.0f)
 {
     AreEqual(a.c0, b.c0, delta);
     AreEqual(a.c1, b.c1, delta);
     AreEqual(a.c2, b.c2, delta);
     AreEqual(a.c3, b.c3, delta);
 }
Beispiel #4
0
        public void Execute(int startIndex, int count)
        {
            float2 oneEighty = new float2(180f);
            float2 threeSixty = new float2(360f);
            float2 ooThreeSixty = new float2(1f / 360f);

            for (int i = startIndex; i < startIndex + count; ++i)
            {

                //Calculate cost of Trajectory positions
                float2x4 trajectoryDiff = InputTrajectories[i] - DesiredTrajectory;

                float2 trajectoryPointDist = ((trajectoryDiff.c0 * trajectoryDiff.c0) +
                                             (trajectoryDiff.c1 * trajectoryDiff.c1) +
                                             (trajectoryDiff.c2 * trajectoryDiff.c2)) * TrajPosMultiplier;

                float2 localCost = trajectoryPointDist;

                //Calculate cost of trajectory facing angle
                float2 angleDiff = math.clamp(trajectoryDiff.c3 - math.floor(trajectoryDiff.c3 * ooThreeSixty) * threeSixty, float2.zero, threeSixty);
                float2 angleSub = math.select(float2.zero, threeSixty, (angleDiff > oneEighty));

                angleDiff = angleDiff - angleSub;
                localCost += math.abs(angleDiff) * TrajFAngleMultiplier;

                GoalCosts[i] = localCost.x + localCost.y;
            }
        }
 public static void AreEqual(float2x4 expected, float2x4 actual, float delta = 0.0f)
 {
     AreEqual(expected.c0, actual.c0, delta);
     AreEqual(expected.c1, actual.c1, delta);
     AreEqual(expected.c2, actual.c2, delta);
     AreEqual(expected.c3, actual.c3, delta);
 }
Beispiel #6
0
 private static float4 GetNoise(float2x4 point, float4 frequency, float4 amplitude)
 {
     return(cnoise(math.float2x4(
                       math.float2(point.c0.x * frequency.x, point.c0.y * frequency.x),
                       math.float2(point.c1.x * frequency.y, point.c1.y * frequency.y),
                       math.float2(point.c2.x * frequency.z, point.c2.y * frequency.z),
                       math.float2(point.c3.x * frequency.w, point.c3.y * frequency.w)
                       )) * amplitude);
 }
Beispiel #7
0
        private void AdjustHeight(float2x4 bezier)
        {
            var len = newKnotData.Length;

            for (var i = 0; i < len; i++)
            {
                var kd = newKnotData[i];
                kd.Position.y += Bezier.Bezier.GetVectorOnCurve(bezier, (float)i / (len - 1)).y;
                newKnotData[i] = kd;
            }
        }
Beispiel #8
0
    private float2 GetBilerp2(float bu, float bv)
    {
        var p00 = GetPosition2(a);
        var p01 = GetPosition2(b);
        var p10 = GetPosition2(c);
        var p11 = GetPosition2(d);

        var quad = new float2x4(p00, p01, p10, p11);

        return(Bilerp(quad, new float2(bu, bv)));
    }
 private static void CustomVisit(ref float2x4 f)
 {
     LogVisit(f);
     GUILayout.Label(name);
     EditorGUI.indentLevel++;
     f[0] = EditorGUILayout.Vector2Field("", (Vector2)f[0]);
     f[1] = EditorGUILayout.Vector2Field("", (Vector2)f[1]);
     f[2] = EditorGUILayout.Vector2Field("", (Vector2)f[2]);
     f[3] = EditorGUILayout.Vector2Field("", (Vector2)f[3]);
     EditorGUI.indentLevel--;
 }
Beispiel #10
0
    private static float2 Bilerp(float2x4 quad, float2 p)
    {
        // u = p.x
        // v = p.y
        // r = q.x
        // s = q.y
        float2 q = 1 - p;
        float4 f = new float4(q.x * q.y, p.x * q.y, q.x * p.y, p.x * p.y);

        return(math.mul(quad, f));
    }
Beispiel #11
0
        private static float4 NoiseValue(float2x4 point, NoiseSettings config)
        {
            var frequency = math.float4(config.Frequency);
            var amplitude = math.float4(config.Amplitude);
            var range     = 1f * amplitude;
            var value     = GetNoise(point, frequency, amplitude);

            for (var o = 1; o < config.Octaves; o++)
            {
                frequency *= config.Lacunarity;
                amplitude *= config.Persistence;
                range     += amplitude;
                value     += GetNoise(point, frequency, amplitude);
            }

            return(value * (1f / range));
        }
Beispiel #12
0
        public void Execute(int index)
        {
            var modifiers     = UpdatedNewLines[index].Modifiers;
            var startPos      = LineJoinPoints[index].A.Pivot;
            var endPos        = LineJoinPoints[index].B.Pivot;
            var length        = math.distance(startPos, endPos);
            var point1        = new float2(0, modifiers.EndHeights.x);
            var point2        = new float2(length, modifiers.EndHeights.y);
            var controlPoint1 = new float2(length * modifiers.InnerDistances.x,
                                           math.lerp(point1.y, point2.y, modifiers.InnerDistances.x)
                                           + modifiers.InnerHeights.x);
            var controlPoint2 = new float2(length - length * modifiers.InnerDistances.y,
                                           math.lerp(point1.y, point2.y, 1 - modifiers.InnerDistances.y)
                                           + modifiers.InnerHeights.y);

            HeightBeziers[index] = new float2x4(point1, controlPoint1, controlPoint2, point2);
        }
Beispiel #13
0
        /// <summary>
        /// Method that actually calculates the bezier spline with variance
        /// </summary>
        /// <param name="t">progress X for center spline, Y for side spline</param>
        /// <param name="spline1">center spline index</param>
        /// <param name="spline2">side spline index</param>
        /// <param name="variance">deviation from center</param>
        /// <returns>final cubic variance position</returns>
        private float2 CubicBezierPoint(float2 t, int spline1, int spline2, half variance)
        {
            //center spline
            float2x4 a = new float2x4(
                Spline.Points[spline1 * 9 + 0],
                Spline.Points[spline1 * 9 + 3],
                Spline.Points[(spline1 + 1) * 9 - 3],
                Spline.Points[(spline1 + 1) * 9 + 0]);

            float2x4 b;

            if (variance > 0)
            {
                // Right spline
                b = new float2x4(
                    Spline.Points[spline2 * 9 + 2],
                    Spline.Points[spline2 * 9 + 5],
                    Spline.Points[(spline2 + 1) * 9 - 1],
                    Spline.Points[(spline2 + 1) * 9 + 2]);
            }
            else
            {
                // Left spline
                b = new float2x4(
                    Spline.Points[spline2 * 9 + 1],
                    Spline.Points[spline2 * 9 + 4],
                    Spline.Points[(spline2 + 1) * 9 - 2],
                    Spline.Points[(spline2 + 1) * 9 + 1]);
            }

            float2 oneMinusT = 1f - t;

            return(math.lerp(
                       (oneMinusT.x * oneMinusT.x * oneMinusT.x * a.c0) +
                       (3f * oneMinusT.x * oneMinusT.x * t.x * a.c1) +
                       (3f * oneMinusT.x * t.x * t.x * a.c2) +
                       (t.x * t.x * t.x * a.c3),
                       (oneMinusT.y * oneMinusT.y * oneMinusT.y * b.c0) +
                       (3f * oneMinusT.y * oneMinusT.y * t.y * b.c1) +
                       (3f * oneMinusT.y * t.y * t.y * b.c2) +
                       (t.y * t.y * t.y * b.c3), math.abs(variance)));
        }
Beispiel #14
0
        public static float4 cnoise(float2x4 P)
        {
            float4x4 Pi = math.float4x4(
                math.floor(P.c0.xyxy) + math.float4(0.0f, 0.0f, 1.0f, 1.0f),
                math.floor(P.c1.xyxy) + math.float4(0.0f, 0.0f, 1.0f, 1.0f),
                math.floor(P.c2.xyxy) + math.float4(0.0f, 0.0f, 1.0f, 1.0f),
                math.floor(P.c3.xyxy) + math.float4(0.0f, 0.0f, 1.0f, 1.0f)
                );
            float4x4 Pf = math.float4x4(
                frac(P.c0.xyxy) - math.float4(0.0f, 0.0f, 1.0f, 1.0f),
                frac(P.c1.xyxy) - math.float4(0.0f, 0.0f, 1.0f, 1.0f),
                frac(P.c2.xyxy) - math.float4(0.0f, 0.0f, 1.0f, 1.0f),
                frac(P.c3.xyxy) - math.float4(0.0f, 0.0f, 1.0f, 1.0f)
                );

            Pi = mod289(Pi);


            float4x4 ix = math.float4x4(
                Pi.c0.xzxz,
                Pi.c1.xzxz,
                Pi.c2.xzxz,
                Pi.c3.xzxz
                );
            float4x4 iy = math.float4x4(
                Pi.c0.yyww,
                Pi.c1.yyww,
                Pi.c2.yyww,
                Pi.c3.yyww
                );
            float4x4 fx = math.float4x4(
                Pf.c0.xzxz,
                Pf.c1.xzxz,
                Pf.c2.xzxz,
                Pf.c3.xzxz
                );
            float4x4 fy = math.float4x4(
                Pf.c0.yyww,
                Pf.c1.yyww,
                Pf.c2.yyww,
                Pf.c3.yyww
                );

            float4x4 i = permute(permute(ix) + iy);

            float4x4 gx = frac(i * (1.0f / 41.0f)) * 2.0f - 1.0f;
            float4x4 gy = math.float4x4(
                math.abs(gx.c0) - 0.5f,
                math.abs(gx.c1) - 0.5f,
                math.abs(gx.c2) - 0.5f,
                math.abs(gx.c3) - 0.5f
                );
            float4x4 tx = math.float4x4(
                math.floor(gx.c0 + 0.5f),
                math.floor(gx.c1 + 0.5f),
                math.floor(gx.c2 + 0.5f),
                math.floor(gx.c3 + 0.5f)
                );

            gx = gx - tx;

            float2x4 g00 = math.float2x4(
                math.float2(gx.c0.x, gy.c0.x),
                math.float2(gx.c1.x, gy.c1.x),
                math.float2(gx.c2.x, gy.c2.x),
                math.float2(gx.c3.x, gy.c3.x)
                );
            float2x4 g10 = math.float2x4(
                math.float2(gx.c0.y, gy.c0.y),
                math.float2(gx.c1.y, gy.c1.y),
                math.float2(gx.c2.y, gy.c2.y),
                math.float2(gx.c3.y, gy.c3.y)
                );
            float2x4 g01 = math.float2x4(
                math.float2(gx.c0.z, gy.c0.z),
                math.float2(gx.c1.z, gy.c1.z),
                math.float2(gx.c2.z, gy.c2.z),
                math.float2(gx.c3.z, gy.c3.z)
                );
            float2x4 g11 = math.float2x4(
                math.float2(gx.c0.w, gy.c0.w),
                math.float2(gx.c1.w, gy.c1.w),
                math.float2(gx.c2.w, gy.c2.w),
                math.float2(gx.c3.w, gy.c3.w)
                );

            float4x4 norm = taylorInvSqrt(math.float4x4(
                                              math.float4(math.dot(g00.c0, g00.c0), math.dot(g01.c0, g01.c0), math.dot(g10.c0, g10.c0),
                                                          math.dot(g11.c0, g11.c0)),
                                              math.float4(math.dot(g00.c1, g00.c1), math.dot(g01.c1, g01.c1), math.dot(g10.c1, g10.c1),
                                                          math.dot(g11.c1, g11.c1)),
                                              math.float4(math.dot(g00.c2, g00.c2), math.dot(g01.c2, g01.c2), math.dot(g10.c2, g10.c2),
                                                          math.dot(g11.c2, g11.c2)),
                                              math.float4(math.dot(g00.c3, g00.c3), math.dot(g01.c3, g01.c3), math.dot(g10.c3, g10.c3),
                                                          math.dot(g11.c3, g11.c3))
                                              ));

            g00 = math.float2x4(
                math.float2(g00.c0.x * norm.c0.x, g00.c0.y * norm.c0.x),
                math.float2(g00.c1.x * norm.c1.x, g00.c1.y * norm.c1.x),
                math.float2(g00.c2.x * norm.c2.x, g00.c2.y * norm.c2.x),
                math.float2(g00.c3.x * norm.c3.x, g00.c3.y * norm.c3.x)
                );
            g01 = math.float2x4(
                math.float2(g01.c0.x * norm.c0.y, g01.c0.y * norm.c0.y),
                math.float2(g01.c1.x * norm.c1.y, g01.c1.y * norm.c1.y),
                math.float2(g01.c2.x * norm.c2.y, g01.c2.y * norm.c2.y),
                math.float2(g01.c3.x * norm.c3.y, g01.c3.y * norm.c3.y)
                );
            g10 = math.float2x4(
                math.float2(g10.c0.x * norm.c0.z, g10.c0.y * norm.c0.z),
                math.float2(g10.c1.x * norm.c1.z, g10.c1.y * norm.c1.z),
                math.float2(g10.c2.x * norm.c2.z, g10.c2.y * norm.c2.z),
                math.float2(g10.c3.x * norm.c3.z, g10.c3.y * norm.c3.z)
                );
            g11 = math.float2x4(
                math.float2(g11.c0.x * norm.c0.w, g11.c0.y * norm.c0.w),
                math.float2(g11.c1.x * norm.c1.w, g11.c1.y * norm.c1.w),
                math.float2(g11.c2.x * norm.c2.w, g11.c2.y * norm.c2.w),
                math.float2(g11.c3.x * norm.c3.w, g11.c3.y * norm.c3.w)
                );

            float4 n00 = math.float4(
                math.dot(g00.c0, math.float2(fx.c0.x, fy.c0.x)),
                math.dot(g00.c1, math.float2(fx.c1.x, fy.c1.x)),
                math.dot(g00.c2, math.float2(fx.c2.x, fy.c2.x)),
                math.dot(g00.c3, math.float2(fx.c3.x, fy.c3.x))
                );
            float4 n10 = math.float4(
                math.dot(g10.c0, math.float2(fx.c0.y, fy.c0.y)),
                math.dot(g10.c1, math.float2(fx.c1.y, fy.c1.y)),
                math.dot(g10.c2, math.float2(fx.c2.y, fy.c2.y)),
                math.dot(g10.c3, math.float2(fx.c3.y, fy.c3.y))
                );
            float4 n01 = math.float4(
                math.dot(g01.c0, math.float2(fx.c0.z, fy.c0.z)),
                math.dot(g01.c1, math.float2(fx.c1.z, fy.c1.z)),
                math.dot(g01.c2, math.float2(fx.c2.z, fy.c2.z)),
                math.dot(g01.c3, math.float2(fx.c3.z, fy.c3.z))
                );
            float4 n11 = math.float4(
                math.dot(g11.c0, math.float2(fx.c0.w, fy.c0.w)),
                math.dot(g11.c1, math.float2(fx.c1.w, fy.c1.w)),
                math.dot(g11.c2, math.float2(fx.c2.w, fy.c2.w)),
                math.dot(g11.c3, math.float2(fx.c3.w, fy.c3.w))
                );
            float2x4 fade_xy = math.float2x4(
                fade(Pf.c0.xy),
                fade(Pf.c1.xy),
                fade(Pf.c2.xy),
                fade(Pf.c3.xy)
                );
            float2x4 n_x = math.float2x4(
                math.lerp(math.float2(n00.x, n01.x), math.float2(n10.x, n11.x), fade_xy.c0.x),
                math.lerp(math.float2(n00.y, n01.y), math.float2(n10.y, n11.y), fade_xy.c1.x),
                math.lerp(math.float2(n00.z, n01.z), math.float2(n10.z, n11.z), fade_xy.c2.x),
                math.lerp(math.float2(n00.w, n01.w), math.float2(n10.w, n11.w), fade_xy.c3.x)
                );
            float4 n_xy = math.float4(
                math.lerp(n_x.c0.x, n_x.c0.y, fade_xy.c0.y),
                math.lerp(n_x.c1.x, n_x.c1.y, fade_xy.c1.y),
                math.lerp(n_x.c2.x, n_x.c2.y, fade_xy.c2.y),
                math.lerp(n_x.c3.x, n_x.c3.y, fade_xy.c3.y)
                );

            return(2.3f * n_xy);
        }
Beispiel #15
0
        private static bool OnRectIntersection(RayComponent ray, ColliderComponent col, TransformComponent tr,
                                               out float2 hitPoint)
        {
            hitPoint = float2.zero;
            float minDist = float.MaxValue;

            float2x2 rotate   = float2x2.Rotate(tr.Rotation);
            float2x4 vertices = float2x4.zero;

            for (int i = 0; i < 4; i++)
            {
                vertices[i] = MathHelper.Mul(rotate, col.Vertices[i]) + tr.Position;
            }

            for (int i = 0; i < 4; i++)
            {
                int j = i + 1;
                if (j == 4)
                {
                    j = 0;
                }

                float2 p1 = vertices[i];
                float2 p2 = vertices[j];

                float2 b = ray.Target - ray.Source;
                float2 d = p2 - p1;

                float cross = b.x * d.y - b.y * d.x;
                if (MathHelper.Equal(cross, 0))
                {
                    continue;
                }

                float2 c = p1 - ray.Source;
                float  t = (c.x * d.y - c.y * d.x) / cross;
                if (t < 0 || t > 1)
                {
                    continue;
                }

                float u = (c.x * b.y - c.y * b.x) / cross;
                if (u < 0 || u > 1)
                {
                    continue;
                }

                float2 p = ray.Source + t * b;

                float dist = math.distancesq(ray.Source, p);
                if (!(dist < minDist))
                {
                    continue;
                }

                minDist  = dist;
                hitPoint = p;
            }

            return(minDist < float.MaxValue);
        }
Beispiel #16
0
 public static float2 GetVectorOnCurve(float2x4 b, float t) =>
 GetVectorOnCurve(b.c0, b.c1, b.c2, b.c3, t);