// Copyright (c) 2014-2015 Robert Rouhani and other contributors (see CONTRIBUTORS file). // Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE using System.Runtime.InteropServices; using SharpNav.Geometry; #if MONOGAME using Vector3 = Microsoft.Xna.Framework.Vector3; #elif OPENTK using Vector3 = OpenTK.Vector3; #elif SHARPDX using Vector3 = SharpDX.Vector3; #endif namespace SharpNav { /// /// A is a vertex that stores 3 integer coordinates and a region ID, and is used to build s. /// [StructLayout(LayoutKind.Sequential)] public struct ContourVertex { /// /// The X coordinate. /// public int X; /// /// The Y coordinate. /// public int Y; /// /// The Z coordinate. /// public int Z; /// /// The region that the vertex belongs to. /// public RegionId RegionId; /// /// Initializes a new instance of the struct. /// /// The X coordinate. /// The Y coordinate. /// The Z coordinate. /// The region ID. public ContourVertex(int x, int y, int z, RegionId region) { this.X = x; this.Y = y; this.Z = z; this.RegionId = region; } /// /// Initializes a new instance of the struct. /// /// The array of X,Y,Z coordinates. /// The Region ID. public ContourVertex(Vector3 vec, RegionId region) { this.X = (int)vec.X; this.Y = (int)vec.Y; this.Z = (int)vec.Z; this.RegionId = region; } /// /// Initializes a new instance of the struct as a copy. /// /// The original vertex. /// The index of the original vertex, which is temporarily stored in the field. public ContourVertex(ContourVertex vert, int index) { this.X = vert.X; this.Y = vert.Y; this.Z = vert.Z; this.RegionId = new RegionId(index); } /// /// Initializes a new instance of the struct as a copy. /// /// The original vertex. /// The region that the vertex belongs to. public ContourVertex(ContourVertex vert, RegionId region) { this.X = vert.X; this.Y = vert.Y; this.Z = vert.Z; this.RegionId = region; } /// /// Gets the leftness of a triangle formed from 3 contour vertices. /// /// The first vertex. /// The second vertex. /// The third vertex. /// A value indicating the leftness of the triangle. public static bool IsLeft(ref ContourVertex a, ref ContourVertex b, ref ContourVertex c) { int area; Area2D(ref a, ref b, ref c, out area); return area < 0; } /// /// Gets the 2D area of the triangle ABC. /// /// Point A of triangle ABC. /// Point B of triangle ABC. /// Point C of triangle ABC. /// The 2D area of the triangle. public static void Area2D(ref ContourVertex a, ref ContourVertex b, ref ContourVertex c, out int area) { area = (b.X - a.X) * (c.Z - a.Z) - (c.X - a.X) * (b.Z - a.Z); } } }