private void AddTrianglesGroupDoodads(TriangleCollection s, ModelInstance mi, Vec3D world_dir, Vec3D world_off, float rot)
        {
            sequence++;
            float dx = mi.pos.x;
            float dy = mi.pos.y;
            float dz = mi.pos.z;

            rotate(dx, dz, rot + 90f, out dx, out dz);

            dx += world_off.x;
            dy += world_off.y;
            dz += world_off.z;

            Quaternion q;

            q.x = mi.dir.z;
            q.y = mi.dir.x;
            q.z = mi.dir.y;
            q.w = mi.w;
            Matrix4 rotMatrix = new Matrix4();

            rotMatrix.makeQuaternionRotate(q);

            Model m = mi.model;

            if (m.boundingTriangles == null)
            {
            }
            else
            {
                // We got boiuding stuff, that is better
                int   nBoundingVertices = m.boundingVertices.Length / 3;
                int[] vertices          = new int[nBoundingVertices];

                for (uint i = 0; i < nBoundingVertices; i++)
                {
                    uint  off = i * 3;
                    float x   = m.boundingVertices[off];
                    float y   = m.boundingVertices[off + 2];
                    float z   = m.boundingVertices[off + 1];
                    x *= mi.sc;
                    y *= mi.sc;
                    z *= -mi.sc;

                    Vector pos;
                    pos.x = x;
                    pos.y = y;
                    pos.z = z;
                    Vector new_pos = rotMatrix.mutiply(pos);
                    x = pos.x;
                    y = pos.y;
                    z = pos.z;

                    float dir_x = world_dir.z;
                    float dir_y = world_dir.y - 90;
                    float dir_z = -world_dir.x;

                    rotate(z, y, dir_x, out z, out y);
                    rotate(x, y, dir_z, out x, out y);
                    rotate(x, z, dir_y, out x, out z);

                    float xx = x + dx;
                    float yy = y + dy;
                    float zz = -z + dz;

                    float finalx = ChunkReader.ZEROPOINT - zz;
                    float finaly = ChunkReader.ZEROPOINT - xx;
                    float finalz = yy;
                    vertices[i] = s.AddVertex(finalx, finaly, finalz);
                }

                int nBoundingTriangles = m.boundingTriangles.Length / 3;
                for (uint i = 0; i < nBoundingTriangles; i++)
                {
                    uint off = i * 3;
                    int  v0  = vertices[m.boundingTriangles[off]];
                    int  v1  = vertices[m.boundingTriangles[off + 1]];
                    int  v2  = vertices[m.boundingTriangles[off + 2]];
                    s.AddTriangle(v0, v2, v1, ChunkedTriangleCollection.TriangleFlagModel, sequence);
                }
            }
        }
        private void AddTriangles(TriangleCollection s, ModelInstance mi)
        {
            sequence++;
            float dx = mi.pos.x;
            float dy = mi.pos.y;
            float dz = mi.pos.z;

            float dir_x = mi.dir.z;
            float dir_y = mi.dir.y - 90; // -90 is correct!
            float dir_z = -mi.dir.x;

            Model m = mi.model;

            if (m == null)
            {
                return;
            }

            if (m.boundingTriangles == null)
            {
                // /cry no bouding info, revert to normal vertives

                /*
                 *              ModelView mv = m.view[0]; // View number 1 ?!?!
                 *              if (mv == null) return;
                 *              int[] vertices = new int[m.vertices.Length / 3];
                 *              for (uint i = 0; i < m.vertices.Length / 3; i++)
                 *              {
                 *                      float x = m.vertices[i * 3];
                 *                      float y = m.vertices[i * 3 + 2];
                 *                      float z = m.vertices[i * 3 + 1];
                 *                      x *= mi.sc;
                 *                      y *= mi.sc;
                 *                      z *= mi.sc;
                 *
                 *                      rotate(y, z, dir_x, out y, out z);
                 *                      rotate(x, y, dir_z, out x, out y);
                 *                      rotate(x, z, dir_y, out x, out z);
                 *
                 *                      float xx = x + dx;
                 *                      float yy = y + dy;
                 *                      float zz = -z + dz;
                 *
                 *                      float finalx = ChunkReader.ZEROPOINT - zz;
                 *                      float finaly = ChunkReader.ZEROPOINT - xx;
                 *                      float finalz = yy;
                 *
                 *                      vertices[i] = s.AddVertex(finalx, finaly, finalz);
                 *              }
                 *
                 *              for (int i = 0; i < mv.triangleList.Length / 3; i++)
                 *              {
                 *                      int off = i * 3;
                 *                      UInt16 vi0 = mv.triangleList[off];
                 *                      UInt16 vi1 = mv.triangleList[off + 1];
                 *                      UInt16 vi2 = mv.triangleList[off + 2];
                 *
                 *                      int ind0 = mv.indexList[vi0];
                 *                      int ind1 = mv.indexList[vi1];
                 *                      int ind2 = mv.indexList[vi2];
                 *
                 *                      int v0 = vertices[ind0];
                 *                      int v1 = vertices[ind1];
                 *                      int v2 = vertices[ind2];
                 *                      s.AddTriangle(v0, v1, v2, ChunkedTriangleCollection.TriangleFlagModel);
                 *              }
                 */
            }
            else
            {
                // We got boiuding stuff, that is better
                int   nBoundingVertices = m.boundingVertices.Length / 3;
                int[] vertices          = new int[nBoundingVertices];
                for (uint i = 0; i < nBoundingVertices; i++)
                {
                    uint  off = i * 3;
                    float x   = m.boundingVertices[off];
                    float y   = m.boundingVertices[off + 2];
                    float z   = m.boundingVertices[off + 1];

                    rotate(z, y, dir_x, out z, out y);
                    rotate(x, y, dir_z, out x, out y);
                    rotate(x, z, dir_y, out x, out z);

                    x *= mi.sc;
                    y *= mi.sc;
                    z *= mi.sc;

                    float xx = x + dx;
                    float yy = y + dy;
                    float zz = -z + dz;

                    float finalx = ChunkReader.ZEROPOINT - zz;
                    float finaly = ChunkReader.ZEROPOINT - xx;
                    float finalz = yy;

                    vertices[i] = s.AddVertex(finalx, finaly, finalz);
                }

                int nBoundingTriangles = m.boundingTriangles.Length / 3;
                for (uint i = 0; i < nBoundingTriangles; i++)
                {
                    uint off = i * 3;
                    int  v0  = vertices[m.boundingTriangles[off]];
                    int  v1  = vertices[m.boundingTriangles[off + 1]];
                    int  v2  = vertices[m.boundingTriangles[off + 2]];
                    s.AddTriangle(v0, v1, v2, ChunkedTriangleCollection.TriangleFlagModel, sequence);
                }
            }
        }
        private void AddTriangles(TriangleCollection s, WMOInstance wi)
        {
            float dx = wi.pos.x;
            float dy = wi.pos.y;
            float dz = wi.pos.z;

            float dir_x = wi.dir.z;
            float dir_y = wi.dir.y - 90;
            float dir_z = -wi.dir.x;

            logger.WriteLine("modeli: " + dir_x + " " + dir_y + " " + dir_z);
            WMO wmo = wi.wmo;

            foreach (WMOGroup g in wmo.groups)
            {
                sequence++;
                int[] vertices = new int[g.nVertices];

                float minx = float.MaxValue;
                float miny = float.MaxValue;
                float minz = float.MaxValue;
                float maxx = float.MinValue;
                float maxy = float.MinValue;
                float maxz = float.MinValue;

                for (int i = 0; i < g.nVertices; i++)
                {
                    int off = i * 3;

                    float x = g.vertices[off];
                    float y = g.vertices[off + 2];
                    float z = g.vertices[off + 1];

                    rotate(z, y, dir_x, out z, out y);
                    rotate(x, y, dir_z, out x, out y);
                    rotate(x, z, dir_y, out x, out z);

                    float xx = x + dx;
                    float yy = y + dy;
                    float zz = -z + dz;

                    float finalx = ChunkReader.ZEROPOINT - zz;
                    float finaly = ChunkReader.ZEROPOINT - xx;
                    float finalz = yy;

                    vertices[i] = s.AddVertex(finalx, finaly, finalz);

                    if (finalx < minx)
                    {
                        minx = finalx;
                    }
                    if (finaly < miny)
                    {
                        miny = finalx;
                    }
                    if (finalz < minz)
                    {
                        minz = finalx;
                    }

                    if (finalx > maxx)
                    {
                        maxx = finalx;
                    }
                    if (finaly > maxy)
                    {
                        maxy = finalx;
                    }
                    if (finalz > maxz)
                    {
                        maxz = finalx;
                    }
                }

                logger.WriteLine("AddTriangles: x(" + minx + " - " + maxx + ") y(" + miny + " - " + maxy + ") z(" + minz + " - " + maxz + ")");

                for (int i = 0; i < g.nTriangles; i++)
                {
                    //if ((g.materials[i] & 0x1000) != 0)
                    {
                        int off = i * 3;
                        int i0  = vertices[g.triangles[off]];
                        int i1  = vertices[g.triangles[off + 1]];
                        int i2  = vertices[g.triangles[off + 2]];

                        int t = s.AddTriangle(i0, i1, i2, ChunkedTriangleCollection.TriangleFlagObject, sequence);
                        //if(t != -1) s.SetTriangleExtra(t, g.materials[0], 0, 0);
                    }
                }
            }

            int doodadset = wi.doodadset;

            if (doodadset < wmo.nDoodadSets)
            {
                uint firstDoodad = wmo.doodads[doodadset].firstInstance;
                uint nDoodads    = wmo.doodads[doodadset].nInstances;

                for (uint i = 0; i < nDoodads; i++)
                {
                    uint          d  = firstDoodad + i;
                    ModelInstance mi = wmo.doodadInstances[d];
                    if (mi != null)
                    {
                        //logger.WriteLine("I got model " + mi.model.fileName + " at " + mi.pos);
                        //AddTrianglesGroupDoodads(s, mi, wi.dir, wi.pos, 0.0f); // DOes not work :(
                    }
                }
            }
        }
        private void AddTriangles(TriangleCollection s, MapChunk c)
        {
            int[,] vertices    = new int[9, 9];
            int[,] verticesMid = new int[8, 8];

            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    float x, y, z;
                    ChunkGetCoordForPoint(c, row, col, out x, out y, out z);
                    int index = s.AddVertex(x, y, z);
                    vertices[row, col] = index;
                }
            }

            for (int row = 0; row < 8; row++)
            {
                for (int col = 0; col < 8; col++)
                {
                    float x, y, z;
                    ChunkGetCoordForMiddlePoint(c, row, col, out x, out y, out z);
                    int index = s.AddVertex(x, y, z);
                    verticesMid[row, col] = index;
                }
            }
            for (int row = 0; row < 8; row++)
            {
                for (int col = 0; col < 8; col++)
                {
                    if (!c.isHole(col, row))
                    {
                        int v0   = vertices[row, col];
                        int v1   = vertices[row + 1, col];
                        int v2   = vertices[row + 1, col + 1];
                        int v3   = vertices[row, col + 1];
                        int vMid = verticesMid[row, col];

                        s.AddTriangle(v0, v1, vMid);
                        s.AddTriangle(v1, v2, vMid);
                        s.AddTriangle(v2, v3, vMid);
                        s.AddTriangle(v3, v0, vMid);
                    }
                }
            }

            if (c.haswater)
            {
                // paint the water
                for (int row = 0; row < 9; row++)
                {
                    for (int col = 0; col < 9; col++)
                    {
                        float x, y, z;
                        ChunkGetCoordForPoint(c, row, col, out x, out y, out z);
                        float height = c.water_height[row, col] - 1.5f;
                        int   index  = s.AddVertex(x, y, height);
                        vertices[row, col] = index;
                    }
                }
                for (int row = 0; row < 8; row++)
                {
                    for (int col = 0; col < 8; col++)
                    {
                        if (c.water_flags[row, col] != 0xf)
                        {
                            int v0 = vertices[row, col];
                            int v1 = vertices[row + 1, col];
                            int v2 = vertices[row + 1, col + 1];
                            int v3 = vertices[row, col + 1];

                            s.AddTriangle(v0, v1, v3, ChunkedTriangleCollection.TriangleFlagDeepWater, 1);
                            s.AddTriangle(v1, v2, v3, ChunkedTriangleCollection.TriangleFlagDeepWater, 1);
                        }
                    }
                }
            }
        }
