當前位置: 首頁>>代碼示例>>C#>>正文


C# Vector3.GetLength方法代碼示例

本文整理匯總了C#中Microsoft.Xna.Framework.Vector3.GetLength方法的典型用法代碼示例。如果您正苦於以下問題:C# Vector3.GetLength方法的具體用法?C# Vector3.GetLength怎麽用?C# Vector3.GetLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.Xna.Framework.Vector3的用法示例。


在下文中一共展示了Vector3.GetLength方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ConvertMeshToVertList

        /// <summary>
        /// warning: cache thrashes
        /// </summary>
        /// <param name="mesh"></param>
        /// <param name="vertexes"></param>
        public static void ConvertMeshToVertList(Vector3[,] mesh, ref VertexPositionTexture[] vertexes)
        {
            int index = 0;
            for (int x = 0; x < mesh.GetLength(0) - 1; x++) {
                for (int z = 0; z < mesh.GetLength(1) - 1; z++) {
                    vertexes[index].Position = mesh[x, z];
                    vertexes[index + 1].Position = mesh[x, z + 1];
                    vertexes[index + 2].Position = mesh[x + 1, z + 1];
                    vertexes[index + 3].Position = mesh[x + 1, z];

                    index += 4;
                }
            }
        }
開發者ID:bsamuels453,項目名稱:With-Fire-and-Iron,代碼行數:19,代碼來源:MeshHelper.cs

示例2: ConvertMeshToVertList

        public static void ConvertMeshToVertList(Vector3[,] mesh, Vector3[,] normals, ref VertexPositionNormalTexture[] verticies)
        {
            //convert from 2d array to 1d
            int index = 0;
            for (int x = 0; x < mesh.GetLength(0) - 1; x++){
                for (int z = 0; z < mesh.GetLength(1) - 1; z++){
                    verticies[index].Position = mesh[x, z];
                    verticies[index].Normal = normals[x, z];

                    verticies[index + 1].Position = mesh[x, z + 1];
                    verticies[index + 1].Normal = normals[x, z + 1];

                    verticies[index + 2].Position = mesh[x + 1, z + 1];
                    verticies[index + 2].Normal = normals[x + 1, z + 1];

                    verticies[index + 3].Position = mesh[x + 1, z];
                    verticies[index + 3].Normal = normals[x + 1, z];

                    index += 4;
                }
            }
        }
開發者ID:bsamuels453,項目名稱:Drydock,代碼行數:22,代碼來源:MeshHelper.cs

示例3: GenerateMeshNormals

        public static Vector3[,] GenerateMeshNormals(Vector3[,] mesh)
        {
            var normals = new Vector3[mesh.GetLength(0), mesh.GetLength(1)];
            for (int vertX = 0; vertX < mesh.GetLength(0) - 1; vertX++) {
                for (int vertZ = 0; vertZ < mesh.GetLength(1) - 1; vertZ++) {
                    var crossSum = new Vector3();

                    var s1 = mesh[vertX + 1, vertZ] - mesh[vertX, vertZ];
                    var s2 = mesh[vertX, vertZ + 1] - mesh[vertX, vertZ];
                    var s3 = mesh[vertX + 1, vertZ + 1] - mesh[vertX, vertZ];

                    crossSum += Vector3.Cross(s1, s3);
                    crossSum += Vector3.Cross(s3, s2);

                    normals[vertX, vertZ] += crossSum;
                    if (crossSum != Vector3.Zero) {
                        normals[vertX, vertZ].Normalize();
                    }
                }
            }

            for (int vertX = 1; vertX < mesh.GetLength(0); vertX++) {
                for (int vertZ = 1; vertZ < mesh.GetLength(1); vertZ++) {
                    var crossSum = new Vector3();

                    var s1 = mesh[vertX - 1, vertZ] - mesh[vertX, vertZ];
                    var s2 = mesh[vertX, vertZ - 1] - mesh[vertX, vertZ];
                    var s3 = mesh[vertX - 1, vertZ - 1] - mesh[vertX, vertZ];

                    crossSum += Vector3.Cross(s1, s3);
                    crossSum += Vector3.Cross(s3, s2);

                    normals[vertX, vertZ] += crossSum;
                    normals[vertX, vertZ].Normalize();
                }
            }
            return normals;
        }
開發者ID:bsamuels453,項目名稱:With-Fire-and-Iron,代碼行數:38,代碼來源:MeshHelper.cs


注:本文中的Microsoft.Xna.Framework.Vector3.GetLength方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。