コード例 #1
0
ファイル: Matlib.cs プロジェクト: Hashmi1/IndorilConverter
        public static Matlib operator *(Matlib _a, Matlib b)
        {
            int n = _a.N;
            int m = b.M;
            int l = _a.M;

            if (l != b.N)
            {
                throw new ArgumentException("Illegal matrix dimensions for multiplication. _a.M must be equal b.N");
            }
            Matlib result = new Matlib(_a.N, b.M);

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    double sum = 0.0;
                    for (int k = 0; k < l; k++)
                    {
                        sum += _a.a[i, k] * b.a[k, j];
                    }
                    result.a[i, j] = sum;
                }
            }
            return(result);
        }
コード例 #2
0
ファイル: Matlib.cs プロジェクト: Hashmi1/IndorilConverter
        public static float[] rotateX(float[] vertex, float xR = (float)3.14159265358979323846 / 2f)
        {
            Matlib rot = new Matlib(3, 3);

            rot[1, 1] = 1.0f;     rot[1, 2] = 0.0f;                 rot[1, 3] = 0.0f;
            rot[2, 1] = 0.0f;     rot[2, 2] = Math.Cos(xR);         rot[2, 3] = -Math.Sin(xR);
            rot[3, 1] = 0.0f;     rot[3, 2] = Math.Sin(xR);         rot[3, 3] = Math.Cos(xR);

            Matlib vertex_mat = new Matlib(3, 1);

            vertex_mat[1, 1] = vertex[0];
            vertex_mat[2, 1] = vertex[1];
            vertex_mat[3, 1] = vertex[2];

            Matlib answer = rot * vertex_mat;

            vertex[0] = (float)answer[1, 1];
            vertex[1] = (float)answer[2, 1];
            vertex[2] = (float)answer[3, 1];

            return(vertex);
        }
コード例 #3
0
ファイル: Generator.cs プロジェクト: Hashmi1/IndorilConverter
        public TES5.Record recast_to_skyrim(string file, UInt32 cell_id)
        {
            try
            {
                List <TES5.NVNM.Vertex>   vertices  = new List <TES5.NVNM.Vertex>();
                List <TES5.NVNM.Triangle> triangles = new List <TES5.NVNM.Triangle>();

                uint nverts = 0;
                uint ntris  = 0;

                # region parsing recastnavigation output
                TextReader fin = File.OpenText(file);

                while (fin.Peek() != -1)
                {
                    string line = fin.ReadLine().Trim();

                    if (String.IsNullOrEmpty(line) || String.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    string[] parsed = line.Split(' ');

                    if (line.StartsWith("#nverts"))
                    {
                        nverts = uint.Parse(parsed[1]);
                    }

                    else if (line.StartsWith("#ntris"))
                    {
                        ntris = uint.Parse(parsed[1]);
                    }

                    else if (parsed[0].Equals("v"))
                    {
                        float[] vtx = new float[3] {
                            float.Parse(parsed[1]), float.Parse(parsed[2]), float.Parse(parsed[3])
                        };

                        vtx = Matlib.scale(vtx, 50);
                        vtx = Matlib.rotateX(vtx);

                        vertices.Add(new TES5.NVNM.Vertex(vtx[0], vtx[1], vtx[2]));
                    }

                    else if (parsed[0].Equals("f"))
                    {
                        TES5.NVNM.Triangle tri = new TES5.NVNM.Triangle();
                        tri.vert1 = (ushort)(ushort.Parse(parsed[1]) - 1);
                        tri.vert2 = (ushort)(ushort.Parse(parsed[2]) - 1);
                        tri.vert3 = (ushort)(ushort.Parse(parsed[3]) - 1);

                        string line2 = fin.ReadLine().Trim();

                        string[] parsed_line2 = line2.Split(' ');

                        if (!parsed_line2[0].Equals("#neighbours"))
                        {
                            Log.error("Neighbour data not found for generated navmesh");
                        }

                        tri.neigh1 = ushort.Parse(parsed_line2[1]);
                        tri.neigh2 = ushort.Parse(parsed_line2[2]);
                        tri.neigh3 = ushort.Parse(parsed_line2[3]);

                        triangles.Add(tri);
                    }
                }
                # endregion

                if (triangles.Count != ntris || vertices.Count != nverts)