예제 #5
0
        void AddTriangles(TriangleCollection s, ModelInstance mi)
        {
            float dx = mi.pos.x;
            float dy = mi.pos.y;
            float dz = mi.pos.z;


            float dir_x = mi.dir.z;
            float dir_y = mi.dir.y;
            float dir_z = mi.dir.x;


            Model m = mi.model;

            if (m.boundingTriangles == null)
            {
                // /cry no bouding info, revert to normal vertives

                ModelView mv       = m.view[0]; // View number 1 ?!?!
                int[]     vertices = new int[m.vertices.Length / 3];
                for (uint i = 0; i < m.vertices.Length / 3; i++)
                {
                    float x = m.vertices[i * 3];
                    float y = m.vertices[i * 3 + 2];
                    float z = m.vertices[i * 3 + 1];
                    x *= mi.sc;
                    y *= mi.sc;
                    z *= mi.sc;

                    rotate(x, y, dir_z, out x, out y);
                    rotate(y, z, -dir_x, out y, out z);
                    rotate(x, z, (dir_y - 90), out x, out z);



                    float xx = x + dx;
                    float yy = y + dy;
                    float zz = -z + dz;

                    float finalx = ChunkReader.ZEROPOINT - zz;
                    float finaly = ChunkReader.ZEROPOINT - xx;
                    float finalz = yy;

                    vertices[i] = s.AddVertex(finalx, finaly, finalz);
                }


                for (int i = 0; i < mv.triangleList.Length / 3; i++)
                {
                    int    off = i * 3;
                    UInt16 vi0 = mv.triangleList[off];
                    UInt16 vi1 = mv.triangleList[off + 1];
                    UInt16 vi2 = mv.triangleList[off + 2];

                    int ind0 = mv.indexList[vi0];
                    int ind1 = mv.indexList[vi1];
                    int ind2 = mv.indexList[vi2];

                    int v0 = vertices[ind0];
                    int v1 = vertices[ind1];
                    int v2 = vertices[ind2];
                    s.AddTriangle(v0, v1, v2, ChunkedTriangleCollection.TriangleFlagModel);
                }
            }
            else
            {
                // We got boiuding stuff, that is better
                int   nBoundingVertices = m.boundingVertices.Length / 3;
                int[] vertices          = new int[nBoundingVertices];
                for (uint i = 0; i < nBoundingVertices; i++)
                {
                    uint  off = i * 3;
                    float x   = m.boundingVertices[off];
                    float y   = m.boundingVertices[off + 2];
                    float z   = m.boundingVertices[off + 1];
                    x *= mi.sc;
                    y *= mi.sc;
                    z *= mi.sc;

                    rotate(x, y, dir_z, out x, out y);
                    rotate(y, z, -dir_x, out y, out z);
                    rotate(x, z, (dir_y - 90), out x, out z);


                    float xx = x + dx;
                    float yy = y + dy;
                    float zz = -z + dz;

                    float finalx = ChunkReader.ZEROPOINT - zz;
                    float finaly = ChunkReader.ZEROPOINT - xx;
                    float finalz = yy;

                    vertices[i] = s.AddVertex(finalx, finaly, finalz);
                }


                int nBoundingTriangles = m.boundingTriangles.Length / 3;
                for (uint i = 0; i < nBoundingTriangles; i++)
                {
                    uint off = i * 3;
                    int  v0  = vertices[m.boundingTriangles[off]];
                    int  v1  = vertices[m.boundingTriangles[off + 1]];
                    int  v2  = vertices[m.boundingTriangles[off + 2]];
                    s.AddTriangle(v0, v1, v2, ChunkedTriangleCollection.TriangleFlagModel);
                }
            }
        }
