Exemplo n.º 1
0
        /// <summary>
        /// Get camera to plane distance
        /// </summary>
        /// <param name="point">Camera position</param>
        /// <param name="plane">Plane definition</param>
        /// <param name="map">Shared map data</param>
        /// <returns>Plane distance</returns>
        private static int GetDistance(Point3D point, Powerslave.Plane plane, Powerslave.Map map)
        {
            List <Powerslave.Vertex> vertices = plane.PolyVert.Select(vertex => map.Vertices[vertex]).ToList();

            Powerslave.Vertex center = new Powerslave.Vertex()
            {
                X = (short)(vertices.Sum(vertex => vertex.X) / 4), Y = (short)(vertices.Sum(vertex => vertex.Y) / 4), Z = (short)(vertices.Sum(vertex => vertex.Z) / 4)
            };
            return((int)(Math.Pow(point.X - (center.X / 10.0f), 2) + Math.Pow(point.Y - (center.Z / 10.0f), 2) + Math.Pow(point.Z - (center.Y / 10.0f), 2)));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get triangles from quad
        /// </summary>
        /// <param name="quad">Quad polygon</param>
        /// <returns>List of triangles</returns>
        private static List <Powerslave.Vertex> GetTrianglesFromQuad(List <Powerslave.Vertex> quad)
        {
            List <List <Powerslave.Vertex> > triangles = new List <List <Powerslave.Vertex> >
            {
                new List <Powerslave.Vertex> {
                    quad[0], quad[1], quad[2]
                },
                new List <Powerslave.Vertex> {
                    quad[2], quad[3], quad[0]
                }
            };

            // Remove zero-area triangles
            for (int triangle = 0; triangle < triangles.Count; triangle++)
            {
                bool foundSame = false;

                for (int index = 0; index < 3 && !foundSame; index++)
                {
                    Powerslave.Vertex toCheck = triangles[triangle][index];

                    for (int compare = 0; compare < 3 && !foundSame; compare++)
                    {
                        Powerslave.Vertex toCompare = triangles[triangle][compare];
                        foundSame = index != compare && toCompare.X == toCheck.X && toCompare.Y == toCheck.Y && toCompare.Z == toCheck.Z;
                    }
                }

                if (foundSame)
                {
                    triangles.RemoveAt(triangle);
                    triangle--;
                }
            }

            return(triangles.SelectMany(triangle => triangle).ToList());
        }