A that maps the HLSL type.
Example #1
0
        /// <summary>
        /// Bestimmt den geometrischen Fehler des angegebenen Vertex in Bezug auf die
        /// Fehlerquadrik Q.
        /// </summary>
        /// <param name="v">
        /// Der Vertex, dessen geometrischer Fehler bestimmt werden soll.
        /// </param>
        /// <param name="q">
        /// Die zugrundeliegende Fehlerquadrik.
        /// </param>
        /// <returns>
        /// Der geometrische Fehler an der Stelle des angegebenen Vertex.
        /// </returns>
        double ComputeVertexError(Double3 v, Double4x4 q)
        {
            var h = new Double4(v, 1);

            //// Geometrischer Fehler Δ(v) = vᵀQv.
            return(Double4.Dot(q * h, h));
        }
Example #2
0
        private void OnValueChanged()
        {
            if (IsSetBlocked)
            {
                return;
            }

            var    isSliding = XElement.IsSliding || YElement.IsSliding || ZElement.IsSliding || WElement.IsSliding;
            var    token     = isSliding ? this : null;
            var    value     = new Double4(XElement.ValueBox.Value, YElement.ValueBox.Value, ZElement.ValueBox.Value, WElement.ValueBox.Value);
            object v         = Values[0];

            if (v is Vector4)
            {
                v = (Vector4)value;
            }
            else if (v is Float4)
            {
                v = (Float4)value;
            }
            else if (v is Double4)
            {
                v = (Double4)value;
            }
            SetValue(v, token);
        }
Example #3
0
 /// <summary>
 /// Writes the Vector4 to the binary stream.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="value">The value to write.</param>
 public static void Write(this BinaryWriter stream, Double4 value)
 {
     stream.Write(value.X);
     stream.Write(value.Y);
     stream.Write(value.Z);
     stream.Write(value.W);
 }
Example #4
0
		public void Dot()
		{
			Double4 a = new Double4(1, 2, 3, 4);
			Double4 b = new Double4(1, 2, 3, 4);
			Double expected = (Double)(1 + 4 + 9 + 16);
			Assert.AreEqual(expected, MathHelper.Dot(a, b));

		}
Example #5
0
        public CurveVertex(Double2 pos, Double4 curve)
        {
            Position    = pos;
            CurveCoords = curve;

            // Sanity check
            //Debug.Assert(!double.IsNaN(curve.X) && !double.IsNaN(curve.Y) && !double.IsNaN(curve.Z), "Problematic curve vertex generated!");
        }
Example #6
0
 public void Bezier(ref Double4 p0, ref Double4 p1, ref Double4 p2, ref Double4 p3, float alpha, out Double4 result)
 {
     Double4.Lerp(ref p0, ref p1, alpha, out var p01);
     Double4.Lerp(ref p1, ref p2, alpha, out var p12);
     Double4.Lerp(ref p2, ref p3, alpha, out var p23);
     Double4.Lerp(ref p01, ref p12, alpha, out var p012);
     Double4.Lerp(ref p12, ref p23, alpha, out var p123);
     Double4.Lerp(ref p012, ref p123, alpha, out result);
 }