예제 #6
0
        void AddTrianglesGroupDoodads(TriangleCollection s, ModelInstance mi, Vec3D world_dir, Vec3D world_off, float rot)
        {
            float dx = mi.pos.x;
            float dy = mi.pos.y;
            float dz = mi.pos.z;

            rotate(dx, dz, rot + 90f, out dx, out dz);


            dx += world_off.x;
            dy += world_off.y;
            dz += world_off.z;


            Quaternion q;

            q.x = -mi.dir.z; q.y = mi.dir.x; q.z = mi.dir.y; q.w = mi.w;
            Matrix4 rotMatrix = new Matrix4();

            rotMatrix.makeQuaternionRotate(q);


            Model m = mi.model;

            if (m.boundingTriangles == null)
            {
                /*
                 * // /cry no bouding info, revert to normal vertices
                 *
                 * ModelView mv = m.view[0]; // View number 1 ?!?!
                 * int[] vertices = new int[m.vertices.Length / 3];
                 * for (uint i = 0; i < m.vertices.Length / 3; i++)
                 * {
                 *  float x = m.vertices[i * 3];
                 *  float y = m.vertices[i * 3 + 2];
                 *  float z = m.vertices[i * 3 + 1];
                 *  x *= mi.sc;
                 *  y *= mi.sc;
                 *  z *= -mi.sc;
                 *
                 *  Vector pos; pos.x = x; pos.y = y; pos.z = z;
                 *  Vector new_pos = rotMatrix.mutiply(pos);
                 *  x = pos.x; y = pos.y; z = pos.z;
                 *
                 *  rotate(x, z, (world_dir.y - 90), out x, out z);
                 *  rotate(y, z, -world_dir.x, out y, out z);
                 *  rotate(x, y, world_dir.z, out x, out y);
                 *
                 *  float xx = x + dx;
                 *  float yy = y + dy;
                 *  float zz = -z + dz;
                 *
                 *  float finalx = ChunkReader.ZEROPOINT - zz;
                 *  float finaly = ChunkReader.ZEROPOINT - xx;
                 *  float finalz = yy;
                 *
                 *  vertices[i] = s.AddVertex(finalx, finaly, finalz);
                 * }
                 *
                 *
                 * for (int i = 0; i < mv.triangleList.Length / 3; i++)
                 * {
                 *  int off = i * 3;
                 *  UInt16 vi0 = mv.triangleList[off];
                 *  UInt16 vi1 = mv.triangleList[off + 1];
                 *  UInt16 vi2 = mv.triangleList[off + 2];
                 *
                 *  int ind0 = mv.indexList[vi0];
                 *  int ind1 = mv.indexList[vi1];
                 *  int ind2 = mv.indexList[vi2];
                 *
                 *  int v0 = vertices[ind0];
                 *  int v1 = vertices[ind1];
                 *  int v2 = vertices[ind2];
                 *  s.AddTriangle(v0, v1, v2, ChunkedTriangleCollection.TriangleFlagModel);
                 * }
                 */
            }
            else
            {
                // We got boiuding stuff, that is better
                int   nBoundingVertices = m.boundingVertices.Length / 3;
                int[] vertices          = new int[nBoundingVertices];

                for (uint i = 0; i < nBoundingVertices; i++)
                {
                    uint  off = i * 3;
                    float x   = m.boundingVertices[off];
                    float y   = m.boundingVertices[off + 2];
                    float z   = m.boundingVertices[off + 1];
                    x *= mi.sc;
                    y *= mi.sc;
                    z *= -mi.sc;

                    Vector pos; pos.x = x; pos.y = y; pos.z = z;
                    Vector new_pos    = rotMatrix.mutiply(pos);
                    x = pos.x; y = pos.y; z = pos.z;

                    rotate(x, z, (world_dir.y - 90), out x, out z);
                    rotate(y, z, -world_dir.x, out y, out z);
                    rotate(x, y, world_dir.z, out x, out y);

                    float xx = x + dx;
                    float yy = y + dy;
                    float zz = -z + dz;

                    float finalx = ChunkReader.ZEROPOINT - zz;
                    float finaly = ChunkReader.ZEROPOINT - xx;
                    float finalz = yy;
                    vertices[i] = s.AddVertex(finalx, finaly, finalz);
                }


                int nBoundingTriangles = m.boundingTriangles.Length / 3;
                for (uint i = 0; i < nBoundingTriangles; i++)
                {
                    uint off = i * 3;
                    int  v0  = vertices[m.boundingTriangles[off]];
                    int  v1  = vertices[m.boundingTriangles[off + 1]];
                    int  v2  = vertices[m.boundingTriangles[off + 2]];
                    s.AddTriangle(v0, v1, v2, ChunkedTriangleCollection.TriangleFlagModel);
                }
            }
        }
