diff --git a/Resources/Crosshair.png b/Resources/Crosshair.png new file mode 100644 index 00000000..40c70d93 Binary files /dev/null and b/Resources/Crosshair.png differ diff --git a/Source/Builder.csproj b/Source/Builder.csproj index 35c74643..8dae6c6d 100644 --- a/Source/Builder.csproj +++ b/Source/Builder.csproj @@ -649,6 +649,7 @@ + diff --git a/Source/BuilderModes/VisualModes/BaseVisualMode.cs b/Source/BuilderModes/VisualModes/BaseVisualMode.cs index 1a43ea0d..a552539c 100644 --- a/Source/BuilderModes/VisualModes/BaseVisualMode.cs +++ b/Source/BuilderModes/VisualModes/BaseVisualMode.cs @@ -48,7 +48,7 @@ namespace CodeImp.DoomBuilder.BuilderModes #region ================== Constants // Object picking interval - private double PICK_INTERVAL = 200.0d; + private double PICK_INTERVAL = 100.0d; #endregion @@ -101,7 +101,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // This picks a new target private void PickTarget() { - // Make ray + // Find the object we are aiming at Vector3D start = CameraPosition; Vector3D delta = CameraTarget - CameraPosition; delta = delta.GetFixedLength(General.Settings.ViewDistance); @@ -110,27 +110,35 @@ namespace CodeImp.DoomBuilder.BuilderModes // Object changed? if(newtarget.geometry != target.geometry) { - // Hide previous info - General.Interface.HideInfo(); - // Any result? if(newtarget.geometry != null) { if(newtarget.geometry is VisualSidedef) { + if(!(target.geometry is VisualSidedef)) General.Interface.HideInfo(); VisualSidedef vsd = (newtarget.geometry as VisualSidedef); General.Interface.ShowLinedefInfo(vsd.Sidedef.Line); } else if(newtarget.geometry is VisualFloor) { + if(!(target.geometry is VisualFloor) && !(target.geometry is VisualCeiling)) General.Interface.HideInfo(); VisualFloor vf = (newtarget.geometry as VisualFloor); General.Interface.ShowSectorInfo(vf.Sector.Sector); } else if(newtarget.geometry is VisualCeiling) { + if(!(target.geometry is VisualFloor) && !(target.geometry is VisualCeiling)) General.Interface.HideInfo(); VisualCeiling vc = (newtarget.geometry as VisualCeiling); General.Interface.ShowSectorInfo(vc.Sector.Sector); } + else + { + General.Interface.HideInfo(); + } + } + else + { + General.Interface.HideInfo(); } } @@ -171,6 +179,9 @@ namespace CodeImp.DoomBuilder.BuilderModes // Done rendering geometry renderer.FinishGeometry(); + // Render crosshair + renderer.RenderCrosshair(); + // Present! renderer.Finish(); } diff --git a/Source/Data/DataManager.cs b/Source/Data/DataManager.cs index e90d3466..a67d49a6 100644 --- a/Source/Data/DataManager.cs +++ b/Source/Data/DataManager.cs @@ -70,6 +70,7 @@ namespace CodeImp.DoomBuilder.Data // Special images private ImageData missingtexture3d; private ImageData hourglass3d; + private ImageData crosshair; // Used images private Dictionary usedimages; @@ -90,6 +91,7 @@ namespace CodeImp.DoomBuilder.Data public bool IsDisposed { get { return isdisposed; } } public ImageData MissingTexture3D { get { return missingtexture3d; } } public ImageData Hourglass3D { get { return hourglass3d; } } + public ImageData Crosshair3D { get { return crosshair; } } internal ICollection TextureSets { get { return texturesets; } } internal OthersTextureSet OthersTextureSet { get { return othertextures; } } @@ -123,6 +125,8 @@ namespace CodeImp.DoomBuilder.Data missingtexture3d.LoadImage(); hourglass3d = new ResourceImage("Hourglass3D.png"); hourglass3d.LoadImage(); + crosshair = new ResourceImage("Crosshair.png"); + crosshair.LoadImage(); } // Disposer @@ -135,6 +139,10 @@ namespace CodeImp.DoomBuilder.Data Unload(); missingtexture3d.Dispose(); missingtexture3d = null; + hourglass3d.Dispose(); + hourglass3d = null; + crosshair.Dispose(); + crosshair = null; // Done isdisposed = true; diff --git a/Source/Rendering/IRenderer3D.cs b/Source/Rendering/IRenderer3D.cs index e25690c8..84e7f497 100644 --- a/Source/Rendering/IRenderer3D.cs +++ b/Source/Rendering/IRenderer3D.cs @@ -55,5 +55,6 @@ namespace CodeImp.DoomBuilder.Rendering // Rendering methods void AddGeometry(VisualGeometry g); + void RenderCrosshair(); } } diff --git a/Source/Rendering/Renderer3D.cs b/Source/Rendering/Renderer3D.cs index 214e841e..ebf9bbc4 100644 --- a/Source/Rendering/Renderer3D.cs +++ b/Source/Rendering/Renderer3D.cs @@ -43,7 +43,7 @@ namespace CodeImp.DoomBuilder.Rendering private const int RENDER_PASSES = 4; private const float PROJ_NEAR_PLANE = 1f; - + private const float CROSSHAIR_SCALE = 0.1f; #endregion #region ================== Variables @@ -57,6 +57,9 @@ namespace CodeImp.DoomBuilder.Rendering // Frustum private ProjectedFrustum2D frustum; + // Crosshair + private FlatVertex[] crosshairverts; + // Geometry to be rendered. // Each Dictionary in the array is a render pass. // Each BinaryHeap in the Dictionary contains all geometry that needs @@ -103,12 +106,13 @@ namespace CodeImp.DoomBuilder.Rendering #endregion - #region ================== Methods + #region ================== Management // This is called before a device is reset // (when resized or display adapter was changed) public override void UnloadResource() { + crosshairverts = null; } // This is called resets when the device is reset @@ -117,9 +121,42 @@ namespace CodeImp.DoomBuilder.Rendering { } + // This makes screen vertices for display + private void CreateCrosshairVerts(Size texturesize) + { + // Determine coordinates + float width = (float)General.Map.Graphics.Viewport.Width; + float height = (float)General.Map.Graphics.Viewport.Height; + float size = (float)height * CROSSHAIR_SCALE; + RectangleF rect = new RectangleF((width - size) / 2, (height - size) / 2, size, size); + + // Make vertices + crosshairverts = new FlatVertex[4]; + crosshairverts[0].x = rect.Left; + crosshairverts[0].y = rect.Top; + crosshairverts[0].c = -1; + crosshairverts[0].u = 1f / texturesize.Width; + crosshairverts[0].v = 1f / texturesize.Height; + crosshairverts[1].x = rect.Right; + crosshairverts[1].y = rect.Top; + crosshairverts[1].c = -1; + crosshairverts[1].u = 1f - 1f / texturesize.Width; + crosshairverts[1].v = 1f / texturesize.Height; + crosshairverts[2].x = rect.Left; + crosshairverts[2].y = rect.Bottom; + crosshairverts[2].c = -1; + crosshairverts[2].u = 1f / texturesize.Width; + crosshairverts[2].v = 1f - 1f / texturesize.Height; + crosshairverts[3].x = rect.Right; + crosshairverts[3].y = rect.Bottom; + crosshairverts[3].c = -1; + crosshairverts[3].u = 1f - 1f / texturesize.Width; + crosshairverts[3].v = 1f - 1f / texturesize.Height; + } + #endregion - #region ================== General + #region ================== Presentation // This creates the projection internal void CreateProjection() @@ -178,7 +215,7 @@ namespace CodeImp.DoomBuilder.Rendering #endregion - #region ================== Presenting + #region ================== Start / Finish // This starts rendering public bool Start() @@ -197,6 +234,10 @@ namespace CodeImp.DoomBuilder.Rendering // Matrices ApplyMatrices(); + + // Create crosshair vertices + if(crosshairverts == null) + CreateCrosshairVerts(new Size(General.Map.Data.Crosshair3D.Width, General.Map.Data.Crosshair3D.Height)); // Ready return true; @@ -226,23 +267,19 @@ namespace CodeImp.DoomBuilder.Rendering graphics.Device.SetRenderState(RenderState.AlphaBlendEnable, false); graphics.Device.SetRenderState(RenderState.AlphaTestEnable, false); graphics.Device.SetRenderState(RenderState.TextureFactor, -1); - - // SOLID PASS graphics.Shaders.World3D.Begin(); graphics.Shaders.World3D.WorldViewProj = viewproj; + + // SOLID PASS graphics.Shaders.World3D.BeginPass(0); RenderSinglePass((int)RenderPass.Solid); graphics.Shaders.World3D.EndPass(); - graphics.Shaders.World3D.End(); // MASK PASS graphics.Device.SetRenderState(RenderState.AlphaTestEnable, true); - graphics.Shaders.World3D.Begin(); - graphics.Shaders.World3D.WorldViewProj = viewproj; graphics.Shaders.World3D.BeginPass(0); RenderSinglePass((int)RenderPass.Mask); graphics.Shaders.World3D.EndPass(); - graphics.Shaders.World3D.End(); // ALPHA PASS graphics.Device.SetRenderState(RenderState.AlphaBlendEnable, true); @@ -250,26 +287,21 @@ namespace CodeImp.DoomBuilder.Rendering graphics.Device.SetRenderState(RenderState.ZWriteEnable, false); graphics.Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha); graphics.Device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha); - graphics.Shaders.World3D.Begin(); - graphics.Shaders.World3D.WorldViewProj = viewproj; graphics.Shaders.World3D.BeginPass(0); RenderSinglePass((int)RenderPass.Alpha); graphics.Shaders.World3D.EndPass(); - graphics.Shaders.World3D.End(); // ADDITIVE PASS graphics.Device.SetRenderState(RenderState.DestinationBlend, Blend.One); - graphics.Shaders.World3D.Begin(); - graphics.Shaders.World3D.WorldViewProj = viewproj; graphics.Shaders.World3D.BeginPass(0); RenderSinglePass((int)RenderPass.Additive); graphics.Shaders.World3D.EndPass(); - graphics.Shaders.World3D.End(); // Remove references graphics.Shaders.World3D.Texture1 = null; // Done + graphics.Shaders.World3D.End(); geometry = null; } @@ -343,7 +375,7 @@ namespace CodeImp.DoomBuilder.Rendering #endregion - #region ================== Geometry + #region ================== Rendering // This collects a visual sector's geometry for rendering public void AddGeometry(VisualGeometry g) @@ -363,6 +395,33 @@ namespace CodeImp.DoomBuilder.Rendering } } + // This renders the crosshair + public void RenderCrosshair() + { + // Set renderstates + graphics.Device.SetRenderState(RenderState.CullMode, Cull.None); + graphics.Device.SetRenderState(RenderState.ZEnable, false); + graphics.Device.SetRenderState(RenderState.AlphaBlendEnable, true); + graphics.Device.SetRenderState(RenderState.AlphaTestEnable, false); + graphics.Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha); + graphics.Device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha); + graphics.Device.SetRenderState(RenderState.TextureFactor, -1); + graphics.Device.SetTransform(TransformState.World, Matrix.Identity); + graphics.Device.SetTransform(TransformState.Projection, Matrix.Identity); + graphics.Device.SetTransform(TransformState.View, Matrix.Identity); + + // Draw + graphics.Shaders.Display2D.Begin(); + if(General.Map.Data.Crosshair3D.Texture == null) General.Map.Data.Crosshair3D.CreateTexture(); + graphics.Device.SetTexture(0, General.Map.Data.Crosshair3D.Texture); + graphics.Shaders.Display2D.Texture1 = General.Map.Data.Crosshair3D.Texture; + graphics.Shaders.Display2D.SetSettings(1.0f, 1.0f, 0.0f, 1.0f, true); + graphics.Shaders.Display2D.BeginPass(1); + graphics.Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 0, 2, crosshairverts); + graphics.Shaders.Display2D.EndPass(); + graphics.Shaders.Display2D.End(); + } + #endregion } } diff --git a/Source/Resources/Crosshair.png b/Source/Resources/Crosshair.png new file mode 100644 index 00000000..40c70d93 Binary files /dev/null and b/Source/Resources/Crosshair.png differ