Ejemplo n.º 1
0
        /// <summary>
        /// Clips a polygon to a plane using the Sutherland-Hodgman algorithm.
        /// </summary>
        /// <param name="inVertices">The input array of vertices.</param>
        /// <param name="outVertices">The output array of vertices.</param>
        /// <param name="distances">A buffer that stores intermediate data</param>
        /// <param name="numVerts">The number of vertices to read from the arrays.</param>
        /// <param name="planeX">The clip plane's X component.</param>
        /// <param name="planeZ">The clip plane's Z component.</param>
        /// <param name="planeD">The clip plane's D component.</param>
        /// <returns>The number of vertices stored in outVertices.</returns>
        internal static int ClipPolygonToPlane(Vector3[] inVertices, Vector3[] outVertices, float[] distances, int numVerts, float planeX, float planeZ, float planeD)
        {
            for (int i = 0; i < numVerts; i++)
            {
                distances[i] = planeX * inVertices[i].X + planeZ * inVertices[i].Z + planeD;
            }

            int     m = 0;
            Vector3 temp;

            for (int i = 0, j = numVerts - 1; i < numVerts; j = i, i++)
            {
                bool inj = distances[j] >= 0;
                bool ini = distances[i] >= 0;

                if (inj != ini)
                {
                    float s = distances[j] / (distances[j] - distances[i]);

                    Vector3.Subtract(ref inVertices[i], ref inVertices[j], out temp);
                    Vector3.Multiply(ref temp, s, out temp);
                    Vector3.Add(ref inVertices[j], ref temp, out outVertices[m]);
                    m++;
                }

                if (ini)
                {
                    outVertices[m] = inVertices[i];
                    m++;
                }
            }

            return(m);
        }
Ejemplo n.º 2
0
        public static Vector3 Multiply(Vector3 left, Vector3 right)
        {
            var result = MonoGameVector3.Multiply(left.MonoGameVector, right.MonoGameVector);

            return(new Vector3(result));
        }
Ejemplo n.º 3
0
        public static Vector3 Multiply(Vector3 left, float scale)
        {
            var result = MonoGameVector3.Multiply(left.MonoGameVector, scale);

            return(new Vector3(result));
        }