Exemplo n.º 1
0
        public void GeneratePatch(Q3BSPVertex[] vList, int vStart, int nVerts, int size_w, int size_h, int level)
        {
            width  = (size_w - 1) / 2;
            height = (size_h - 1) / 2;

            tesselation = level;
            patches     = new Q3BSPBiQuadPatch[width * height];

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Q3BSPBiQuadPatch bpatch     = new Q3BSPBiQuadPatch();
                    Q3BSPVertex[]    ctrlPoints = new Q3BSPVertex[9];
                    for (int r = 0; r < 3; r++)
                    {
                        for (int c = 0; c < 3; c++)
                        {
                            ctrlPoints[r * 3 + c] = vList[vStart + (y * 2 * size_w + x * 2) + r * size_w + c];
                        }
                    }
                    bpatch.Tesselate(ctrlPoints, level);
                    patches[(y * width + x)] = bpatch;
                }
            }
        }
Exemplo n.º 2
0
        public void Tesselate(Q3BSPVertex[] controls, int level)
        {
            float px, py;

            Q3BSPVertex[] temp = new Q3BSPVertex[3];

            tesLevel = level;
            vertices = new Q3BSPVertex[(level + 1) * (level + 1)];

            for (int v = 0; v <= level; v++)
            {
                px = (float)v / level;
                float a = ((1.0f - px) * (1.0f - px));
                float b = ((1.0f - px) * px * 2);
                float c = px * px;

                vertices[v] = controls[0] * a + controls[3] * b + controls[6] * c;
            }

            for (int u = 1; u <= level; u++)
            {
                py = (float)u / level;
                float a = ((1.0f - py) * (1.0f - py));
                float b = ((1.0f - py) * py * 2);
                float c = py * py;

                temp[0] = controls[0] * a + controls[1] * b + controls[2] * c;
                temp[1] = controls[3] * a + controls[4] * b + controls[5] * c;
                temp[2] = controls[6] * a + controls[7] * b + controls[8] * c;

                for (int v = 0; v <= level; v++)
                {
                    px = (float)v / level;

                    a = (1.0f - px) * (1.0f - px);
                    b = (1.0f - px) * px * 2;
                    c = px * px;

                    vertices[u * (level + 1) + v] = temp[0] * a + temp[1] * b + temp[2] * c;
                }
            }

            indices = new int[level * (level + 1) * 2];
            for (int row = 0; row < level; row++)
            {
                for (int pt = 0; pt <= level; pt++)
                {
                    indices[(row * (level + 1) + pt) * 2 + 1] = row * (level + 1) + pt;
                    indices[(row * (level + 1) + pt) * 2]     = (row + 1) * (level + 1) + pt;
                }
            }
        }
Exemplo n.º 3
0
        private bool LoadVertexLump(Q3BSPDirEntry dir, BinaryReader fileReader)
        {
            int vertexCount = dir.Length / Q3BSPConstants.sizeVertex;

            vertices = new Q3BSPVertex[vertexCount];
            for (int i = 0; i < vertexCount; i++)
            {
                vertices[i] = Q3BSPVertex.FromStream(fileReader);
            }

            bspLogger.WriteLine("No of vertices: " + vertexCount);
            return(true);
        }
Exemplo n.º 4
0
        public void InitializeStatic(GraphicsDevice graphics)
        {
            List <short>   indexList              = new List <short>();
            List <short[]> indexBufferList        = new List <short[]>();
            List <Vector2> textureAndLightMapList = new List <Vector2>();
            int            lastTextureIndex       = 0;
            int            lastLightMapIndex      = 0;

            Q3BSPFace[] tempFaces = new Q3BSPFace[faces.Length];
            faces.CopyTo(tempFaces, 0);

            System.Array.Sort(tempFaces, new Q3BSPFaceComparer());

            foreach (Q3BSPFace face in tempFaces)
            {
                // The current index buffer is done and needs to be refreshed.
                if ((face.TextureIndex != lastTextureIndex || face.LightMapIndex != lastLightMapIndex) && ((indexList.Count != 0 || indexList.Count > int.MaxValue)))
                {
                    indexBufferList.Add(indexList.ToArray());
                    textureAndLightMapList.Add(new Vector2(lastTextureIndex, lastLightMapIndex));
                    indexList.Clear();
                }

                if (face.FaceType == Q3BSPFaceType.Patch)
                {
                    Q3BSPVertex[] patchVertices  = patches[face.PatchIndex].GetVertices();
                    short[]       patchIndices   = patches[face.PatchIndex].GetIndices();
                    Q3BSPVertex[] newVertexArray = new Q3BSPVertex[vertices.Length + patchVertices.Length];

                    vertices.CopyTo(newVertexArray, 0);
                    patchVertices.CopyTo(newVertexArray, vertices.Length);

                    foreach (short index in patchIndices)
                    {
                        indexList.Add((short)(vertices.Length + index));
                    }

                    vertices = newVertexArray;
                }

                for (int i = 0; i < face.MeshVertexCount; ++i)
                {
                    indexList.Add((short)(face.StartVertex + meshVertices[face.StartMeshVertex + i]));
                }

                lastTextureIndex  = face.TextureIndex;
                lastLightMapIndex = face.LightMapIndex;
            }

            // Add the last index buffer
            indexBufferList.Add(indexList.ToArray());
            textureAndLightMapList.Add(new Vector2(lastTextureIndex, lastLightMapIndex));
            indexList.Clear();

            // Set the vertex and index buffers
            vertexBuffer = new VertexBuffer(graphics, typeof(Q3BSPVertex), vertices.Length, BufferUsage.WriteOnly);
            vertexBuffer.SetData <Q3BSPVertex>(vertices);

            indexBuffers       = new IndexBuffer[indexBufferList.Count];
            indexBufferLengths = new int[indexBufferList.Count];
            for (int i = 0; i < indexBuffers.Length; i++)
            {
                indexBuffers[i] = new IndexBuffer(graphics, typeof(short), indexBufferList[i].Length, BufferUsage.WriteOnly);
                indexBuffers[i].SetData <short>(indexBufferList[i]);
                indexBufferLengths[i] = indexBufferList[i].Length;
            }

            // Set the texture and lightmap array
            textureAndLightMapIndices = textureAndLightMapList.ToArray();
        }