public void UpdateCamDist(CameraSceneObject camera) { float dx, dy, dz; dx = center.x - camera.Position.x; dy = center.y - camera.Position.y; dz = center.z - camera.Position.z; camDist = (float)System.Math.Sqrt(dx * dx + dy * dy + dz * dz); }
public override void Render(IGraphics graphics, CameraSceneObject camera) { graphics.Lighting = false; var oldMatrix = graphics.WorldMatrix; graphics.WorldMatrix = Matrix.Translation(camera.Position.x, camera.Position.y, camera.Position.z); graphics.Filtering = false; graphics.RenderTriangleStrip(VertexPoolIndex, 0, 8, TextureIndex, -1); graphics.RenderTriangleStrip(VertexPoolIndex, 8, 8, TextureIndex, -1); graphics.Filtering = true; graphics.WorldMatrix = oldMatrix; }
public override void Render(IGraphics graphics, CameraSceneObject camera) { int i, j; float d; Plane plane; bool[] pvs; ArrayList visFaces; BspFace face; bool visible; bool firstAlphaFace; using (Profiler.StartSample("HLBSPMap.Render")) { // create visible faces list visFaces = new ArrayList(); // add faces to visible faces list if (BSPRendering) { // get camera node using (Profiler.StartSample("get camera leaf")) { i = 0; while (i >= 0) { plane = Planes[Nodes[i].plane]; d = plane.Distance(camera.Position); if (d >= 0.0f) { i = Nodes[i].frontChild; } else { i = Nodes[i].backChild; } } } // get pvs for current leaf (~i => -(i + 1)) using (Profiler.StartSample("decompress pvs")) { i = Leaves[~i].pvs; pvs = DecompressPvs(i); } // add visible faces using (Profiler.StartSample("add visible faces")) { for (i = 0; i < Leaves.Length; i++) // go through all leaves { visible = i == 0; if (!visible) { visible = pvs[i - 1]; } if (visible) // if leaf is visible { for (j = 0; j < Leaves[i].numMarkFaces; j++) // go through all faces of leaf .. { face = Faces[MarkFaces[Leaves[i].firstMarkFace + j]]; if (face.texture < 0) { continue; } if (face.model) { continue; } visFaces.Add(face); // .. and add them } } } } // add all model faces using (Profiler.StartSample("add model faces")) { visFaces.AddRange(ModelFaces); } } else { using (Profiler.StartSample("add all faces")) { for (i = 0; i < Faces.Length; i++) { face = Faces[i]; if (face.texture < 0) { continue; } visFaces.Add(face); } } } // perform frustum culling on visible faces if (FrustumCulling) { using (Profiler.StartSample("frustum culling")) { for (i = visFaces.Count - 1; i >= 0; i--) { face = (BspFace)visFaces[i]; if (!camera.InsideFrustum(face.center, face.radius)) { visFaces.RemoveAt(i); } } } } // update camera distance of visible faces using (Profiler.StartSample("update face distance")) { for (i = 0; i < visFaces.Count; i++) { ((BspFace)visFaces[i]).UpdateCamDist(camera); } } // sort visible faces using (Profiler.StartSample("sort faces")) { visFaces.Sort(); } // render visible faces + sky somewher ebetween the transparant and the solid faces using (Profiler.StartSample("render faces")) { firstAlphaFace = false; for (i = 0; i < visFaces.Count; i++) { face = (BspFace)visFaces[i]; if (face.IsTransparant()) { if (!firstAlphaFace && Sky != null) { // render skybox using (Profiler.StartSample("render sky")) { Sky.Render(graphics, camera); } firstAlphaFace = true; } graphics.AlphaBlending = true; graphics.Alpha = face.alpha; graphics.TextureAlpha = face.textureAlpha; } else { graphics.AlphaBlending = false; } graphics.Lighting = face.lightmap >= 0; graphics.RenderTriangleFan(VertexPoolIndex, face.firstVertex, face.numVertices, face.texture, face.lightmap); } if (!firstAlphaFace && Sky != null) { // render skybox using (Profiler.StartSample("render sky")) { Sky.Render(graphics, camera); } } } } }
public virtual void Render(IGraphics graphics, CameraSceneObject camera) { }