int IComparer.Compare(object x, object y) { Q3BSPFace face1 = (Q3BSPFace)x; Q3BSPFace face2 = (Q3BSPFace)y; return(face1.TextureIndex - face2.TextureIndex); }
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]; } effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); graphics.DrawUserIndexedPrimitives <Q3BSPVertex>( PrimitiveType.TriangleList, vertices, face.StartVertex, face.VertexCount, indices, 0, triCount); pass.End(); } effect.End(); }
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); } bspLogger.WriteLine("No of faces: " + faceCount); return(true); }
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); graphics.VertexDeclaration = vertexDeclaration; 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) { effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); patches[face.PatchIndex].Draw(graphics); pass.End(); } effect.End(); } else { RenderFace(face, effect, graphics); } } } }