private Segment SegmentFor(VertexDirection direction)
        {
            switch (direction)
            {
            case VertexDirection.None:
            case VertexDirection.Top:  return(Terrain.UvMapping.Top);

            case VertexDirection.Down: return(Terrain.UvMapping.Bottom);

            case VertexDirection.Left: return(Terrain.UvMapping.Left);

            case VertexDirection.Right: return(Terrain.UvMapping.Right);

            default: throw new ArgumentOutOfRangeException();
            }
        }
        private ViewModels.Segment GetUvMappingOf(VertexDirection direction)
        {
            switch (direction)
            {
            case VertexDirection.Top:
                return(m_mesh.UvMapping.Top);

            case VertexDirection.Down:
                return(m_mesh.UvMapping.Bottom ?? m_mesh.UvMapping.Top);

            case VertexDirection.Left:
                return(m_mesh.UvMapping.Left ?? m_mesh.UvMapping.Right ?? m_mesh.UvMapping.Top);

            case VertexDirection.Right:
                return(m_mesh.UvMapping.Right ?? m_mesh.UvMapping.Left ?? m_mesh.UvMapping.Top);

            default:
                return(null);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates an arc with the specified endpoints and the resultant included angle and vertex direction.
        /// </summary>
        /// <param name="p1">The first point.</param>
        /// <param name="p2">The second point.</param>
        /// <param name="includedAngle">The included angle of the resultant arc in degrees.</param>
        /// <param name="vertexDirection">The direction of the vertices specifying the arc.</param>
        /// <returns>The resultant arc, or null if it couldn't be created.</returns>
        public static PrimitiveEllipse ArcFromPointsAndIncludedAngle(Point p1, Point p2, double includedAngle, VertexDirection vertexDirection)
        {
            if (p1.Z != p2.Z)
            {
                throw new InvalidOperationException("only simple planar arcs are currently supported");
            }

            if (includedAngle < 0.0 || includedAngle >= MathHelper.ThreeSixty)
            {
                throw new ArgumentOutOfRangeException(nameof(includedAngle));
            }

            // given the following diagram:
            //
            //                p1
            //               -)
            //            -  |  )
            //        -      |    )
            //    -          |     )
            // O ------------|C----T
            //    -          |  x  )
            //        -      |    )
            //            -  |  )
            //               -)
            //               p2
            //
            // where O is the center of the circle, C is the midpoint between p1 and p2, the
            // distance x is the amount that C would have to be offset perpendicular to the
            // line p1p2 to find the third point T from which we can calculate the arcs

            // first, find the required radius
            // there is an isoceles triangle created between the two points and the center which means splitting that there's
            // a right triangle whose hypotenuse is a radius of the circle and the opposite side is half of the distance between
            // the points.
            var incAngleRad = includedAngle * MathHelper.DegreesToRadians;
            var halfAngle   = incAngleRad / 2.0;
            var otherLength = (p2 - p1).Length / 2.0;
            // since sin(theta) = opposite / hypotenuse => opposite / sin(theta) = hypotenuse
            var radius = otherLength / Math.Sin(halfAngle); // hypotenuse length

            // then, given that Op1C is a right triangle and that the line OC has a length of r - x and assuming y is the distance
            // between the point C and p1, we get
            // r^2 = (r-x)^2 + y^2 => x = r - sqrt(r^2 - y^2)
            var midpoint = (p1 + p2) / 2.0;
            var y        = otherLength;
            var xOffset  = radius - Math.Sqrt((radius * radius) - (y * y));

            // for angles greater than 180 degrees, the offset point is really much farther away
            if (includedAngle >= MathHelper.OneEighty)
            {
                xOffset = radius + radius - xOffset;
            }

            // now offset the midpoint by x (both directions) perpendicular to the line p1p2 and compute the arcs
            var chordVector       = p2 - p1;
            var offsetVector      = new Vector(-chordVector.Y, chordVector.X, chordVector.Z).Normalize() * xOffset;
            var possibleMidpoint1 = midpoint + offsetVector;
            var possibleMidpoint2 = midpoint - offsetVector;

            // now construct like normal
            var arc        = ThreePointArc(p1, possibleMidpoint1, p2, idealNormal: Vector.ZAxis);
            var startPoint = arc.StartPoint();

            if (startPoint.CloseTo(p1) ^ vertexDirection != VertexDirection.CounterClockwise)
            {
                // arc is correct
            }
            else
            {
                arc = ThreePointArc(p1, possibleMidpoint2, p2, idealNormal: Vector.ZAxis);
            }

            return(arc);
        }
Esempio n. 4
0
 public Vertex(Point location, double includedAngle, VertexDirection direction)
 {
     Location      = location;
     IncludedAngle = includedAngle;
     Direction     = direction;
 }
Esempio n. 5
0
 public VertexInfo(Vector v, VertexDirection dir = VertexDirection.Auto)
 {
     Position  = v;
     Direction = dir;
 }
Esempio n. 6
0
 public VertexInfo(double x = 0, double y = 0, VertexDirection dir = VertexDirection.Auto)
 {
     Position  = new Vector(x, y);
     Direction = dir;
 }
Esempio n. 7
0
 public VertexInfo(Vector2 pos, VertexDirection dir, SplitMode split)
 {
     Position  = pos;
     Direction = dir;
     Split     = split;
 }