示例#1
0
        private bool LoadFaceLump(Q3BSPDirEntry dir, BinaryReader fileReader)
        {
            int faceCount = dir.Length / Q3BSPConstants.sizeFace;

            faces       = new Q3BSPFace[faceCount];
            facesToDraw = new bool[faceCount];
            for (int i = 0; i < faceCount; i++)
            {
                faces[i] = Q3BSPFace.FromStream(fileReader);
            }
            return(true);
        }
示例#2
0
        private void RenderFace(Q3BSPFace face, Effect effect, GraphicsDevice graphics)
        {
            int[] indices;
            int   triCount = face.MeshVertexCount / 3;

            indices = new int[face.MeshVertexCount];
            for (int i = 0; i < face.MeshVertexCount; i++)
            {
                indices[i] = meshVertices[face.StartMeshVertex + i];
            }
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphics.DrawUserIndexedPrimitives <Q3BSPVertex>(
                    PrimitiveType.TriangleList,
                    vertices,
                    face.StartVertex,
                    face.VertexCount,
                    indices,
                    0,
                    triCount);
            }
        }
示例#3
0
        public void RenderLevel(Vector3 cameraPosition, Matrix viewMatrix, Matrix projMatrix, GameTime gameTime, GraphicsDevice graphics)
        {
            int cameraLeaf    = GetCameraLeaf(cameraPosition);
            int cameraCluster = leafs[cameraLeaf].Cluster;

            if (0 > cameraCluster)
            {
                return;
            }

            ResetFacesToDraw();

            BoundingFrustum frustum      = new BoundingFrustum(viewMatrix * projMatrix);
            ArrayList       visibleFaces = new ArrayList();

            foreach (Q3BSPLeaf leaf in leafs)
            {
                if (!visData.FastIsClusterVisible(cameraCluster, leaf.Cluster))
                {
                    continue;
                }

                if (!frustum.Intersects(leaf.Bounds))
                {
                    //continue;
                }

                for (int i = 0; i < leaf.LeafFaceCount; i++)
                {
                    int       faceIndex = leafFaces[leaf.StartLeafFace + i];
                    Q3BSPFace face      = faces[faceIndex];
                    if (4 != face.FaceType && !facesToDraw[faceIndex])
                    {
                        facesToDraw[faceIndex] = true;
                        visibleFaces.Add(face);
                    }
                }
            }

            if (0 >= visibleFaces.Count)
            {
                return;
            }

            Q3BSPFaceComparer fc = new Q3BSPFaceComparer();

            visibleFaces.Sort(fc);

            Matrix matrixWorldViewProjection = viewMatrix * projMatrix;
            Effect effect;

            foreach (Q3BSPFace face in visibleFaces)
            {
                effect = shaderManager.GetEffect(face.TextureIndex, face.LightMapIndex);
                if (null != effect)
                {
                    effect.Parameters["WorldViewProj"].SetValue(matrixWorldViewProjection);
                    effect.Parameters["WorldView"].SetValue(viewMatrix);
                    if (Q3BSPConstants.faceTypePatch == face.FaceType)
                    {
                        foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                        {
                            pass.Apply();
                            patches[face.PatchIndex].Draw(graphics);
                        }
                    }
                    else
                    {
                        RenderFace(face, effect, graphics);
                    }
                }
            }
        }