/// <summary> /// Adds an object to the list of visible objects /// only maintained for players /// </summary> /// <returns>TRUE if object was previously not visible, and added to the visible list</returns> public bool AddVisibleObject(PhysicsObj obj) { rwLock.EnterWriteLock(); try { if (VisibleObjects.ContainsKey(obj.ID)) { return(false); } if (InitialClamp && !KnownObjects.ContainsKey(obj.ID)) { var distSq = PhysicsObj.Position.Distance2DSquared(obj.Position); if (distSq > InitialClamp_DistSq) { return(false); } } //Console.WriteLine($"{PhysicsObj.Name}.AddVisibleObject({obj.Name})"); VisibleObjects.TryAdd(obj.ID, obj); if (obj.WeenieObj.IsMonster) { obj.ObjMaint.AddVisibleTarget(PhysicsObj, false); } return(true); } finally { rwLock.ExitWriteLock(); } }
public void DropdownSelectGraph() { switch (graphDropdown.value) { case 0: displayOption = VisibleObjects.System; cube.GetComponent <MeshRenderer>().enabled = true; cube.GetComponent <BoxCollider>().enabled = true; graphableValuesGraph.SetActive(false); break; case 1: displayOption = VisibleObjects.GraphableGraph; cube.GetComponent <MeshRenderer>().enabled = false; cube.GetComponent <BoxCollider>().enabled = false; graphableValuesGraph.SetActive(true); break; } for (int i = 0; i < valuesDropdowns.Length; i++) { valuesDropdowns[i].interactable = displayOption.Equals(VisibleObjects.GraphableGraph); } baseDropdown.interactable = displayOption.Equals(VisibleObjects.GraphableGraph); ResetDisplays(); }
/// <summary> /// Clears all of the ObjMaint tables for an object /// </summary> private void RemoveAllObjects() { KnownObjects.Clear(); VisibleObjects.Clear(); DestructionQueue.Clear(); KnownPlayers.Clear(); VisibleTargets.Clear(); }
/// <summary> /// Removes an object from the visible objects list /// only run for players, and also removes the player from /// the object's visible targets list /// </summary> public bool RemoveVisibleObject(PhysicsObj obj, bool inverseTarget = true) { var removed = VisibleObjects.Remove(obj.ID); if (inverseTarget) { obj.ObjMaint.RemoveVisibleTarget(PhysicsObj); } return(removed); }
public bool VisibleObjectsContainsKey(uint key) { rwLock.EnterReadLock(); try { return(VisibleObjects.ContainsKey(key)); } finally { rwLock.ExitReadLock(); } }
public List <KeyValuePair <uint, PhysicsObj> > GetVisibleObjectsWhere(Func <KeyValuePair <uint, PhysicsObj>, bool> predicate) { rwLock.EnterReadLock(); try { return(VisibleObjects.Where(predicate).ToList()); } finally { rwLock.ExitReadLock(); } }
public override void InitializeVisibility() { ObjectsSortedByStart = StaticObjectStates.Select((x, i) => new { Index = i, Distance = x.StartingDistance }).OrderBy(x => x.Distance).Select(x => x.Index).ToArray(); ObjectsSortedByEnd = StaticObjectStates.Select((x, i) => new { Index = i, Distance = x.EndingDistance }).OrderBy(x => x.Distance).Select(x => x.Index).ToArray(); ObjectsSortedByStartPointer = 0; ObjectsSortedByEndPointer = 0; double p = CameraTrackFollower.TrackPosition + Camera.Alignment.Position.Z; foreach (ObjectState state in StaticObjectStates.Where(recipe => recipe.StartingDistance <= p + Camera.ForwardViewingDistance & recipe.EndingDistance >= p - Camera.BackwardViewingDistance)) { VisibleObjects.ShowObject(state, ObjectType.Static); } }
/// <summary> /// Removes an object from the visible objects list /// only run for players /// and also removes the player from the object's visible targets list /// </summary> public bool RemoveVisibleObject(PhysicsObj obj, bool inverseTarget = true) { rwLock.EnterWriteLock(); try { var removed = VisibleObjects.Remove(obj.ID, out _); if (inverseTarget) { obj.ObjMaint.RemoveVisibleTarget(PhysicsObj); } return(removed); } finally { rwLock.ExitWriteLock(); } }
public void DropdownSelectGraph() { switch (graphDropdown.value) { case 0: displayOption = VisibleObjects.System; system.SetActive(true); phasorGraph.SetActive(false); graphableValuesGraph.SetActive(false); break; case 1: displayOption = VisibleObjects.PhasorGraph; system.SetActive(false); phasorGraph.SetActive(true); graphableValuesGraph.SetActive(false); break; case 2: displayOption = VisibleObjects.GraphableGraph; system.SetActive(false); phasorGraph.SetActive(false); graphableValuesGraph.SetActive(true); break; } for (int i = 0; i < valuesDropdowns.Length; i++) { valuesDropdowns[i].interactable = displayOption.Equals(VisibleObjects.GraphableGraph); } baseDropdown.interactable = displayOption.Equals(VisibleObjects.GraphableGraph); ResetDisplays(); }
public void Faded() { Monster m; Owner.DeadMembers.Enqueue(this); Owner.DyingMembers.TryRemove(UID, out m); Common.MapService.RemoveFlag(MapID, X, Y, TinyMap.TileFlag.Monster); var packet = GeneralActionPacket.Create(UID, DataAction.RemoveEntity, 0, 0); foreach (var p in Map.QueryPlayers(this)) { if (p.VisibleObjects.ContainsKey(UID)) { uint x; p.Send(packet); p.VisibleObjects.TryRemove(UID, out x); } if (VisibleObjects.ContainsKey(p.UID)) { uint x; VisibleObjects.TryRemove(p.UID, out x); } } }
public bool IsChildNextToMargin(Gtk.PositionType margin, DockObject obj, bool visibleOnly) { if (type == DockGroupType.Tabbed) { return(true); } else if (type == DockGroupType.Horizontal) { if (margin == PositionType.Top || margin == PositionType.Bottom) { return(true); } int i = visibleOnly ? VisibleObjects.IndexOf(obj) : Objects.IndexOf(obj); if (margin == PositionType.Left && i == 0) { return(true); } if (margin == PositionType.Right && i == (visibleOnly ? VisibleObjects.Count - 1 : Objects.Count - 1)) { return(true); } } else if (type == DockGroupType.Vertical) { if (margin == PositionType.Left || margin == PositionType.Right) { return(true); } int i = visibleOnly ? VisibleObjects.IndexOf(obj) : Objects.IndexOf(obj); if (margin == PositionType.Top && i == 0) { return(true); } if (margin == PositionType.Bottom && i == (visibleOnly ? VisibleObjects.Count - 1 : Objects.Count - 1)) { return(true); } } return(false); }
// render scene internal void RenderScene(double TimeElapsed) { // initialize ResetOpenGlState(); if (OptionWireFrame) { if (Program.CurrentRoute.CurrentFog.Start < Program.CurrentRoute.CurrentFog.End) { const float fogDistance = 600.0f; float n = (fogDistance - Program.CurrentRoute.CurrentFog.Start) / (Program.CurrentRoute.CurrentFog.End - Program.CurrentRoute.CurrentFog.Start); float cr = n * inv255 * Program.CurrentRoute.CurrentFog.Color.R; float cg = n * inv255 * Program.CurrentRoute.CurrentFog.Color.G; float cb = n * inv255 * Program.CurrentRoute.CurrentFog.Color.B; GL.ClearColor(cr, cg, cb, 1.0f); } else { GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f); } } GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); // set up camera CurrentViewMatrix = Matrix4D.LookAt(Vector3.Zero, new Vector3(Camera.AbsoluteDirection.X, Camera.AbsoluteDirection.Y, -Camera.AbsoluteDirection.Z), new Vector3(Camera.AbsoluteUp.X, Camera.AbsoluteUp.Y, -Camera.AbsoluteUp.Z)); GL.Light(LightName.Light0, LightParameter.Position, new[] { (float)Lighting.OptionLightPosition.X, (float)Lighting.OptionLightPosition.Y, (float)-Lighting.OptionLightPosition.Z, 0.0f }); // fog double fd = Program.CurrentRoute.NextFog.TrackPosition - Program.CurrentRoute.PreviousFog.TrackPosition; if (fd != 0.0) { float fr = (float)((World.CameraTrackFollower.TrackPosition - Program.CurrentRoute.PreviousFog.TrackPosition) / fd); float frc = 1.0f - fr; Program.CurrentRoute.CurrentFog.Start = Program.CurrentRoute.PreviousFog.Start * frc + Program.CurrentRoute.NextFog.Start * fr; Program.CurrentRoute.CurrentFog.End = Program.CurrentRoute.PreviousFog.End * frc + Program.CurrentRoute.NextFog.End * fr; Program.CurrentRoute.CurrentFog.Color.R = (byte)(Program.CurrentRoute.PreviousFog.Color.R * frc + Program.CurrentRoute.NextFog.Color.R * fr); Program.CurrentRoute.CurrentFog.Color.G = (byte)(Program.CurrentRoute.PreviousFog.Color.G * frc + Program.CurrentRoute.NextFog.Color.G * fr); Program.CurrentRoute.CurrentFog.Color.B = (byte)(Program.CurrentRoute.PreviousFog.Color.B * frc + Program.CurrentRoute.NextFog.Color.B * fr); } else { Program.CurrentRoute.CurrentFog = Program.CurrentRoute.PreviousFog; } // render background GL.Disable(EnableCap.DepthTest); Program.CurrentRoute.UpdateBackground(TimeElapsed, false); if (OptionEvents) { RenderEvents(); } // fog float aa = Program.CurrentRoute.CurrentFog.Start; float bb = Program.CurrentRoute.CurrentFog.End; if (aa < bb & aa < Program.CurrentRoute.CurrentBackground.BackgroundImageDistance) { OptionFog = true; Fog.Start = aa; Fog.End = bb; Fog.Color = Program.CurrentRoute.CurrentFog.Color; SetFogForImmediateMode(); } else { OptionFog = false; } // world layer // opaque face ResetOpenGlState(); foreach (FaceState face in VisibleObjects.OpaqueFaces) { if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Activate(); ResetShader(DefaultShader); RenderFace(DefaultShader, face); DefaultShader.Deactivate(); } else { RenderFaceImmediateMode(face); } } // alpha face ResetOpenGlState(); VisibleObjects.SortPolygonsInAlphaFaces(); if (Interface.CurrentOptions.TransparencyMode == TransparencyMode.Performance) { SetBlendFunc(); SetAlphaFunc(AlphaFunction.Greater, 0.0f); GL.DepthMask(false); foreach (FaceState face in VisibleObjects.AlphaFaces) { if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Activate(); ResetShader(DefaultShader); RenderFace(DefaultShader, face); DefaultShader.Deactivate(); } else { RenderFaceImmediateMode(face); } } } else { UnsetBlendFunc(); SetAlphaFunc(AlphaFunction.Equal, 1.0f); GL.DepthMask(true); foreach (FaceState face in VisibleObjects.AlphaFaces) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].BlendMode == MeshMaterialBlendMode.Normal && face.Object.Prototype.Mesh.Materials[face.Face.Material].GlowAttenuationData == 0) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].Color.A == 255) { if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Activate(); ResetShader(DefaultShader); RenderFace(DefaultShader, face); DefaultShader.Deactivate(); } else { RenderFaceImmediateMode(face); } } } } SetBlendFunc(); SetAlphaFunc(AlphaFunction.Less, 1.0f); GL.DepthMask(false); bool additive = false; foreach (FaceState face in VisibleObjects.AlphaFaces) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].BlendMode == MeshMaterialBlendMode.Additive) { if (!additive) { UnsetAlphaFunc(); additive = true; } if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Activate(); ResetShader(DefaultShader); RenderFace(DefaultShader, face); DefaultShader.Deactivate(); } else { RenderFaceImmediateMode(face); } } else { if (additive) { SetAlphaFunc(); additive = false; } if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Activate(); ResetShader(DefaultShader); RenderFace(DefaultShader, face); DefaultShader.Deactivate(); } else { RenderFaceImmediateMode(face); } } } } // render overlays ResetOpenGlState(); OptionLighting = false; OptionFog = false; UnsetAlphaFunc(); GL.Disable(EnableCap.DepthTest); RenderOverlays(); OptionLighting = true; }
public List <MapObject> RetreivePlayerTargets(Predicate <MapObject> predicate) { return(VisibleObjects.ToList().FindAll(n => n is Aisling && predicate(n))); }
// render scene internal void RenderScene(double TimeElapsed) { ReleaseResources(); // initialize ResetOpenGlState(); if (OptionWireFrame) { if (Program.CurrentRoute.CurrentFog.Start < Program.CurrentRoute.CurrentFog.End) { const float fogDistance = 600.0f; float n = (fogDistance - Program.CurrentRoute.CurrentFog.Start) / (Program.CurrentRoute.CurrentFog.End - Program.CurrentRoute.CurrentFog.Start); float cr = n * inv255 * Program.CurrentRoute.CurrentFog.Color.R; float cg = n * inv255 * Program.CurrentRoute.CurrentFog.Color.G; float cb = n * inv255 * Program.CurrentRoute.CurrentFog.Color.B; GL.ClearColor(cr, cg, cb, 1.0f); } else { GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f); } } GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); // set up camera CurrentViewMatrix = Matrix4D.LookAt(Vector3.Zero, new Vector3(Camera.AbsoluteDirection.X, Camera.AbsoluteDirection.Y, -Camera.AbsoluteDirection.Z), new Vector3(Camera.AbsoluteUp.X, Camera.AbsoluteUp.Y, -Camera.AbsoluteUp.Z)); TransformedLightPosition = new Vector3(Lighting.OptionLightPosition.X, Lighting.OptionLightPosition.Y, -Lighting.OptionLightPosition.Z); TransformedLightPosition.Transform(CurrentViewMatrix); if (!AvailableNewRenderer) { GL.Light(LightName.Light0, LightParameter.Position, new[] { (float)TransformedLightPosition.X, (float)TransformedLightPosition.Y, (float)TransformedLightPosition.Z, 0.0f }); } Lighting.OptionLightingResultingAmount = (Lighting.OptionAmbientColor.R + Lighting.OptionAmbientColor.G + Lighting.OptionAmbientColor.B) / 480.0f; if (Lighting.OptionLightingResultingAmount > 1.0f) { Lighting.OptionLightingResultingAmount = 1.0f; } // fog double fd = Program.CurrentRoute.NextFog.TrackPosition - Program.CurrentRoute.PreviousFog.TrackPosition; if (fd != 0.0) { float fr = (float)((CameraTrackFollower.TrackPosition - Program.CurrentRoute.PreviousFog.TrackPosition) / fd); float frc = 1.0f - fr; Program.CurrentRoute.CurrentFog.Start = Program.CurrentRoute.PreviousFog.Start * frc + Program.CurrentRoute.NextFog.Start * fr; Program.CurrentRoute.CurrentFog.End = Program.CurrentRoute.PreviousFog.End * frc + Program.CurrentRoute.NextFog.End * fr; Program.CurrentRoute.CurrentFog.Color.R = (byte)(Program.CurrentRoute.PreviousFog.Color.R * frc + Program.CurrentRoute.NextFog.Color.R * fr); Program.CurrentRoute.CurrentFog.Color.G = (byte)(Program.CurrentRoute.PreviousFog.Color.G * frc + Program.CurrentRoute.NextFog.Color.G * fr); Program.CurrentRoute.CurrentFog.Color.B = (byte)(Program.CurrentRoute.PreviousFog.Color.B * frc + Program.CurrentRoute.NextFog.Color.B * fr); if (!Program.CurrentRoute.CurrentFog.IsLinear) { Program.CurrentRoute.CurrentFog.Density = (byte)(Program.CurrentRoute.PreviousFog.Density * frc + Program.CurrentRoute.NextFog.Density * fr); } } else { Program.CurrentRoute.CurrentFog = Program.CurrentRoute.PreviousFog; } // render background GL.Disable(EnableCap.DepthTest); Program.CurrentRoute.UpdateBackground(TimeElapsed, false); if (OptionEvents) { RenderEvents(); } // fog float aa = Program.CurrentRoute.CurrentFog.Start; float bb = Program.CurrentRoute.CurrentFog.End; if (aa < bb & aa < Program.CurrentRoute.CurrentBackground.BackgroundImageDistance) { OptionFog = true; Fog.Start = aa; Fog.End = bb; Fog.Color = Program.CurrentRoute.CurrentFog.Color; Fog.Density = Program.CurrentRoute.CurrentFog.Density; Fog.IsLinear = Program.CurrentRoute.CurrentFog.IsLinear; Fog.SetForImmediateMode(); } else { OptionFog = false; } // world layer // opaque face if (AvailableNewRenderer) { //Setup the shader for rendering the scene DefaultShader.Activate(); if (OptionLighting) { DefaultShader.SetIsLight(true); DefaultShader.SetLightPosition(TransformedLightPosition); DefaultShader.SetLightAmbient(Lighting.OptionAmbientColor); DefaultShader.SetLightDiffuse(Lighting.OptionDiffuseColor); DefaultShader.SetLightSpecular(Lighting.OptionSpecularColor); DefaultShader.SetLightModel(Lighting.LightModel); } if (OptionFog) { DefaultShader.SetIsFog(true); DefaultShader.SetFog(Fog); } DefaultShader.SetTexture(0); DefaultShader.SetCurrentProjectionMatrix(CurrentProjectionMatrix); } ResetOpenGlState(); foreach (FaceState face in VisibleObjects.OpaqueFaces) { face.Draw(); } // alpha face ResetOpenGlState(); VisibleObjects.SortPolygonsInAlphaFaces(); if (Interface.CurrentOptions.TransparencyMode == TransparencyMode.Performance) { SetBlendFunc(); SetAlphaFunc(AlphaFunction.Greater, 0.0f); GL.DepthMask(false); foreach (FaceState face in VisibleObjects.AlphaFaces) { face.Draw(); } } else { UnsetBlendFunc(); SetAlphaFunc(AlphaFunction.Equal, 1.0f); GL.DepthMask(true); foreach (FaceState face in VisibleObjects.AlphaFaces) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].BlendMode == MeshMaterialBlendMode.Normal && face.Object.Prototype.Mesh.Materials[face.Face.Material].GlowAttenuationData == 0) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].Color.A == 255) { face.Draw(); } } } SetBlendFunc(); SetAlphaFunc(AlphaFunction.Less, 1.0f); GL.DepthMask(false); bool additive = false; foreach (FaceState face in VisibleObjects.AlphaFaces) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].BlendMode == MeshMaterialBlendMode.Additive) { if (!additive) { UnsetAlphaFunc(); additive = true; } face.Draw(); } else { if (additive) { SetAlphaFunc(); additive = false; } face.Draw(); } } } // render overlays if (AvailableNewRenderer) { DefaultShader.Deactivate(); } ResetOpenGlState(); OptionLighting = false; OptionFog = false; UnsetAlphaFunc(); GL.Disable(EnableCap.DepthTest); SetBlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); //FIXME: Remove when text switches between two renderer types RenderOverlays(); OptionLighting = true; }
// render scene internal void RenderScene() { // initialize ResetOpenGlState(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); CurrentViewMatrix = Matrix4D.LookAt(Vector3.Zero, new Vector3(Camera.AbsoluteDirection.X, Camera.AbsoluteDirection.Y, -Camera.AbsoluteDirection.Z), new Vector3(Camera.AbsoluteUp.X, Camera.AbsoluteUp.Y, -Camera.AbsoluteUp.Z)); OptionFog = false; if (OptionCoordinateSystem) { Cube.Draw(redAxisVAO, Vector3.Zero, Vector3.Forward, Vector3.Down, Vector3.Right, new Vector3(100.0, 0.01, 0.01), Camera.AbsolutePosition, null); Cube.Draw(greenAxisVAO, Vector3.Zero, Vector3.Forward, Vector3.Down, Vector3.Right, new Vector3(0.01, 100.0, 0.01), Camera.AbsolutePosition, null); Cube.Draw(blueAxisVAO, Vector3.Zero, Vector3.Forward, Vector3.Down, Vector3.Right, new Vector3(0.01, 0.01, 100.0), Camera.AbsolutePosition, null); } // opaque face if (Interface.CurrentOptions.IsUseNewRenderer) { //Setup the shader for rendering the scene DefaultShader.Activate(); if (OptionLighting) { DefaultShader.SetIsLight(true); DefaultShader.SetLightPosition(Lighting.OptionLightPosition); DefaultShader.SetLightAmbient(Lighting.OptionAmbientColor); DefaultShader.SetLightDiffuse(Lighting.OptionDiffuseColor); DefaultShader.SetLightSpecular(Lighting.OptionSpecularColor); } DefaultShader.SetTexture(0); DefaultShader.SetCurrentProjectionMatrix(CurrentProjectionMatrix); } ResetOpenGlState(); foreach (FaceState face in VisibleObjects.OpaqueFaces) { if (Interface.CurrentOptions.IsUseNewRenderer) { RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } // alpha face ResetOpenGlState(); VisibleObjects.SortPolygonsInAlphaFaces(); if (Interface.CurrentOptions.TransparencyMode == TransparencyMode.Performance) { SetBlendFunc(); SetAlphaFunc(AlphaFunction.Greater, 0.0f); GL.DepthMask(false); foreach (FaceState face in VisibleObjects.AlphaFaces) { if (Interface.CurrentOptions.IsUseNewRenderer) { RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } else { UnsetBlendFunc(); SetAlphaFunc(AlphaFunction.Equal, 1.0f); GL.DepthMask(true); foreach (FaceState face in VisibleObjects.AlphaFaces) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].BlendMode == MeshMaterialBlendMode.Normal && face.Object.Prototype.Mesh.Materials[face.Face.Material].GlowAttenuationData == 0) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].Color.A == 255) { if (Interface.CurrentOptions.IsUseNewRenderer) { RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } } SetBlendFunc(); SetAlphaFunc(AlphaFunction.Less, 1.0f); GL.DepthMask(false); bool additive = false; foreach (FaceState face in VisibleObjects.AlphaFaces) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].BlendMode == MeshMaterialBlendMode.Additive) { if (!additive) { UnsetAlphaFunc(); additive = true; } if (Interface.CurrentOptions.IsUseNewRenderer) { RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } else { if (additive) { SetAlphaFunc(); additive = false; } if (Interface.CurrentOptions.IsUseNewRenderer) { RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } } if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Deactivate(); } // render overlays ResetOpenGlState(); OptionLighting = false; UnsetAlphaFunc(); GL.Disable(EnableCap.DepthTest); RenderOverlays(); OptionLighting = true; }
public List <MapObject> RetreiveAllTargets(Predicate <MapObject> predicate) { return(VisibleObjects.ToList().FindAll(n => n != null && predicate(n))); }
public static int Main(string[] args) { #region 公共工具 if (args[0] == "MENU_MoveObject") { MoveObject move = new MoveObject(); move.Show(); } if (args[0] == "MENU_MoveComponent") { MoveComponent move = new MoveComponent(); move.Show(); } if (args[0] == "MENU_MoveObjectMin") { VisibleObjects vis = new VisibleObjects(); Point3d endPt = new Point3d(vis.Aoo.CenterPt.X, vis.Aoo.CenterPt.Y, vis.Aoo.CenterPt.Z - vis.Aoo.DisPt.Z); IMoveBulider move = new MovePointToPointBuilder(new Point3d(0, 0, 0), endPt); move.Move(vis.VisObjs.ToArray()); } if (args[0] == "MENU_MoveObjectMax") { VisibleObjects vis = new VisibleObjects(); Point3d endPt = new Point3d(vis.Aoo.CenterPt.X, vis.Aoo.CenterPt.Y, vis.Aoo.CenterPt.Z + vis.Aoo.DisPt.Z); IMoveBulider move = new MovePointToPointBuilder(new Point3d(0, 0, 0), endPt); move.Move(vis.VisObjs.ToArray()); } if (args[0] == "MENU_MoveObjectRotateX") { VisibleObjects vis = new VisibleObjects(); IMoveBulider move = new MoveRotateBuilder(new Vector3d(1, 0, 0), 90); move.Move(vis.VisObjs.ToArray()); } if (args[0] == "MENU_MoveObjectRotateY") { VisibleObjects vis = new VisibleObjects(); IMoveBulider move = new MoveRotateBuilder(new Vector3d(0, 1, 0), 90); move.Move(vis.VisObjs.ToArray()); } if (args[0] == "MENU_MoveObjectRotateZ") { VisibleObjects vis = new VisibleObjects(); IMoveBulider move = new MoveRotateBuilder(new Vector3d(0, 0, 1), 90); move.Move(vis.VisObjs.ToArray()); } if (args[0] == "MENU_AnalyzeBodyAndFace") { AnalyzeBodyAndFace analyze = new AnalyzeBodyAndFace(); analyze.Show(); } #endregion #region 电极设计 if (args[0] == "MENU_SuperBox") { SuperBox superBox = new SuperBox(); superBox.Show(); } if (args[0] == "MENU_AddEdmAsm") { AddEdmAsm add = new AddEdmAsm(); add.Show(); } if (args[0] == "MENU_AddWorkpiece") { AddWorkpiece add = new AddWorkpiece(); add.Show(); } if (args[0] == "MENU_AddWork") { AddWork add = new AddWork(); add.Show(); } if (args[0] == "MENU_CheckElectrode") { CheckElectrode check = new CheckElectrode(); check.Show(); } if (args[0] == "MENU_MoveBody") { MoveBody move = new MoveBody(); move.Show(); } if (args[0] == "MENU_EleStandardSeatZ+") { ElectrodeCreateExpAndMatr expAndMatr = new ElectrodeCreateExpAndMatr(new ZPositiveElectrodeMatrix()); CreateEleStandardSeatForm form = new CreateEleStandardSeatForm(expAndMatr); form.Show(); } if (args[0] == "MENU_EleStandardSeatX+") { ElectrodeCreateExpAndMatr expAndMatr = new ElectrodeCreateExpAndMatr(new XNegativeElectrodeMatrix()); CreateEleStandardSeatForm form = new CreateEleStandardSeatForm(expAndMatr); form.Show(); } if (args[0] == "MENU_EleStandardSeatY+") { ElectrodeCreateExpAndMatr expAndMatr = new ElectrodeCreateExpAndMatr(new YPositiveElectrodeMatrix()); CreateEleStandardSeatForm form = new CreateEleStandardSeatForm(expAndMatr); form.Show(); } if (args[0] == "MENU_EleStandardSeatX-") { ElectrodeCreateExpAndMatr expAndMatr = new ElectrodeCreateExpAndMatr(new XPositiveElectrodeMatrix()); CreateEleStandardSeatForm form = new CreateEleStandardSeatForm(expAndMatr); form.Show(); } if (args[0] == "MENU_EleStandardSeatY-") { ElectrodeCreateExpAndMatr expAndMatr = new ElectrodeCreateExpAndMatr(new YNegativeElectrodeMatrix()); CreateEleStandardSeatForm form = new CreateEleStandardSeatForm(expAndMatr); form.Show(); } if (args[0] == "MENU_ElectrodeColor") { ElectrodeColor color = new ElectrodeColor(); color.Show(); } if (args[0] == "MENU_DeleteEle") { DeleteEle delete = new DeleteEle(); delete.Show(); } if (args[0] == "MENU_CopyElectrode") { CopyElectrode copy = new CopyElectrode(); copy.Show(); } if (args[0] == "MENU_PositionEle") { PositionEle posit = new PositionEle(); posit.Show(); } if (args[0] == "MENU_MoovElectrode") { new MoovElectrode().Show(); } if (args[0] == "MENU_Interference") { Interference inter = new Interference(); inter.Show(); } if (args[0] == "MENU_WorkpieceDrawing") { new WorkpieceDrawingCreateForm().Show(); } if (args[0] == "MENU_ElectrodeDrawing") { new ElectrodeDrawingCreateForm().Show(); } if (args[0] == "MENU_Bom") { new BomCreateForm().Show(); } if (args[0] == "MENU_AlterComponent") { new AlterComponent().Show(); } if (args[0] == "MENU_CopyAsm") { new CopyAsm().Show(); } if (args[0] == "MENU_ExportEleCam") { new ExportEleCamCreateForm().Show(); } if (args[0] == "MENU_ExportEleCMM") { new ExportEleCMMCreateForm().Show(); } #endregion if (args[0] == "MENU_EleProgram") { EleProgramCreateForm mode = new EleProgramCreateForm(); mode.Show(); } if (args[0] == "MENU_AddProgram") { AddProgram ele = new AddProgram(); ele.Show(); } if (args[0] == "MENU_Program") { UserOperation.CreateUserOper(); } if (args[0] == "MENU_OffsetBodyGapVauleUi") { new OffsetBodyGapVauleUi().Show(); } if (args[0] == "MENU_PostShopdoc") { PostShopdocCreateForm.Show(); } // Test.User(); return(1); }
// render scene internal void RenderScene(double TimeElapsed) { // initialize ResetOpenGlState(); if (OptionWireFrame) { if (Program.CurrentRoute.CurrentFog.Start < Program.CurrentRoute.CurrentFog.End) { const float fogDistance = 600.0f; float n = (fogDistance - Program.CurrentRoute.CurrentFog.Start) / (Program.CurrentRoute.CurrentFog.End - Program.CurrentRoute.CurrentFog.Start); float cr = n * inv255 * Program.CurrentRoute.CurrentFog.Color.R; float cg = n * inv255 * Program.CurrentRoute.CurrentFog.Color.G; float cb = n * inv255 * Program.CurrentRoute.CurrentFog.Color.B; GL.ClearColor(cr, cg, cb, 1.0f); } else { GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f); } } GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); UpdateViewport(ViewportChangeMode.ChangeToScenery); // set up camera CurrentViewMatrix = Matrix4D.LookAt(Vector3.Zero, new Vector3(Camera.AbsoluteDirection.X, Camera.AbsoluteDirection.Y, -Camera.AbsoluteDirection.Z), new Vector3(Camera.AbsoluteUp.X, Camera.AbsoluteUp.Y, -Camera.AbsoluteUp.Z)); GL.Light(LightName.Light0, LightParameter.Position, new[] { (float)Lighting.OptionLightPosition.X, (float)Lighting.OptionLightPosition.Y, (float)-Lighting.OptionLightPosition.Z, 0.0f }); Lighting.OptionLightingResultingAmount = (Lighting.OptionAmbientColor.R + Lighting.OptionAmbientColor.G + Lighting.OptionAmbientColor.B) / 480.0f; if (Lighting.OptionLightingResultingAmount > 1.0f) { Lighting.OptionLightingResultingAmount = 1.0f; } // fog double fd = Program.CurrentRoute.NextFog.TrackPosition - Program.CurrentRoute.PreviousFog.TrackPosition; if (fd != 0.0) { float fr = (float)((CameraTrackFollower.TrackPosition - Program.CurrentRoute.PreviousFog.TrackPosition) / fd); float frc = 1.0f - fr; Program.CurrentRoute.CurrentFog.Start = Program.CurrentRoute.PreviousFog.Start * frc + Program.CurrentRoute.NextFog.Start * fr; Program.CurrentRoute.CurrentFog.End = Program.CurrentRoute.PreviousFog.End * frc + Program.CurrentRoute.NextFog.End * fr; Program.CurrentRoute.CurrentFog.Color.R = (byte)(Program.CurrentRoute.PreviousFog.Color.R * frc + Program.CurrentRoute.NextFog.Color.R * fr); Program.CurrentRoute.CurrentFog.Color.G = (byte)(Program.CurrentRoute.PreviousFog.Color.G * frc + Program.CurrentRoute.NextFog.Color.G * fr); Program.CurrentRoute.CurrentFog.Color.B = (byte)(Program.CurrentRoute.PreviousFog.Color.B * frc + Program.CurrentRoute.NextFog.Color.B * fr); } else { Program.CurrentRoute.CurrentFog = Program.CurrentRoute.PreviousFog; } // render background GL.Disable(EnableCap.DepthTest); Program.CurrentRoute.UpdateBackground(TimeElapsed, Program.Renderer.CurrentInterface != InterfaceType.Normal); events.Render(Camera.AbsolutePosition); // fog float aa = Program.CurrentRoute.CurrentFog.Start; float bb = Program.CurrentRoute.CurrentFog.End; if (aa < bb & aa < Program.CurrentRoute.CurrentBackground.BackgroundImageDistance) { OptionFog = true; Fog.Start = aa; Fog.End = bb; Fog.Color = Program.CurrentRoute.CurrentFog.Color; SetFogForImmediateMode(); } else { OptionFog = false; } // world layer // opaque face if (AvailableNewRenderer) { //Setup the shader for rendering the scene DefaultShader.Activate(); if (OptionLighting) { DefaultShader.SetIsLight(true); DefaultShader.SetLightPosition(Lighting.OptionLightPosition); DefaultShader.SetLightAmbient(Lighting.OptionAmbientColor); DefaultShader.SetLightDiffuse(Lighting.OptionDiffuseColor); DefaultShader.SetLightSpecular(Lighting.OptionSpecularColor); } if (OptionFog) { DefaultShader.SetIsFog(true); DefaultShader.SetFogStart(Fog.Start); DefaultShader.SetFogEnd(Fog.End); DefaultShader.SetFogColor(Fog.Color); } DefaultShader.SetTexture(0); DefaultShader.SetCurrentProjectionMatrix(CurrentProjectionMatrix); } ResetOpenGlState(); foreach (FaceState face in VisibleObjects.OpaqueFaces) { if (AvailableNewRenderer) { RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } // alpha face ResetOpenGlState(); VisibleObjects.SortPolygonsInAlphaFaces(); if (Interface.CurrentOptions.TransparencyMode == TransparencyMode.Performance) { SetBlendFunc(); SetAlphaFunc(AlphaFunction.Greater, 0.0f); GL.DepthMask(false); foreach (FaceState face in VisibleObjects.AlphaFaces) { if (AvailableNewRenderer) { RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } else { UnsetBlendFunc(); SetAlphaFunc(AlphaFunction.Equal, 1.0f); GL.DepthMask(true); foreach (FaceState face in VisibleObjects.AlphaFaces) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].BlendMode == MeshMaterialBlendMode.Normal && face.Object.Prototype.Mesh.Materials[face.Face.Material].GlowAttenuationData == 0) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].Color.A == 255) { if (AvailableNewRenderer) { RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } } SetBlendFunc(); SetAlphaFunc(AlphaFunction.Less, 1.0f); GL.DepthMask(false); bool additive = false; foreach (FaceState face in VisibleObjects.AlphaFaces) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].BlendMode == MeshMaterialBlendMode.Additive) { if (!additive) { UnsetAlphaFunc(); additive = true; } if (AvailableNewRenderer) { RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } else { if (additive) { SetAlphaFunc(); additive = false; } if (AvailableNewRenderer) { RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } } // motion blur ResetOpenGlState(); SetAlphaFunc(AlphaFunction.Greater, 0.0f); GL.Disable(EnableCap.DepthTest); GL.DepthMask(false); OptionLighting = false; if (Interface.CurrentOptions.MotionBlur != MotionBlurMode.None) { DefaultShader.Deactivate(); MotionBlur.RenderFullscreen(Interface.CurrentOptions.MotionBlur, FrameRate, Math.Abs(Camera.CurrentSpeed)); } // overlay layer OptionFog = false; UpdateViewport(ViewportChangeMode.ChangeToCab); if (AvailableNewRenderer) { /* * We must reset the shader between overlay and world layers for correct lighting results. * Additionally, the viewport change updates the projection matrix */ DefaultShader.Activate(); ResetShader(DefaultShader); DefaultShader.SetCurrentProjectionMatrix(CurrentProjectionMatrix); } CurrentViewMatrix = Matrix4D.LookAt(Vector3.Zero, new Vector3(Camera.AbsoluteDirection.X, Camera.AbsoluteDirection.Y, -Camera.AbsoluteDirection.Z), new Vector3(Camera.AbsoluteUp.X, Camera.AbsoluteUp.Y, -Camera.AbsoluteUp.Z)); if (Camera.CurrentRestriction == CameraRestrictionMode.NotAvailable || Camera.CurrentRestriction == CameraRestrictionMode.Restricted3D) { ResetOpenGlState(); // TODO: inserted GL.Clear(ClearBufferMask.DepthBufferBit); OptionLighting = true; Color24 prevOptionAmbientColor = Lighting.OptionAmbientColor; Color24 prevOptionDiffuseColor = Lighting.OptionDiffuseColor; Lighting.OptionAmbientColor = Color24.LightGrey; Lighting.OptionDiffuseColor = Color24.LightGrey; if (AvailableNewRenderer) { DefaultShader.SetIsLight(true); DefaultShader.SetLightPosition(Lighting.OptionLightPosition); DefaultShader.SetLightAmbient(Lighting.OptionAmbientColor); DefaultShader.SetLightDiffuse(Lighting.OptionDiffuseColor); DefaultShader.SetLightSpecular(Lighting.OptionSpecularColor); } GL.Light(LightName.Light0, LightParameter.Ambient, new[] { inv255 * 178, inv255 * 178, inv255 * 178, 1.0f }); GL.Light(LightName.Light0, LightParameter.Diffuse, new[] { inv255 * 178, inv255 * 178, inv255 * 178, 1.0f }); // overlay opaque face foreach (FaceState face in VisibleObjects.OverlayOpaqueFaces) { if (AvailableNewRenderer) { RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } // overlay alpha face ResetOpenGlState(); VisibleObjects.SortPolygonsInOverlayAlphaFaces(); if (Interface.CurrentOptions.TransparencyMode == TransparencyMode.Performance) { SetBlendFunc(); SetAlphaFunc(AlphaFunction.Greater, 0.0f); GL.DepthMask(false); foreach (FaceState face in VisibleObjects.OverlayAlphaFaces) { if (AvailableNewRenderer) { RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } else { UnsetBlendFunc(); SetAlphaFunc(AlphaFunction.Equal, 1.0f); GL.DepthMask(true); foreach (FaceState face in VisibleObjects.OverlayAlphaFaces) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].BlendMode == MeshMaterialBlendMode.Normal && face.Object.Prototype.Mesh.Materials[face.Face.Material].GlowAttenuationData == 0) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].Color.A == 255) { if (AvailableNewRenderer) { RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } } SetBlendFunc(); SetAlphaFunc(AlphaFunction.Less, 1.0f); GL.DepthMask(false); bool additive = false; foreach (FaceState face in VisibleObjects.OverlayAlphaFaces) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].BlendMode == MeshMaterialBlendMode.Additive) { if (!additive) { UnsetAlphaFunc(); additive = true; } if (AvailableNewRenderer) { RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } else { if (additive) { SetAlphaFunc(); additive = false; } if (AvailableNewRenderer) { RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } } Lighting.OptionAmbientColor = prevOptionAmbientColor; Lighting.OptionDiffuseColor = prevOptionDiffuseColor; Lighting.Initialize(); } else { /* * Render 2D Cab * This is actually an animated object generated on the fly and held in memory */ ResetOpenGlState(); OptionLighting = false; SetBlendFunc(); UnsetAlphaFunc(); GL.Disable(EnableCap.DepthTest); GL.DepthMask(false); VisibleObjects.SortPolygonsInOverlayAlphaFaces(); foreach (FaceState face in VisibleObjects.OverlayAlphaFaces) { if (AvailableNewRenderer) { RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } if (AvailableNewRenderer) { /* * Must remember to de-activate at the end of the render sequence if in GL3 mode. * The overlays currently use immediate mode and do not work correctly with the shader active */ DefaultShader.Deactivate(); } // render touch OptionLighting = false; Touch.RenderScene(); // render overlays ResetOpenGlState(); UnsetAlphaFunc(); SetBlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); //FIXME: Remove when text switches between two renderer types GL.Disable(EnableCap.DepthTest); overlays.Render(TimeElapsed); OptionLighting = true; }
public override void UpdateVisibility(double TrackPosition) { double d = TrackPosition - LastUpdatedTrackPosition; int n = ObjectsSortedByStart.Length; double p = CameraTrackFollower.TrackPosition + Camera.Alignment.Position.Z; if (d < 0.0) { if (ObjectsSortedByStartPointer >= n) { ObjectsSortedByStartPointer = n - 1; } if (ObjectsSortedByEndPointer >= n) { ObjectsSortedByEndPointer = n - 1; } // dispose while (ObjectsSortedByStartPointer >= 0) { int o = ObjectsSortedByStart[ObjectsSortedByStartPointer]; if (StaticObjectStates[o].StartingDistance > p + Camera.ForwardViewingDistance) { VisibleObjects.HideObject(StaticObjectStates[o]); ObjectsSortedByStartPointer--; } else { break; } } // introduce while (ObjectsSortedByEndPointer >= 0) { int o = ObjectsSortedByEnd[ObjectsSortedByEndPointer]; if (StaticObjectStates[o].EndingDistance >= p - Camera.BackwardViewingDistance) { if (StaticObjectStates[o].StartingDistance <= p + Camera.ForwardViewingDistance) { VisibleObjects.ShowObject(StaticObjectStates[o], ObjectType.Static); } ObjectsSortedByEndPointer--; } else { break; } } } else if (d > 0.0) { if (ObjectsSortedByStartPointer < 0) { ObjectsSortedByStartPointer = 0; } if (ObjectsSortedByEndPointer < 0) { ObjectsSortedByEndPointer = 0; } // dispose while (ObjectsSortedByEndPointer < n) { int o = ObjectsSortedByEnd[ObjectsSortedByEndPointer]; if (StaticObjectStates[o].EndingDistance < p - Camera.BackwardViewingDistance) { VisibleObjects.HideObject(StaticObjectStates[o]); ObjectsSortedByEndPointer++; } else { break; } } // introduce while (ObjectsSortedByStartPointer < n) { int o = ObjectsSortedByStart[ObjectsSortedByStartPointer]; if (StaticObjectStates[o].StartingDistance <= p + Camera.ForwardViewingDistance) { if (StaticObjectStates[o].EndingDistance >= p - Camera.BackwardViewingDistance) { VisibleObjects.ShowObject(StaticObjectStates[o], ObjectType.Static); } ObjectsSortedByStartPointer++; } else { break; } } } LastUpdatedTrackPosition = TrackPosition; }
// render scene internal void RenderScene() { lastObjectState = null; if (!AvailableNewRenderer) { CurrentShader.Deactivate(); } ReleaseResources(); // initialize ResetOpenGlState(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); UpdateViewport(ViewportChangeMode.ChangeToScenery); CurrentViewMatrix = Matrix4D.LookAt(Vector3.Zero, new Vector3(Camera.AbsoluteDirection.X, Camera.AbsoluteDirection.Y, -Camera.AbsoluteDirection.Z), new Vector3(Camera.AbsoluteUp.X, Camera.AbsoluteUp.Y, -Camera.AbsoluteUp.Z)); TransformedLightPosition = new Vector3(Lighting.OptionLightPosition.X, Lighting.OptionLightPosition.Y, -Lighting.OptionLightPosition.Z); TransformedLightPosition.Transform(CurrentViewMatrix); if (!AvailableNewRenderer) { GL.Light(LightName.Light0, LightParameter.Position, new[] { (float)TransformedLightPosition.X, (float)TransformedLightPosition.Y, (float)TransformedLightPosition.Z, 0.0f }); } Lighting.OptionLightingResultingAmount = (Lighting.OptionAmbientColor.R + Lighting.OptionAmbientColor.G + Lighting.OptionAmbientColor.B) / 480.0f; if (Lighting.OptionLightingResultingAmount > 1.0f) { Lighting.OptionLightingResultingAmount = 1.0f; } OptionFog = false; if (OptionCoordinateSystem) { UnsetAlphaFunc(); if (AvailableNewRenderer) { redAxisVAO.Draw(Vector3.Zero, Vector3.Forward, Vector3.Down, Vector3.Right, new Vector3(100.0, 0.01, 0.01), Camera.AbsolutePosition, null); greenAxisVAO.Draw(Vector3.Zero, Vector3.Forward, Vector3.Down, Vector3.Right, new Vector3(0.01, 100.0, 0.01), Camera.AbsolutePosition, null); blueAxisVAO.Draw(Vector3.Zero, Vector3.Forward, Vector3.Down, Vector3.Right, new Vector3(0.01, 0.01, 100.0), Camera.AbsolutePosition, null); } else { GL.Color4(1.0, 0.0, 0.0, 0.2); Cube.Draw(Vector3.Zero, Vector3.Forward, Vector3.Down, Vector3.Right, new Vector3(100.0, 0.01, 0.01), Camera.AbsolutePosition, null); GL.Color4(0.0, 1.0, 0.0, 0.2); Cube.Draw(Vector3.Zero, Vector3.Forward, Vector3.Down, Vector3.Right, new Vector3(0.01, 100.0, 0.01), Camera.AbsolutePosition, null); GL.Color4(0.0, 0.0, 1.0, 0.2); Cube.Draw(Vector3.Zero, Vector3.Forward, Vector3.Down, Vector3.Right, new Vector3(0.01, 0.01, 100.0), Camera.AbsolutePosition, null); } } GL.Disable(EnableCap.DepthTest); // opaque face if (AvailableNewRenderer) { //Setup the shader for rendering the scene DefaultShader.Activate(); if (OptionLighting) { DefaultShader.SetIsLight(true); DefaultShader.SetLightPosition(TransformedLightPosition); DefaultShader.SetLightAmbient(Lighting.OptionAmbientColor); DefaultShader.SetLightDiffuse(Lighting.OptionDiffuseColor); DefaultShader.SetLightSpecular(Lighting.OptionSpecularColor); DefaultShader.SetLightModel(Lighting.LightModel); } DefaultShader.SetTexture(0); DefaultShader.SetCurrentProjectionMatrix(CurrentProjectionMatrix); } ResetOpenGlState(); foreach (FaceState face in VisibleObjects.OpaqueFaces) { face.Draw(); } // alpha face ResetOpenGlState(); VisibleObjects.SortPolygonsInAlphaFaces(); if (Interface.CurrentOptions.TransparencyMode == TransparencyMode.Performance) { SetBlendFunc(); SetAlphaFunc(AlphaFunction.Greater, 0.0f); GL.DepthMask(false); foreach (FaceState face in VisibleObjects.AlphaFaces) { face.Draw(); } } else { UnsetBlendFunc(); SetAlphaFunc(AlphaFunction.Equal, 1.0f); GL.DepthMask(true); foreach (FaceState face in VisibleObjects.AlphaFaces) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].BlendMode == MeshMaterialBlendMode.Normal && face.Object.Prototype.Mesh.Materials[face.Face.Material].GlowAttenuationData == 0) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].Color.A == 255) { face.Draw(); } } } SetBlendFunc(); SetAlphaFunc(AlphaFunction.Less, 1.0f); GL.DepthMask(false); bool additive = false; foreach (FaceState face in VisibleObjects.AlphaFaces) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].BlendMode == MeshMaterialBlendMode.Additive) { if (!additive) { UnsetAlphaFunc(); additive = true; } face.Draw(); } else { if (additive) { SetAlphaFunc(); additive = false; } face.Draw(); } } } if (AvailableNewRenderer) { DefaultShader.Deactivate(); lastVAO = -1; } // render overlays ResetOpenGlState(); OptionLighting = false; UnsetAlphaFunc(); GL.Disable(EnableCap.DepthTest); SetBlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); //FIXME: Remove when text switches between two renderer types RenderOverlays(); OptionLighting = true; }
// render scene internal void RenderScene(double TimeElapsed) { // initialize ResetOpenGlState(); if (OptionWireFrame) { if (Program.CurrentRoute.CurrentFog.Start < Program.CurrentRoute.CurrentFog.End) { const float fogDistance = 600.0f; float n = (fogDistance - Program.CurrentRoute.CurrentFog.Start) / (Program.CurrentRoute.CurrentFog.End - Program.CurrentRoute.CurrentFog.Start); float cr = n * inv255 * Program.CurrentRoute.CurrentFog.Color.R; float cg = n * inv255 * Program.CurrentRoute.CurrentFog.Color.G; float cb = n * inv255 * Program.CurrentRoute.CurrentFog.Color.B; GL.ClearColor(cr, cg, cb, 1.0f); } else { GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f); } } GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); UpdateViewport(ViewportChangeMode.ChangeToScenery); // set up camera CurrentViewMatrix = Matrix4D.LookAt(Vector3.Zero, new Vector3(Camera.AbsoluteDirection.X, Camera.AbsoluteDirection.Y, -Camera.AbsoluteDirection.Z), new Vector3(Camera.AbsoluteUp.X, Camera.AbsoluteUp.Y, -Camera.AbsoluteUp.Z)); GL.Light(LightName.Light0, LightParameter.Position, new[] { (float)Lighting.OptionLightPosition.X, (float)Lighting.OptionLightPosition.Y, (float)-Lighting.OptionLightPosition.Z, 0.0f }); // fog double fd = Program.CurrentRoute.NextFog.TrackPosition - Program.CurrentRoute.PreviousFog.TrackPosition; if (fd != 0.0) { float fr = (float)((World.CameraTrackFollower.TrackPosition - Program.CurrentRoute.PreviousFog.TrackPosition) / fd); float frc = 1.0f - fr; Program.CurrentRoute.CurrentFog.Start = Program.CurrentRoute.PreviousFog.Start * frc + Program.CurrentRoute.NextFog.Start * fr; Program.CurrentRoute.CurrentFog.End = Program.CurrentRoute.PreviousFog.End * frc + Program.CurrentRoute.NextFog.End * fr; Program.CurrentRoute.CurrentFog.Color.R = (byte)(Program.CurrentRoute.PreviousFog.Color.R * frc + Program.CurrentRoute.NextFog.Color.R * fr); Program.CurrentRoute.CurrentFog.Color.G = (byte)(Program.CurrentRoute.PreviousFog.Color.G * frc + Program.CurrentRoute.NextFog.Color.G * fr); Program.CurrentRoute.CurrentFog.Color.B = (byte)(Program.CurrentRoute.PreviousFog.Color.B * frc + Program.CurrentRoute.NextFog.Color.B * fr); } else { Program.CurrentRoute.CurrentFog = Program.CurrentRoute.PreviousFog; } // render background GL.Disable(EnableCap.DepthTest); Program.CurrentRoute.UpdateBackground(TimeElapsed, Game.CurrentInterface != Game.InterfaceType.Normal); events.Render(Camera.AbsolutePosition); // fog float aa = Program.CurrentRoute.CurrentFog.Start; float bb = Program.CurrentRoute.CurrentFog.End; if (aa < bb & aa < Program.CurrentRoute.CurrentBackground.BackgroundImageDistance) { OptionFog = true; Fog.Start = aa; Fog.End = bb; Fog.Color = Program.CurrentRoute.CurrentFog.Color; SetFogForImmediateMode(); } else { OptionFog = false; } // world layer // opaque face ResetOpenGlState(); foreach (FaceState face in VisibleObjects.OpaqueFaces) { if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Activate(); ResetShader(DefaultShader); RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } // alpha face ResetOpenGlState(); VisibleObjects.SortPolygonsInAlphaFaces(); if (Interface.CurrentOptions.TransparencyMode == TransparencyMode.Performance) { SetBlendFunc(); SetAlphaFunc(AlphaFunction.Greater, 0.0f); GL.DepthMask(false); foreach (FaceState face in VisibleObjects.AlphaFaces) { if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Activate(); ResetShader(DefaultShader); RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } else { UnsetBlendFunc(); SetAlphaFunc(AlphaFunction.Equal, 1.0f); GL.DepthMask(true); foreach (FaceState face in VisibleObjects.AlphaFaces) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].BlendMode == MeshMaterialBlendMode.Normal && face.Object.Prototype.Mesh.Materials[face.Face.Material].GlowAttenuationData == 0) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].Color.A == 255) { if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Activate(); ResetShader(DefaultShader); RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } } SetBlendFunc(); SetAlphaFunc(AlphaFunction.Less, 1.0f); GL.DepthMask(false); bool additive = false; foreach (FaceState face in VisibleObjects.AlphaFaces) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].BlendMode == MeshMaterialBlendMode.Additive) { if (!additive) { UnsetAlphaFunc(); additive = true; } if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Activate(); ResetShader(DefaultShader); RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } else { if (additive) { SetAlphaFunc(); additive = false; } if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Activate(); ResetShader(DefaultShader); RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } } // motion blur ResetOpenGlState(); SetAlphaFunc(AlphaFunction.Greater, 0.0f); GL.Disable(EnableCap.DepthTest); GL.DepthMask(false); OptionLighting = false; if (Interface.CurrentOptions.MotionBlur != MotionBlurMode.None) { MotionBlur.RenderFullscreen(Interface.CurrentOptions.MotionBlur, FrameRate, Math.Abs(Camera.CurrentSpeed)); } // overlay layer OptionFog = false; UpdateViewport(ViewportChangeMode.ChangeToCab); CurrentViewMatrix = Matrix4D.LookAt(Vector3.Zero, new Vector3(Camera.AbsoluteDirection.X, Camera.AbsoluteDirection.Y, -Camera.AbsoluteDirection.Z), new Vector3(Camera.AbsoluteUp.X, Camera.AbsoluteUp.Y, -Camera.AbsoluteUp.Z)); if (Camera.CurrentRestriction == CameraRestrictionMode.NotAvailable || Camera.CurrentRestriction == CameraRestrictionMode.Restricted3D) { ResetOpenGlState(); // TODO: inserted GL.Clear(ClearBufferMask.DepthBufferBit); OptionLighting = true; Color24 prevOptionAmbientColor = Lighting.OptionAmbientColor; Color24 prevOptionDiffuseColor = Lighting.OptionDiffuseColor; Lighting.OptionAmbientColor = new Color24(178, 178, 178); Lighting.OptionDiffuseColor = new Color24(178, 178, 178); GL.Light(LightName.Light0, LightParameter.Ambient, new[] { inv255 * 178, inv255 * 178, inv255 * 178, 1.0f }); GL.Light(LightName.Light0, LightParameter.Diffuse, new[] { inv255 * 178, inv255 * 178, inv255 * 178, 1.0f }); // overlay opaque face foreach (FaceState face in VisibleObjects.OverlayOpaqueFaces) { if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Activate(); ResetShader(DefaultShader); RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } // overlay alpha face ResetOpenGlState(); VisibleObjects.SortPolygonsInOverlayAlphaFaces(); if (Interface.CurrentOptions.TransparencyMode == TransparencyMode.Performance) { SetBlendFunc(); SetAlphaFunc(AlphaFunction.Greater, 0.0f); GL.DepthMask(false); foreach (FaceState face in VisibleObjects.OverlayAlphaFaces) { if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Activate(); ResetShader(DefaultShader); RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } else { UnsetBlendFunc(); SetAlphaFunc(AlphaFunction.Equal, 1.0f); GL.DepthMask(true); foreach (FaceState face in VisibleObjects.OverlayAlphaFaces) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].BlendMode == MeshMaterialBlendMode.Normal && face.Object.Prototype.Mesh.Materials[face.Face.Material].GlowAttenuationData == 0) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].Color.A == 255) { if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Activate(); ResetShader(DefaultShader); RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } } SetBlendFunc(); SetAlphaFunc(AlphaFunction.Less, 1.0f); GL.DepthMask(false); bool additive = false; foreach (FaceState face in VisibleObjects.OverlayAlphaFaces) { if (face.Object.Prototype.Mesh.Materials[face.Face.Material].BlendMode == MeshMaterialBlendMode.Additive) { if (!additive) { UnsetAlphaFunc(); additive = true; } if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Activate(); ResetShader(DefaultShader); RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } else { if (additive) { SetAlphaFunc(); additive = false; } if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Activate(); ResetShader(DefaultShader); RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } } Lighting.OptionAmbientColor = prevOptionAmbientColor; Lighting.OptionDiffuseColor = prevOptionDiffuseColor; Lighting.Initialize(); } else { /* * Render 2D Cab * This is actually an animated object generated on the fly and held in memory */ ResetOpenGlState(); OptionLighting = false; SetBlendFunc(); UnsetAlphaFunc(); GL.Disable(EnableCap.DepthTest); GL.DepthMask(false); VisibleObjects.SortPolygonsInOverlayAlphaFaces(); foreach (FaceState face in VisibleObjects.OverlayAlphaFaces) { if (Interface.CurrentOptions.IsUseNewRenderer) { DefaultShader.Activate(); ResetShader(DefaultShader); RenderFace(DefaultShader, face); } else { RenderFaceImmediateMode(face); } } } // render touch OptionLighting = false; Touch.RenderScene(); // render overlays ResetOpenGlState(); UnsetAlphaFunc(); GL.Disable(EnableCap.DepthTest); overlays.Render(TimeElapsed); OptionLighting = true; }