예제 #7
0
        void AddTriangles(TriangleCollection s, WMOInstance wi)
        {
            float dx = wi.pos.x;
            float dy = wi.pos.y;
            float dz = wi.pos.z;

            float dir_x = wi.dir.x;
            float dir_y = wi.dir.y;
            float dir_z = wi.dir.z;

            WMO wmo = wi.wmo;

            foreach (WMOGroup g in wmo.groups)
            {
                int[] vertices = new int[g.nVertices];

                for (int i = 0; i < g.nVertices; i++)
                {
                    int off = i * 3;

                    float x = g.vertices[off];
                    float y = g.vertices[off + 2];
                    float z = g.vertices[off + 1];

                    rotate(x, z, (dir_y - 90), out x, out z);
                    rotate(x, y, dir_z, out x, out y);
                    rotate(y, z, -dir_x, out y, out z);

                    float xx = x + dx;
                    float yy = y + dy;
                    float zz = -z + dz;

                    float finalx = ChunkReader.ZEROPOINT - zz;
                    float finaly = ChunkReader.ZEROPOINT - xx;
                    float finalz = yy;

                    vertices[i] = s.AddVertex(finalx, finaly, finalz);
                }
                // Console.WriteLine("nTriangles: " + g.nTriangles);
                for (int i = 0; i < g.nTriangles; i++)
                {
                    //if ((g.materials[i] & 0x1000) != 0)
                    {
                        int off = i * 3;
                        int i0  = vertices[g.triangles[off]];
                        int i1  = vertices[g.triangles[off + 1]];
                        int i2  = vertices[g.triangles[off + 2]];

                        int t = s.AddTriangle(i0, i1, i2, ChunkedTriangleCollection.TriangleFlagObject);
                        //if(t != -1) s.SetTriangleExtra(t, g.materials[0], 0, 0);
                    }
                }
            }

            int doodadset = wi.doodadset;


            if (doodadset < wmo.nDoodadSets)
            {
                uint firstDoodad = wmo.doodads[doodadset].firstInstance;
                uint nDoodads    = wmo.doodads[doodadset].nInstances;

                for (uint i = 0; i < nDoodads; i++)
                {
                    uint          d  = firstDoodad + i;
                    ModelInstance mi = wmo.doodadInstances[d];
                    if (mi != null)
                    {
                        //Console.WriteLine("I got model " + mi.model.fileName + " at " + mi.pos);
                        //AddTrianglesGroupDoodads(s, mi, wi.dir, wi.pos, 0.0f);
                    }
                }
            }
        }