Example #7
0
        public DoubleCurveVertex(Double2 pos, Double4 curve1, Double4 curve2, bool disjointUnion)
        {
            Position     = pos;
            CurveCoords1 = curve1;
            CurveCoords2 = curve2;

            if (disjointUnion)
            {
                CurveCoords1.W += 4;
            }

            Debug.Assert(!double.IsNaN(curve1.X) && !double.IsNaN(curve1.Y) && !double.IsNaN(curve1.Z) && !double.IsNaN(curve1.W));
            Debug.Assert(!double.IsNaN(curve2.X) && !double.IsNaN(curve2.Y) && !double.IsNaN(curve2.Z) && !double.IsNaN(curve2.W));
        }
        private CurveVertex[] CubicBezier_CurveVertices()
        {
            // Apply the Loop-Blinn method to get the texture coordinates
            // Available on https://www.microsoft.com/en-us/research/wp-content/uploads/2005/01/p1000-loop.pdf

            // Use the computations in Chapter 4 of the Loop-Blinn paper
            // The canonical form of the curve
            var c3 = -A + 3 * B - 3 * C + D;
            var c2 = 3 * A - 6 * B + 3 * C;
            var c1 = -3 * A + 3 * B;
            var c0 = A;

            // Again the inflection point polynomials, this time the homogeneous form
            var d3 = c1.Cross(c2);
            var d2 = c3.Cross(c1);
            var d1 = c2.Cross(c3);

            // The texture coordinates in canonical form
            Double4 f0, f1, f2, f3;

            void NegateSigns()
            {
                f0 = f0.NegateX.NegateY;
                f1 = f1.NegateX.NegateY;
                f2 = f2.NegateX.NegateY;
                f3 = f3.NegateX.NegateY;
            }

            // Check for the "true" cubics first
            if (d1 != 0)
            {
                // Discriminant
                var D = 3 * d2 * d2 - 4 * d3 * d1;

                // Serpentine or cusp
                if (D > -double.Epsilon)
                {
                    // Find the roots of the equation
                    var dv = d2 >= 0 ? Math.Sqrt(D / 3) : -Math.Sqrt(D / 3);
                    var q  = 0.5 * (d2 + dv);

                    var x1 = q / d1;
                    var x2 = (d3 / 3) / q;

                    var l = Math.Min(x1, x2);
                    var m = Math.Max(x1, x2);

                    f0 = new Double4(l * m, l * l * l, m * m * m, 0);
                    f1 = new Double4(-l - m, -3 * l * l, -3 * m * m, 0);
                    f2 = new Double4(1, 3 * l, 3 * m, 0);
                    f3 = new Double4(0, -1, -1, 0);

                    // Guarantee that the signs are correct
                    if (d1 < 0)
                    {
                        NegateSigns();
                    }
                }
                // Loop
                else
                {
                    // Find the roots of the equation
                    var dv = d2 >= 0 ? Math.Sqrt(-D) : -Math.Sqrt(-D);
                    var q  = 0.5 * (d2 + dv);

                    var x1 = q / d1;
                    var x2 = (d2 * d2 / d1 - d3) / q;

                    var d = Math.Min(x1, x2);
                    var e = Math.Max(x1, x2);

                    f0 = new Double4(d * e, d * d * e, d * e * e, 0);
                    f1 = new Double4(-d - e, -d * d - 2 * e * d, -e * e - 2 * d * e, 0);
                    f2 = new Double4(1, e + 2 * d, d + 2 * e, 0);
                    f3 = new Double4(0, -1, -1, 0);

                    // Guarantee that the signs are correct
                    var h1  = d3 * d1 - d2 * d2;
                    var h2  = d3 * d1 - d2 * d2 + d1 * d2 - d1 * d1;
                    var h   = Math.Abs(h1) > Math.Abs(h2) ? h1 : h2;
                    var h12 = d3 * d1 - d2 * d2 + d1 * d2 / 2 - d1 * d1 / 4;
                    if (Math.Abs(h12) > Math.Abs(h))
                    {
                        h = h12;
                    }

                    if (d1 * h > 0)
                    {
                        NegateSigns();
                    }
                }
            }
            // Other kind of cusp
            else if (d2 != 0)
            {
                // A single root
                var l = d3 / (3 * d2);

                f0 = new Double4(l, l * l * l, 1, 0);
                f1 = new Double4(-1, -3 * l * l, 0, 0);
                f2 = new Double4(0, -3 * l, 0, 0);
                f3 = new Double4(0, -1, 0, 0);
            }
            // Degenerate forms for the cubic - first, a quadratic
            else if (d3 != 0)
            {
                f0 = new Double4(0, 0, 1, 0);
                f1 = new Double4(1, 0, 1, 0);
                f2 = new Double4(0, 1, 0, 0);
                f3 = new Double4(0, 0, 0, 0);
            }
            // A line or a point - no triangles
            else
            {
                return(new CurveVertex[0]);
            }

            // Put the texture coordinates back into "normal" form
            return(new[]
            {
                new CurveVertex(A, f0),
                new CurveVertex(B, f0 + f1 / 3),
                new CurveVertex(C, f0 + (2 * f1 + f2) / 3),
                new CurveVertex(D, f0 + f1 + f2 + f3)
            });
        }
 public CurveVertex(Double2 pos, Double4 curve)
 {
     Position    = pos;
     CurveCoords = curve;
 }
    private void SaveState()
    {
        List<SerializableNode> serializableNodes = new List<SerializableNode> ();
        foreach (Node node in Nodes)
        {
            SerializableNode newNode = new SerializableNode();
            newNode.Name = node.Name;
            newNode.Position = new Double2 (node.Position.x, node.Position.y);
            newNode.HasOutput = node.HasOutput;
            newNode.Content = node._content;

            newNode.Inputs = new List<int>();
            newNode.InputNames = new List<string>();
            if (node.Inputs != null)
            {
                int i=0;
                foreach (Node input in node.Inputs)
                {
                    newNode.InputNames.Add (node.InputNames[i]);
                    if (input != null)
                    {
                        newNode.Inputs.Add(Nodes.IndexOf(input));
                    }
                    else
                    {
                        newNode.Inputs.Add(-1);
                    }
                    i++;
                }
            }

            newNode.FloatUserInputs = new List<double>();
            newNode.Vector2UserInputs = new List<Double2>();
            newNode.ColorUserInputs = new List<Double4>();
            foreach (object userInput in node.UserInputs)
            {
                if (userInput.GetType() == typeof(float))
                {
                    double value = (float)userInput;
                    newNode.FloatUserInputs.Add(value);
                }
                if (userInput.GetType() == typeof(Vector2))
                {
                    Double2 value = new Double2(((Vector2)userInput).x, ((Vector2)userInput).y);
                    newNode.Vector2UserInputs.Add(value);
                }
                if (userInput.GetType() == typeof(Color))
                {
                    Double4 value = new Double4(((Color)userInput).r, ((Color)userInput).g, ((Color)userInput).b, ((Color)userInput).a);
                    newNode.ColorUserInputs.Add(value);
                }
            }
            serializableNodes.Add(newNode);
        }
        string json = JsonMapper.ToJson (serializableNodes);
        string actualSavePath = string.Format(WINDOW_SAVESTATE_PATH, SelectedmaterialName) + ".txt";
        File.WriteAllText (actualSavePath, json);
    }
 void IKeyframeAccess <Double4> .SetCurveValue(float curve, ref Double4 value, int component)
 {
     value[component] = curve;
 }
 float IKeyframeAccess <Double4> .GetCurveValue(ref Double4 value, int component)
 {
     return((float)value[component]);
 }
 void IKeyframeAccess <Double4> .GetDefaultValue(out Double4 value)
 {
     value = Double4.Zero;
 }
Example #14
0
 public DoubleCurveVertex(Double2 pos, Double4 curve1, Double4 curve2)
 {
     Position     = pos;
     CurveCoords1 = curve1;
     CurveCoords2 = curve2;
 }
Example #15
0
 public void Linear(ref Double4 a, ref Double4 b, float alpha, out Double4 result)
 {
     Double4.Lerp(ref a, ref b, alpha, out result);
 }
Example #16
0
 public void GetTangent(ref Double4 value, ref Double4 tangent, float lengthThird, out Double4 result)
 {
     result = value + tangent * lengthThird;
 }