示例#1
0
文件: Renderer.cs 项目: vsugrob/Q3Bot
        private int QSortPartition(int start, int end)
        {
            ReadOnlyCollection <Q3BspFace> faces = map.Faces;
            int           texture  = faces [visibleFaces [end]].texture;
            int           lm_index = faces [visibleFaces [end]].lm_index;
            Q3BspFaceType type     = faces[visibleFaces [end]].type;
            int           i        = start - 1;

            for (int j = start; j < end; j++)
            {
                if (faces [visibleFaces [j]].texture == texture &&
                    faces [visibleFaces [j]].lm_index == lm_index &&
                    faces [visibleFaces [j]].type <= type)
                {
                    i++;
                    SwapFaces(i, j);
                }
                else if (faces [visibleFaces [j]].texture == texture &&
                         faces [visibleFaces [j]].lm_index <= lm_index)
                {
                    i++;
                    SwapFaces(i, j);
                }
                else if (faces [visibleFaces [j]].texture < texture)
                {
                    i++;
                    SwapFaces(i, j);
                }
            }

            SwapFaces(i + 1, end);

            return(i + 1);
        }
示例#2
0
        public void FromUnsafe(Q3BspFaceUnsafe s, Q3BspVertex [] vertices)
        {
            texture     = s.texture;
            effect      = s.effect;
            type        = ( Q3BspFaceType )s.type;
            vertex      = s.vertex;
            n_vertexes  = s.n_vertexes;
            meshvert    = s.meshvert;
            n_meshverts = s.n_meshverts;
            n_triangles = s.n_meshverts / 3;
            lm_index    = s.lm_index;

            lm_start = new int [2];
            lm_size  = new int [2];
            lm_vecs  = new Vector3 [2];

            unsafe {
                lm_start [0] = s.lm_start [0];
                lm_start [1] = s.lm_start [1];
                lm_size [0]  = s.lm_size [0];
                lm_size [1]  = s.lm_size [1];
                lm_origin    = new Vector3(s.lm_origin [0], s.lm_origin [2], s.lm_origin [1]);
                lm_vecs [0]  = new Vector3(s.lm_vecs [0], s.lm_vecs [1], s.lm_vecs [2]);
                lm_vecs [1]  = new Vector3(s.lm_vecs [3], s.lm_vecs [4], s.lm_vecs [5]);
                // swapping axes
                normal = new Vector3(s.normal [0], s.normal [2], s.normal [1]);
                width  = s.size [0];
                height = s.size [1];
            }

            if (type == Q3BspFaceType.Patch)
            {
                Q3BspPatch q3patch = new Q3BspPatch();

                int patch_size_x       = (width - 1) / 2;
                int patch_size_y       = (height - 1) / 2;
                int num_bezier_patches = patch_size_y * patch_size_x;

                q3patch.size   = num_bezier_patches;
                q3patch.bezier = new Q3BezierPatch [q3patch.size];

                int patchIndex = 0;
                int ii, n, j, nn;

                for (ii = 0, n = 0; n < patch_size_x; n++, ii = 2 * n)
                {
                    for (j = 0, nn = 0; nn < patch_size_y; nn++, j = 2 * nn)
                    {
                        Q3BezierPatch bezier = new Q3BezierPatch();

                        for (int ctr = 0, index = 0; ctr < 3; ctr++)
                        {
                            int pos  = ctr * width;
                            int vIdx = vertex + ii + width * j + pos;

                            bezier.controls [index++] = vertices [vIdx].Copy();
                            bezier.controls [index++] = vertices [vIdx + 1].Copy();
                            bezier.controls [index++] = vertices [vIdx + 2].Copy();
                        }

                        bezier.Tessellate(5);
                        q3patch.bezier [patchIndex] = bezier;
                        patchIndex++;
                    }
                }

                patch = q3patch;
            }
        }