Ejemplo n.º 1
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)
            {
            }
            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);
                }
            }
        }