Beispiel #1
0
        public void ForwardSampleVerificationOnAStraightLine()
        {
            var points = new Vector3[] {
                new Vector3(-300.0f, 100.0f, 37.5f),
                new Vector3(1.2134f, -35.0f, 175.0f)
            };

            var bezier        = Bezier.ConstructSmoothSpline(points);
            var pntsDirection = (points[1] - points[0]).normalized;

            for (float t = 0.0f; t < 1.0f; t += 0.05f)
            {
                UAssert.Near(Vector3.Dot(bezier.ForwardSample(t), pntsDirection), 1.0f, 0.001f);
            }
        }
Beispiel #2
0
        public void ConstructSmoothStraightLineSpline()
        {
            var points = new Vector3[] {
                new Vector3(-300.0f, 0.0f, 237.0f),
                new Vector3(1.0f, 25.0f, -187.0f)
            };

            var bezier = Bezier.ConstructSmoothSpline(points);

            // Check that all points are linear on the x axis
            for (float t = 0.0f; t < 1.0f; t += 0.05f)
            {
                UAssert.NearLineSegment(points[0], points[1], bezier.PositionSample(t), 0.001f);
            }
        }
Beispiel #3
0
        public void ForwardDoesntFlipOnClosedSplines()
        {
            var points = new Vector3[] {
                new Vector3(10.0f, 0.0f, 0.0f),
                new Vector3(0.0f, 10.0f, 0.0f),
                new Vector3(-10.0f, 0.0f, 0.0f),
                new Vector3(0.0f, -10.0f, 0.0f),
            };

            var bezier = Bezier.ConstructSmoothSpline(points, true);

            var dir1 = bezier.ForwardSample(0.0f);
            var dir2 = bezier.ForwardSample(1.0f);

            UAssert.Near(dir1, dir2, 0.0001f);
        }
Beispiel #4
0
        public void ForwardSampleVerificationOnACircle()
        {
            var points = new Vector3[] {
                new Vector3(1.0f, 0.0f, 0.0f),
                new Vector3(0.0f, 1.0f, 0.0f),
                new Vector3(-1.0f, 0.0f, 0.0f),
                new Vector3(0.0f, -1.0f, 0.0f),
            };

            var bezier = Bezier.ConstructSmoothSpline(points);

            for (float t = 0.0f; t < 1.0f; t += 0.05f)
            {
                var expectedAngle = Mathf.Cos(t);
                UAssert.Near(Vector3.Dot(bezier.ForwardSample(t), Vector3.up), expectedAngle, 0.1f);
            }
        }
        public Loft BuildTube(float length, float radius)
        {
            var tubePath = Bezier.ConstructSmoothSpline(
                new Vector3[] {
                Vector3.zero,
                new Vector3(0.0f, length, 0.0f)
            }
                );

            var tubeShape = Bezier.ConstructSmoothSpline(
                new Vector3[] {
                new Vector3(-radius, 0.0f, 0.0f),
                new Vector3(0.0f, 0.0f, -radius),
                new Vector3(radius, 0.0f, 0.0f),
                new Vector3(0.0f, 0.0f, radius)
            },
                true
                );

            return(new Loft(tubePath, tubeShape));
        }
Beispiel #6
0
        public void ConstructSmoothSplineVerification()
        {
            var points = new Vector3[] {
                new Vector3(0.0f, 0.0f, 0.0f),
                new Vector3(1.0f, 0.0f, 0.0f),
                new Vector3(0.0f, 1.0f, 0.0f),
                new Vector3(0.0f, 0.0f, 1.0f),
                new Vector3(1.0f, 1.0f, 0.0f),
                new Vector3(0.0f, 1.0f, 1.0f),
                new Vector3(1.0f, 0.0f, 1.0f),
                new Vector3(1.0f, 1.0f, 1.0f)
            };

            var bezier = Bezier.ConstructSmoothSpline(points);

            // Check that the end points are sane
            UAssert.Near(bezier.PositionSample(0.0f), points[0], 0.0001f);
            UAssert.Near(bezier.PositionSample(1.0f), points[points.Length - 1], 0.0001f);

            // Check that there are no crazy values
            Vector3 pointCenter = MathExt.Average(points);

            for (float t = 0.0f; t < 1.0f; t += 0.01f)
            {
                UAssert.Near(bezier.PositionSample(t), pointCenter, 1.0f);
            }

            // Check that all the spline tangents are locked
            var controlPoints = new List <Bezier.ControlPoint>(bezier.ControlPoints);

            for (int i = 1; i < controlPoints.Count - 1; ++i)
            {
                var controlPoint   = controlPoints[i];
                var relativeInTan  = controlPoint.InTangent - controlPoint.Point;
                var relativeOutTan = controlPoint.OutTangent - controlPoint.Point;

                UAssert.Near(relativeInTan, relativeOutTan * -1.0f, 0.0001f);
            }
        }
        public Loft BuildTorus(float radius, float thickness)
        {
            var torusPath = Bezier.ConstructSmoothSpline(
                new Vector3[] {
                new Vector3(0.0f, radius, 0.0f),
                new Vector3(radius, 0.0f, 0.0f),
                new Vector3(0.0f, -radius, 0.0f),
                new Vector3(-radius, 0.0f, 0.0f)
            },
                true
                );

            var torusShape = Bezier.ConstructSmoothSpline(
                new Vector3[] {
                new Vector3(0.0f, 0.0f, thickness),
                new Vector3(thickness, 0.0f, 0.0f),
                new Vector3(0.0f, 0.0f, -thickness),
                new Vector3(-thickness, 0.0f, 0.0f)
            },
                true
                );

            return(new Loft(torusPath, torusShape));
        }