public override bool Draw3D(RenderContext11 renderContext, float transparancy, Tile parent)
        {
            RenderedGeneration = CurrentRenderGeneration;
            TilesTouched++;

            InViewFrustum = true;

            if (!ReadyToRender)
            {
                TileCache.AddTileToQueue(this);

                return false;
            }

            TilesInView++;

            if (!CreateGeometry(renderContext, true))
            {
                return false;
            }

            renderContext.SetVertexBuffer(vertexBuffer);

            renderContext.MainTexture = texture;

            renderContext.SetIndexBuffer( indexBuffer[0]);

            int partCount = this.TriangleCount;
            TrianglesRendered += partCount;

            renderContext.devContext.DrawIndexed(indexBuffer[0].Count, 0, 0);

            return true;
        }
Пример #2
0
        // Draw an ellipse with the specified semi-major axis and eccentricity. The orbit is drawn over a single period,
        // fading from full brightness at the given eccentric anomaly.
        //
        // In order to match exactly the position at which a planet is drawn, the planet's position at the current time
        // must be passed as a parameter. positionNow is in the current coordinate system of the render context, not the
        // translated and rotated system of the orbital plane.
        public static void DrawEllipse(RenderContext11 renderContext, double semiMajorAxis, double eccentricity, double eccentricAnomaly, Color color, Matrix3d worldMatrix, Vector3d positionNow)
        {
            if (ellipseShader == null)
            {
                ellipseShader = new EllipseShader11();
            }

            if (ellipseVertexBuffer == null)
            {
                ellipseVertexBuffer = CreateEllipseVertexBuffer( 500);
            }

            Matrix3d savedWorld = renderContext.World;
            renderContext.World = worldMatrix;

            renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.LineStrip;

            renderContext.SetVertexBuffer(ellipseVertexBuffer);

            ellipseShader.UseShader(renderContext, semiMajorAxis, eccentricity, eccentricAnomaly, new SharpDX.Color(color.R, color.G, color.B, color.A), savedWorld, positionNow);

            renderContext.devContext.Draw(ellipseVertexBuffer.Count, 0);

            renderContext.World = savedWorld;
        }
Пример #3
0
        public override bool CreateGeometry(RenderContext11 renderContext, bool uiThread)
        {
            InitializeStarDB();

            ReadyToRender = true;
            return true;
        }
Пример #4
0
        public static void Draw(RenderContext11 renderContext, PositionColoredTextured[] points, int count, Matrix mat, bool triangleStrip)
        {
            if (VertexBuffer == null)
            {
                VertexBuffer = new Buffer(renderContext.Device, System.Runtime.InteropServices.Marshal.SizeOf(points[0]) * 2500, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, System.Runtime.InteropServices.Marshal.SizeOf(points[0]));
                VertexBufferBinding = new VertexBufferBinding(VertexBuffer, System.Runtime.InteropServices.Marshal.SizeOf((points[0])), 0);

            }

            renderContext.devContext.InputAssembler.PrimitiveTopology = triangleStrip ? SharpDX.Direct3D.PrimitiveTopology.TriangleStrip : SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            renderContext.BlendMode = BlendMode.Alpha;
            renderContext.setRasterizerState(TriangleCullMode.Off);

            mat.Transpose();

            WarpOutputShader.MatWVP = mat;
            WarpOutputShader.Use(renderContext.devContext, false);

            renderContext.SetVertexBuffer(VertexBufferBinding);

            DataBox box = renderContext.devContext.MapSubresource(VertexBuffer, 0, MapMode.WriteDiscard, MapFlags.None);
            Utilities.Write(box.DataPointer, points, 0, count);

            renderContext.devContext.UnmapSubresource(VertexBuffer, 0);

            renderContext.devContext.PixelShader.SetShaderResource(0, null);

            renderContext.devContext.Draw(count, 0);
        }
Пример #5
0
        public static void Draw(RenderContext11 renderContext, PositionColoredTextured[] points, int count, Texture11 texture, SharpDX.Direct3D.PrimitiveTopology primitiveType, float opacity = 1.0f)
        {
            if (VertexBuffer == null)
            {
                VertexBuffer = new Buffer(renderContext.Device, System.Runtime.InteropServices.Marshal.SizeOf(points[0]) * 2500, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, System.Runtime.InteropServices.Marshal.SizeOf(points[0]));
                VertexBufferBinding = new VertexBufferBinding(VertexBuffer, System.Runtime.InteropServices.Marshal.SizeOf((points[0])), 0);

            }
            renderContext.devContext.InputAssembler.PrimitiveTopology = primitiveType;
            renderContext.BlendMode = BlendMode.Alpha;
            renderContext.setRasterizerState(TriangleCullMode.Off);
            SharpDX.Matrix mat = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            mat.Transpose();

            WarpOutputShader.MatWVP = mat;
            WarpOutputShader.Use(renderContext.devContext, texture != null, opacity);

            renderContext.SetVertexBuffer(VertexBufferBinding);

            DataBox box = renderContext.devContext.MapSubresource(VertexBuffer, 0, MapMode.WriteDiscard, MapFlags.None);
            Utilities.Write(box.DataPointer, points, 0, count);

            renderContext.devContext.UnmapSubresource(VertexBuffer, 0);
            if (texture != null)
            {
                renderContext.devContext.PixelShader.SetShaderResource(0, texture.ResourceView);
            }
            else
            {
                renderContext.devContext.PixelShader.SetShaderResource(0, null);
            }
            renderContext.devContext.Draw(count, 0);
        }
Пример #6
0
        public void Draw3D(RenderContext11 renderContext, float transparancy)
        {
            ratio = 1116f / Earth3d.MainWindow.RenderWindow.ClientRectangle.Height;

            if (SingleSelectHandles == null)
            {
                SingleSelectHandles = Texture11.FromBitmap(RenderContext11.PrepDevice, Resources.Selhand);
            }

            if (MultiSelectHandles == null)
            {
                MultiSelectHandles = Texture11.FromBitmap(RenderContext11.PrepDevice, Resources.MultiSelhand);
            }

            if (FocusHandles == null)
            {
                FocusHandles = Texture11.FromBitmap(RenderContext11.PrepDevice, Resources.FocusHandles);
            }

            if (selectionSet.Count > 1)
            {
                foreach (var overlay in selectionSet)
                {
                    if (overlay == focus)
                    {

                        DrawSelectionHandles(renderContext, overlay, FocusHandles);
                    }
                    else
                    {

                        DrawSelectionHandles(renderContext, overlay, MultiSelectHandles);
                    }
                }
            }
            else
            {
                foreach (var overlay in selectionSet)
                {
                    DrawSelectionHandles(renderContext, overlay, SingleSelectHandles);
                }
            }
        }
        public override bool CreateGeometry(RenderContext11 renderContext, bool uiThread)
        {
            if (texture == null)
            {
                if (this.texture == null)
                {
                    if (TextureReady)
                    {

                        texture = BufferPool11.GetTexture(FileName);

                        double aspect = (double)texture.Width / (double)texture.Height;

                        if (aspect < 1.5)
                        {
                            domeMaster = true;
                        }

                    }
                    else
                    {
                        return false;
                    }
                }

                iTileBuildCount++;

                if (vertexBuffer == null)
                {
                    vertexBuffer = new VertexBuffer11(typeof(PositionNormalTexturedX2), VertexCount, RenderContext11.PrepDevice);
                    indexBuffer = new IndexBuffer11[4];

                    OnCreateVertexBuffer(vertexBuffer);
                    sphereRadius = 1;
                    sphereCenter = new Vector3d(0, 0, 0);
                }
            }
            ReadyToRender = true;
            return true;
        }
Пример #8
0
        private void DrawSelectionHandles(RenderContext11 renderContext, Overlay overlay, Texture11 handleTexture)
        {
            var handles = MakeHandles(overlay);
            var angle = overlay.RotationAngle;

            var i = 0;
            var j = 0;
            foreach (var handle in handles)
            {
                points[i + 0].Position = overlay.MakePosition(centerX, centerY, handle.Left - centerX, handle.Top - centerY, angle).Vector4;
                points[i + 0].Tu = j * (1f / 9f);
                points[i + 0].Tv = 0;
                points[i + 0].Color = Color.White;

                points[i + 1].Position = overlay.MakePosition(centerX, centerY, handle.Right - centerX, handle.Top - centerY, angle).Vector4;
                points[i + 1].Tu = (j + 1) * (1f / 9f);
                points[i + 1].Tv = 0;
                points[i + 1].Color = Color.White;

                points[i + 2].Position = overlay.MakePosition(centerX, centerY, handle.Left - centerX, handle.Bottom - centerY, angle).Vector4;
                points[i + 2].Tu = j * (1f / 9f);
                points[i + 2].Tv = 1;
                points[i + 2].Color = Color.White;

                points[i + 3].Position = overlay.MakePosition(centerX, centerY, handle.Right - centerX, handle.Top - centerY, angle).Vector4;
                points[i + 3].Tu = (j + 1) * (1f / 9f);
                points[i + 3].Tv = 0;
                points[i + 3].Color = Color.White;

                points[i + 4].Position = overlay.MakePosition(centerX, centerY, handle.Right - centerX, handle.Bottom - centerY, angle).Vector4;
                points[i + 4].Tu = (j + 1) * (1f / 9f);
                points[i + 4].Tv = 1;
                points[i + 4].Color = Color.White;

                points[i + 5].Position = overlay.MakePosition(centerX, centerY, handle.Left - centerX, handle.Bottom - centerY, angle).Vector4;
                points[i + 5].Tu = j * (1f / 9f);
                points[i + 5].Tv = 1;
                points[i + 5].Color = Color.White;

                i += 6;
                j++;
            }

            if (MultiSelect)
            {
                Sprite2d.Draw(renderContext, points, points.Length - 6, handleTexture, PrimitiveTopology.TriangleList);
            }
            else
            {
                Sprite2d.Draw(renderContext, points, points.Length, handleTexture, PrimitiveTopology.TriangleList);
            }
        }
Пример #9
0
        public void Draw(RenderContext11 renderContext, float opacity, Color color)
        {
            if (glyphCache == null || glyphCache.Version > glyphVersion)
            {
                PrepareBatch();
            }

            Color col = Color.FromArgb((int)(color.A * opacity), (int)(color.R * opacity), (int)(color.G * opacity), (int)(color.B * opacity));

            SimpleGeometryShader11.Color = col;

            SharpDX.Matrix mat = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            mat.Transpose();

            SimpleGeometryShader11.WVPMatrix = mat;

            renderContext.setRasterizerState(TriangleCullMode.CullCounterClockwise);

            BlendMode bm = renderContext.BlendMode;
            DepthStencilMode dm = renderContext.DepthStencilMode;
            //renderContext.DepthStencilMode = DepthStencilMode.ZReadOnly;
            renderContext.BlendMode = BlendMode.Alpha;

            SimpleGeometryShader11.Use(renderContext.devContext);

            renderContext.MainTexture = glyphCache.Texture;
            // Debug to get Glyhph textures and caches
            //        SharpDX.Direct3D11.Texture2D.ToFile(renderContext.devContext, glyphCache.Texture.Texture, SharpDX.Direct3D11.ImageFileFormat.Png, "c:\\temp\\texture2.png");

            renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;

            renderContext.SetVertexBuffer(vertexBuffer);

            renderContext.devContext.Draw(vertexBuffer.Count, 0);

            renderContext.DepthStencilMode = dm;

            renderContext.BlendMode = bm;

            //dump cache

              //          glyphCache.SaveToXML("c:\\temp\\glyphCache.xml");
        }
Пример #10
0
        public override bool Draw(RenderContext11 renderContext, float opacity, bool flat)
        {
            var matSaved = renderContext.World;
            renderContext.World = renderContext.WorldBaseNonRotating;

            foreach (var frame in frames)
            {
                if (frame.ShowOrbitPath)
                {
                    if (frame.Orbit == null)
                    {
                        frame.Orbit = new Orbit(frame.Elements, 360, Color, 1, (float)renderContext.NominalRadius);
                    }
                    frame.Orbit.Draw3D(renderContext, opacity * Opacity, new Vector3d(0, 0, 0));
                }
            }
            renderContext.World = matSaved;
            return true;
        }
Пример #11
0
        public void DrawLabels(RenderContext11 renderContext)
        {
            if (positions.Count < 1)
            {
                return;
            }
            InitLabelBuffer();

            renderContext.SetVertexBuffer(labelBuffer);
            renderContext.BlendMode = BlendMode.Alpha;
            renderContext.DepthStencilMode = DepthStencilMode.Off;
            renderContext.setRasterizerState(TriangleCullMode.Off);
            var mvp = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            mvp.Transpose();
            PointSpriteShader11.WVPMatrix = mvp;
            PointSpriteShader11.Color = SharpDX.Color.White;

            var adjustedScale = .01f; // (float)(1 / (Earth3d.MainWindow.ZoomFactor / 360));

            PointSpriteShader11.ViewportScale = new Vector2((2.0f / renderContext.ViewPort.Width) * adjustedScale, (2.0f / renderContext.ViewPort.Height) * adjustedScale);
            PointSpriteShader11.PointScaleFactors = new Vector3(0.0f, 0.0f, 10000.0f);
            PointSpriteShader11.Use(renderContext.Device.ImmediateContext);

            renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, texture.ResourceView);

            renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList;
            renderContext.devContext.Draw(labelBuffer.Count, 0);

            renderContext.Device.ImmediateContext.GeometryShader.Set(null);
        }
Пример #12
0
        internal void Draw(RenderContext11 renderContext)
        {
            if (reticleImage == null)
            {
                reticleImage = Texture11.FromBitmap(Properties.Resources.Reticle);
            }

            ComputePoints();

            Sprite2d.Draw(renderContext, points, 4, reticleImage, SharpDX.Direct3D.PrimitiveTopology.TriangleStrip);
        }
Пример #13
0
        public override void RenderPart(RenderContext11 renderContext, int part, float opacity, bool combine)
        {
            if (dsm != null && dsm.DsmIndex != null)
            {
                renderContext.SetIndexBuffer(dsm.DsmIndex);
                renderContext.SetVertexBuffer(dsm.VertexBuffer);
                if (dsm.Subsets.Length > 4)
                {
                    switch (part)
                    {
                        case 0:
                            part = 2;
                            break;
                        case 1:
                            part = 3;
                          //  return;
                            break;
                        case 2:
                            part = 0;

                            break;
                        case 3:
                            part = 1;

                            break;
                    }

                    renderContext.devContext.DrawIndexed(dsm.Subsets[part + 1] - dsm.Subsets[part], dsm.Subsets[part], 0);
                }
                else
                {
                    if (dsm.Subsets.Length > 0)
                    {
                        renderContext.devContext.DrawIndexed(dsm.Subsets[0] , 0, 0);

                    }

                }
            }
            else
            {
                base.RenderPart(renderContext, part, opacity, combine);
            }
        }
Пример #14
0
        public static void Draw2D(RenderContext11 renderContext, Texture11 srcTexture, SizeF size, PointF rotationCenter, float rotationAngle, PointF position, System.Drawing.Color color)
        {
            cornerPoints[0].Position = MakePosition(position.X, position.Y, -size.Width / 2, -size.Height / 2, rotationAngle).Vector4;
            cornerPoints[0].Tu = 0;
            cornerPoints[0].Tv = 0;
            cornerPoints[0].Color = color;

            cornerPoints[1].Position = MakePosition(position.X, position.Y, size.Width / 2, -size.Height / 2, rotationAngle).Vector4;
            cornerPoints[1].Tu = 1;
            cornerPoints[1].Tv = 0;
            cornerPoints[1].Color = color;

            cornerPoints[2].Position = MakePosition(position.X, position.Y, -size.Width / 2, size.Height / 2, rotationAngle).Vector4;
            cornerPoints[2].Tu = 0;
            cornerPoints[2].Tv = 1;
            cornerPoints[2].Color = color;

            cornerPoints[3].Position = MakePosition(position.X, position.Y, size.Width / 2, size.Height / 2, rotationAngle).Vector4;
            cornerPoints[3].Tu = 1;
            cornerPoints[3].Tv = 1;
            cornerPoints[3].Color = color;

            renderContext.setRasterizerState(TriangleCullMode.Off);
            renderContext.DepthStencilMode = DepthStencilMode.Off;
            DrawForScreen(renderContext, cornerPoints, 4, srcTexture, SharpDX.Direct3D.PrimitiveTopology.TriangleStrip);
        }
Пример #15
0
        public void Draw(RenderContext11 renderContext, bool space3d)
        {
            var cam = Vector3d.TransformCoordinate(Earth3d.MainWindow.RenderContext11.CameraPosition, Matrix3d.Invert(Earth3d.WorldMatrix));

            if (!space3d)
            {
                if (Vector3d.Dot(cam, pos) < 0)
                {
                    return;
                }
            }
            var temp = pos;

            if (Earth3d.MainWindow.SolarSystemMode)
            {
                temp.Add( Earth3d.MainWindow.viewCamera.ViewTarget);
            }

            var wvp = renderContext.World * renderContext.View * renderContext.Projection;

            var screenPos = Vector3.Project(temp.Vector311, renderContext.ViewPort.TopLeftX, renderContext.ViewPort.TopLeftY,renderContext.ViewPort.Width,renderContext.ViewPort.Height, 0, 1, wvp.Matrix11);

            // Get the w component of the transformed object position; if it's negative the
            // object is behind the viewer.
            var w = wvp.M14 * temp.X + wvp.M24 * temp.Y + wvp.M34 * temp.Z + wvp.M44;
            if (w < 0.0 && Earth3d.MainWindow.SolarSystemMode)
            {
                // Don't show labels that are behind the viewer
                return;
            }

            screenPos = new Vector3((int)screenPos.X, (int)screenPos.Y, 1);

            Sprite2d.Draw2D(renderContext, texture, new SizeF(20, 20), new PointF(0, 0), 0, new PointF(screenPos.X, screenPos.Y), Color.White);

            if (Earth3d.MainWindow.SolarSystemMode || Style == LabelSytle.Telrad)
            {
                var worldMatrix = renderContext.World;
                var viewMatrix = renderContext.View;
                var projectionMatrix = renderContext.Projection;

                var labelScale = Earth3d.MainWindow.SolarSystemMode ? 8.0 : 30.0;
                renderContext.World =
                    Matrix3d.Scaling(labelScale, labelScale, 1.0) *
                    Matrix3d.Translation(screenPos.X + 10.0, -screenPos.Y, 0.0) *
                    Matrix3d.Translation(-renderContext.ViewPort.Width / 2, renderContext.ViewPort.Height / 2, 0);
                renderContext.View = Matrix3d.Identity;
                renderContext.Projection = Matrix3d.OrthoLH(renderContext.ViewPort.Width, renderContext.ViewPort.Height, 1, -1);

                renderContext.BlendMode = BlendMode.PremultipliedAlpha;
                textBatch.Draw(renderContext, 1, Color.White);

                renderContext.World = worldMatrix;
                renderContext.View = viewMatrix;
                renderContext.Projection = projectionMatrix;
            }
            else
            {
                renderContext.BlendMode = BlendMode.PremultipliedAlpha;
                textBatch.Draw(renderContext, 1, Color.White);
            }

            //todo11 Implement this
            //sprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.SortTexture);

            //sprite.Draw(texture, rect, center, screenPos, Color.White);
            //Rectangle recttext = new Rectangle((int)(screenPos.X + 15), (int)(screenPos.Y - 8), 0, 0);
            //Earth3d.MainWindow.labelFont.DrawText(sprite, Text, recttext,
            //DrawTextFormat.NoClip, System.Drawing.Color.White);

            //sprite.End();
        }
Пример #16
0
        public SkyLabel(RenderContext11 renderContext, Vector3d point, string text, LabelSytle style)
        {
            Text = text;
            Style = style;

            if (texture == null)
            {
                texture = Texture11.FromBitmap(Resources.circle, 0);
            }

            pos = point;

            center = new Vector3(9, 9, 0);

            textBatch = new Text3dBatch(80);

            if (style == LabelSytle.Telrad)
            {
                // Telrad-style labels are always screen-aligned
                var t3 = new Text3d(new Vector3d(0, 0, 0.1), new Vector3d(0, 1, 0), text, 20, .01);
                t3.alignment = Text3d.Alignment.Left;
                textBatch.Add(t3);
            }
            else
            {
                // This will produce sky or orbit aligned text
                textBatch.Add(new Text3d(pos, new Vector3d(0,1,0), text, 20, .01));
            }
        }
Пример #17
0
        public SkyLabel(RenderContext11 renderContext, double ra, double dec, string text, LabelSytle style, double distance)
        {
            RA = ra;
            Dec = dec;
            Text = text;
            Style = style;

            Distance = distance;

            if (texture == null)
            {
                texture = Texture11.FromBitmap(Resources.circle, 0);
            }

            var up = new Vector3d();
            var textPos = new Vector3d();
            if (Earth3d.MainWindow.SolarSystemMode)
            {
                pos = Coordinates.RADecTo3d(ra, -dec, distance);
                up = Coordinates.RADecTo3d(ra, -dec + 90, distance);

                pos.RotateX(Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI);
                pos.Add(Planets.GetPlanet3dLocation(SolarSystemObjects.Earth));

                up.RotateX(Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI);
                up.Add(Planets.GetPlanet3dLocation(SolarSystemObjects.Earth));
               }
            else
            {
                pos = Coordinates.RADecTo3d(ra+12, dec, distance);
                textPos = Coordinates.RADecTo3d(ra + 12, dec + 2, distance);
                up = Coordinates.RADecTo3d(ra+12, dec + 92, distance);

            }
            center = new Vector3(9, 9, 0);

            textBatch = new Text3dBatch(24);
            if (style == LabelSytle.Telrad)
            {
                // Telrad-style labels are always screen-aligned
                var t3 = new Text3d(new Vector3d(0, 0, 0.1), new Vector3d(0, 1, 0), text, 20, .01);
                t3.alignment = Text3d.Alignment.Left;
                textBatch.Add(t3);
            }
            else
            {
                up.Normalize();
                textPos.Normalize();
                textBatch.Add(new Text3d(textPos, up, text, 20, .0005));
            }
        }
Пример #18
0
        // Set up render context state required for drawing ground overlays when shaders
        // are enabled.
        public void SetupGroundOverlays(RenderContext11 renderContext)
        {
            // A shader should be set up already
            if (renderContext.Shader == null)
            {
                renderContext.SetupBasicEffect(BasicEffect.TextureOnly, 1.0f, Color.White);
            }

            // Count the number of overlays so that we can choose the appropriate shader
            var overlayCount = 0;
            foreach (var overlay in GroundOverlays)
            {
                if (overlay.Icon.Texture != null)
                {
                    ++overlayCount;
                }
            }

            overlayCount = Math.Min(PlanetShader11.MaxOverlayTextures, overlayCount);
            if (overlayCount == 0)
            {
                // No work to do
                return;
            }

            // Get a shader identical to the one currently in use, but which supports
            // the required number of overlays.
            var key = renderContext.Shader.Key;
            key.overlayTextureCount = overlayCount;
            var overlayShader = PlanetShader11.GetPlanetShader(renderContext.Device, key);
            renderContext.Shader = overlayShader;
            renderContext.Shader.DiffuseColor = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            var devContext = renderContext.Device.ImmediateContext;
            var overlayIndex = 0;
            foreach (var overlay in GroundOverlays)
            {
                var texture = overlay.Icon.Texture;
                if ( texture != null)
                {
                    if (overlayIndex < PlanetShader11.MaxOverlayTextures)
                    {
                        renderContext.Shader.SetOverlayTextureMatrix(overlayIndex, overlay.GetMatrix().Matrix11);
                        renderContext.Shader.SetOverlayTextureColor(overlayIndex, overlay.color);
                        renderContext.Shader.SetOverlayTexture(overlayIndex, texture.ResourceView);
                    }
                    ++overlayIndex;
                }
            }
        }
Пример #19
0
        public override bool PreCreateGeometry(RenderContext11 renderContext)
        {
            if (Properties.Settings.Default.Show3dCities)
            {
                // Conditionalsupport for 3d Cities based on settings
                dsm = new DSMTile();
                var center = new Vector3d();
                double radius = 0;
                if (dsm != null)
                {
                    texture = dsm.LoadMeshFile(filename, localCenter, out center, out radius);
                }
                if (texture != null)
                {
                    sphereCenter = center;
                    sphereRadius = radius;
                    return true;
                }

            }
            return false;
        }
Пример #20
0
        public override bool Draw(RenderContext11 renderContext, float opacity, bool flat)
        {
            if (RetainedVisualsDirty)
            {
                UpdateRetainedVisuals();
                RetainedVisualsDirty = false;
            }

            triangles.Draw(renderContext, opacity, TriangleList.CullMode.Clockwise);
            lines.DrawLines(renderContext, opacity);
            DrawPlaceMarks();
            DrawScreenOverlays(renderContext);
            return true;
        }
Пример #21
0
 internal static void DrawAll(RenderContext11 rendercontext)
 {
     foreach (Reticle reticle in Reticles.Values)
     {
         if (reticle.Visible.State)
         {
             reticle.Draw(rendercontext);
         }
     }
 }
Пример #22
0
 public override bool PreDraw(RenderContext11 renderContext, float opacity)
 {
     SetupGroundOverlays(renderContext);
     return true;
 }
        private void DrawTranparentBox(RenderContext11 renderContext, Rectangle rect)
        {
            Color Color = Color.FromArgb(128, 32, 32, 128);
            boxPoints[0].X = rect.X;
            boxPoints[0].Y = rect.Y;
            boxPoints[0].Z = .9f;
            boxPoints[0].W = 1;
            boxPoints[0].Tu = 0;
            boxPoints[0].Tv = 0;
            boxPoints[0].Color = Color;

            boxPoints[1].X = (float)(rect.X + (rect.Width));
            boxPoints[1].Y = (float)(rect.Y);
            boxPoints[1].Tu = 1;
            boxPoints[1].Tv = 0;
            boxPoints[1].Color = Color;
            boxPoints[1].Z = .9f;
            boxPoints[1].W = 1;

            boxPoints[2].X = (float)(rect.X );
            boxPoints[2].Y = (float)(rect.Y + (rect.Height ));
            boxPoints[2].Tu = 0;
            boxPoints[2].Tv = 1;
            boxPoints[2].Color = Color;
            boxPoints[2].Z = .9f;
            boxPoints[2].W = 1;

            boxPoints[3].X = (float)(rect.X + (rect.Width ));
            boxPoints[3].Y = (float)(rect.Y + (rect.Height ));
            boxPoints[3].Tu = 1;
            boxPoints[3].Tv = 1;
            boxPoints[3].Color = Color;
            boxPoints[3].Z = .9f;
            boxPoints[3].W = 1;

            SharpDX.Matrix mat = SharpDX.Matrix.OrthoLH(renderContext.ViewPort.Width, renderContext.ViewPort.Height, 1, -1);

            Sprite2d.Draw(renderContext, boxPoints, 4, mat, true);
        }
        public override bool Draw(RenderContext11 renderContext, float opacity, bool flat)
        {
            if (shapefile == null)
            {
                return false;
            }

            if (shapeFileVertex == null)
            {

                var vertList = new List<Vector3>();
                var indexList = new List<UInt32>();
                UInt32 firstItemIndex = 0;
                var lastItem = new Vector3();
                var firstItem = true;

                var north = true;
                double offsetX = 0;
                double offsetY = 0;
                double centralMeridian = 0;
                double mapScale = 0;
                double standardParallel = 70;

                if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                {
                    north = shapefile.FileHeader.ProjectionInfo.Name.ToLower().Contains("north");
                    standardParallel = shapefile.FileHeader.ProjectionInfo.GetParameter("standard_parallel_1");
                    centralMeridian = shapefile.FileHeader.ProjectionInfo.GetParameter("central_meridian");
                    mapScale = shapefile.FileHeader.ProjectionInfo.GetParameter("scale_factor");
                    offsetY = shapefile.FileHeader.ProjectionInfo.GetParameter("false_easting");
                    offsetX = shapefile.FileHeader.ProjectionInfo.GetParameter("false_northing");

                }

                UInt32 currentIndex = 0;
                var color = Color;
                var count = 360;
                for (var i = 0; i < shapefile.Shapes.Count; i++)
                {
                    if (shapefile.Shapes[i].GetType() == typeof(Polygon))
                    {
                        var p = (Polygon)shapefile.Shapes[i];

                        for (var z = 0; z < p.Rings.Length; z++)
                        {
                            count = (p.Rings[z].Points.Length);

                            // content from DBF
                            var dr = p.Rings[z].Attributes;

                            for (var k = 0; k < p.Rings[z].Points.Length; k++)
                            {
                                // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used.
                                var Xcoord = p.Rings[z].Points[k].X;
                                var Ycoord = p.Rings[z].Points[k].Y;

                                if (shapefile.Projection == ShapeFile.Projections.Geo)
                                {
                                    lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord);
                                }
                                else if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                                {
                                    lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3;
                                }

                                if (k == 0)
                                {
                                    firstItemIndex = currentIndex;
                                    firstItem = true;
                                }

                                vertList.Add(lastItem);

                                if (firstItem)
                                {
                                    firstItem = false;
                                }
                                else
                                {
                                    indexList.Add(currentIndex);
                                    currentIndex++;
                                    indexList.Add(currentIndex);
                                }
                            }

                            indexList.Add(currentIndex);
                            indexList.Add(firstItemIndex);
                            currentIndex++;

                        }
                    }
                    else if (shapefile.Shapes[i].GetType() == typeof(PolygonZ))
                    {
                        var p = (PolygonZ)shapefile.Shapes[i];

                        for (var z = 0; z < p.Rings.Length; z++)
                        {
                            count = (p.Rings[z].Points.Length);

                            // content from DBF
                            var dr = p.Rings[z].Attributes;

                            for (var k = 0; k < p.Rings[z].Points.Length; k++)
                            {
                                // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used.
                                var Xcoord = p.Rings[z].Points[k].X;
                                var Ycoord = p.Rings[z].Points[k].Y;

                                if (shapefile.Projection == ShapeFile.Projections.Geo)
                                {
                                    lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord);
                                }
                                else if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                                {
                                    lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3;
                                }

                                if (k == 0)
                                {
                                    firstItemIndex = currentIndex;
                                    firstItem = true;
                                }

                                vertList.Add(lastItem);

                                if (firstItem)
                                {
                                    firstItem = false;
                                }
                                else
                                {
                                    indexList.Add(currentIndex);
                                    currentIndex++;
                                    indexList.Add(currentIndex);
                                }
                            }

                            indexList.Add(currentIndex);
                            indexList.Add(firstItemIndex);
                            currentIndex++;

                        }
                    }
                    else if (shapefile.Shapes[i].GetType() == typeof(PolyLine))
                    {
                        var p = (PolyLine)shapefile.Shapes[i];
                        for (var z = 0; z < p.Lines.Length; z++)
                        {
                            count = (p.Lines[z].Points.Length);

                            firstItem = true;
                            for (var k = 0; k < p.Lines[z].Points.Length; k++)
                            {
                                // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used.
                                var Xcoord = p.Lines[z].Points[k].X;
                                var Ycoord = p.Lines[z].Points[k].Y;
                                if (shapefile.Projection == ShapeFile.Projections.Geo)
                                {
                                    lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord);
                                }
                                else if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                                {
                                    lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3;
                                }

                                if (k == 0)
                                {
                                    firstItemIndex = currentIndex;
                                    firstItem = true;
                                }

                                vertList.Add(lastItem);

                                if (firstItem)
                                {
                                    firstItem = false;
                                }
                                else
                                {
                                    indexList.Add(currentIndex);
                                    currentIndex++;
                                    indexList.Add(currentIndex);
                                }

                            }
                            currentIndex++;

                        }
                    }
                    else if (shapefile.Shapes[i].GetType() == typeof(PolyLineZ))
                    {
                        var p = (PolyLineZ)shapefile.Shapes[i];
                        for (var z = 0; z < p.Lines.Length; z++)
                        {
                            count = (p.Lines[z].Points.Length);
                            var points = new Vector3[(count)];

                            firstItem = true;
                            for (var k = 0; k < p.Lines[z].Points.Length; k++)
                            {
                                // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used.
                                var Xcoord = p.Lines[z].Points[k].X;
                                var Ycoord = p.Lines[z].Points[k].Y;
                                if (shapefile.Projection == ShapeFile.Projections.Geo)
                                {
                                    lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord);
                                }
                                else if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                                {
                                    lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3;
                                }

                                if (k == 0)
                                {
                                    firstItemIndex = currentIndex;
                                    firstItem = true;
                                }

                                vertList.Add(lastItem);

                                if (firstItem)
                                {
                                    firstItem = false;
                                }
                                else
                                {
                                    indexList.Add(currentIndex);
                                    currentIndex++;
                                    indexList.Add(currentIndex);
                                }

                            }
                            currentIndex++;

                        }
                    }
                    else if (shapefile.Shapes[i].GetType() == typeof(Point))
                    {
                        var p = (Point)shapefile.Shapes[i];

                        // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used.
                        var Xcoord = p.X;
                        var Ycoord = p.Y;
                        if (shapefile.Projection == ShapeFile.Projections.Geo)
                        {
                            lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord);
                        }
                        else if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                        {
                            lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3;
                        }

                        vertList.Add(lastItem);

                        currentIndex++;
                        lines = false;
                    }

                }

                shapeVertexCount = vertList.Count;
                shapeFileVertex = new PositionVertexBuffer11(vertList.Count, RenderContext11.PrepDevice);

                var verts = (Vector3[])shapeFileVertex.Lock(0, 0); // Lock the buffer (which will return our structs)
                var indexer = 0;
                foreach (var vert in vertList)
                {
                    verts[indexer++] = vert;
                }
                shapeFileVertex.Unlock();

                shapeIndexCount = indexList.Count;

                if (lines)
                {
                    if (indexList.Count > 65500)
                    {
                        isLongIndex = true;
                        shapeFileIndex = new IndexBuffer11(typeof(UInt32), indexList.Count, RenderContext11.PrepDevice);
                    }
                    else
                    {
                        isLongIndex = false;
                        shapeFileIndex = new IndexBuffer11(typeof(short), indexList.Count, RenderContext11.PrepDevice);
                    }

                    if (isLongIndex)
                    {
                        indexer = 0;
                        var indexes = (UInt32[])shapeFileIndex.Lock();
                        foreach (var indexVal in indexList)
                        {
                            indexes[indexer++] = indexVal;
                        }
                        shapeFileIndex.Unlock();
                    }
                    else
                    {
                        indexer = 0;
                        var indexes = (short[])shapeFileIndex.Lock();
                        foreach (var indexVal in indexList)
                        {
                            indexes[indexer++] = (short)indexVal;
                        }
                        shapeFileIndex.Unlock();
                    }
                }
            }

            renderContext.DepthStencilMode = DepthStencilMode.Off;
            renderContext.BlendMode = BlendMode.Alpha;
            SimpleLineShader11.Color = Color.FromArgb((int)(opacity * 255), Color);

            var mat = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            mat.Transpose();

            SimpleLineShader11.WVPMatrix = mat;
            SimpleLineShader11.CameraPosition = Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.Invert(renderContext.World)).Vector3;
            SimpleLineShader11.ShowFarSide = false;
            SimpleLineShader11.Sky = false;

            renderContext.SetVertexBuffer(shapeFileVertex);
            SimpleLineShader11.Use(renderContext.devContext);

            if (lines)
            {
                renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineList;
                renderContext.SetIndexBuffer(shapeFileIndex);
                renderContext.devContext.DrawIndexed(shapeFileIndex.Count, 0, 0);
            }
            else
            {
                renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList;
                renderContext.devContext.Draw(shapeVertexCount, 0);
            }

            renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;

            return true;
        }
Пример #25
0
        public void DrawScreenOverlays(RenderContext11 renderContext)
        {
            foreach (KmlScreenOverlay overlay in ScreenOverlays)
            {

                Texture11 texture = overlay.Icon.Texture;

                if (texture != null)
                {
                    PointF center = new PointF();
                    PointF screen = new PointF();

                    SizeF size = new SizeF();

                    if (overlay.RotationSpot.UnitsX == KmlPixelUnits.Fraction)
                    {
                        center.X = overlay.RotationSpot.X * texture.Width;
                    }

                    if (overlay.RotationSpot.UnitsY == KmlPixelUnits.Fraction)
                    {
                        center.Y = overlay.RotationSpot.Y * texture.Height;
                    }

                    Rectangle clientRect = Earth3d.MainWindow.ClearClientArea;

                    Size clientSize = clientRect.Size;

                    if (overlay.ScreenSpot.UnitsX == KmlPixelUnits.Fraction)
                    {
                        screen.X = overlay.ScreenSpot.X * clientSize.Width;
                    }
                    else if (overlay.Size.UnitsX == KmlPixelUnits.Pixels)
                    {
                        screen.X = overlay.ScreenSpot.X;
                    }

                    if (overlay.ScreenSpot.UnitsY == KmlPixelUnits.Fraction)
                    {
                        screen.Y = overlay.ScreenSpot.Y * clientSize.Height;
                    }
                    else if (overlay.Size.UnitsY == KmlPixelUnits.Pixels)
                    {
                        screen.Y = overlay.ScreenSpot.Y;
                    }

                    if (overlay.Size.UnitsX == KmlPixelUnits.Fraction)
                    {
                        if (overlay.Size.X == -1)
                        {
                            size.Width = texture.Width;
                        }
                        else
                        {
                            size.Width = overlay.Size.X * clientSize.Width;
                        }
                    }
                    else if (overlay.Size.UnitsX == KmlPixelUnits.Pixels)
                    {
                        if (overlay.Size.X == -1)
                        {
                            size.Width = texture.Width;
                        }
                        else
                        {
                            size.Width = overlay.Size.X;
                        }
                    }

                    if (overlay.Size.UnitsY == KmlPixelUnits.Fraction)
                    {
                        size.Height = overlay.Size.Y * clientSize.Height;
                    }
                    else if (overlay.Size.UnitsY == KmlPixelUnits.Pixels)
                    {
                        if (overlay.Size.Y == -1)
                        {
                            size.Height = texture.Height;
                        }
                        else
                        {
                            size.Height = overlay.Size.Y;
                        }
                    }
                    screen.Y = clientRect.Bottom - screen.Y - size.Height + center.Y;
                    screen.X = clientRect.Left + screen.X + center.X;

                    Sprite2d.Draw2D(renderContext, texture, size, center, (float)overlay.Rotation, screen, overlay.color);
                    //sprite.Draw2D(texture, Rectangle.Empty, size, center, (float)overlay.Rotation, screen, Color.White);

                }

            }
        }
Пример #26
0
        public void UseShader(RenderContext11 renderContext, double semiMajorAxis, double eccentricity, double eccentricAnomaly, Color color, Matrix3d world, Vector3d positionNow)
        {
            SemiMajorAxis = (float)semiMajorAxis;
            Eccentricity = (float)eccentricity;
            EccentricAnomaly = (float)eccentricAnomaly;

            Color = color;
            PositionNow = positionNow;

            Matrix matrixWVP = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            matrixWVP.Transpose();
            MatWVP = matrixWVP;

            Matrix positionWVP = (world * renderContext.View * renderContext.Projection).Matrix11;
            positionWVP.Transpose();

            MatPositionWVP = positionWVP;

            Use(renderContext.devContext);
        }
Пример #27
0
 public void SetupGroundOverlays(RenderContext11 renderContext)
 {
     foreach (KmlGroundOverlay overlay in GroundOverlays)
     {
         if (Earth3d.MainWindow.KmlMarkers != null)
         {
             if (overlay.ShouldDisplay())
             {
                 Earth3d.MainWindow.KmlMarkers.AddGroundOverlay(overlay);
             }
         }
     }
 }
Пример #28
0
        public static void UseShader(RenderContext11 renderContext, Color color, Matrix3d world, Vector3d positionNow, double timeOffset, double coverageDuration)
        {
            TimeOffset = (float)timeOffset;
            CoverageDuration = (float)coverageDuration;

            Color = color;
            PositionNow = positionNow;

            Matrix matrixWVP = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            matrixWVP.Transpose();
            MatWVP = matrixWVP;

            Matrix positionWVP = (world * renderContext.View * renderContext.Projection).Matrix11;
            positionWVP.Transpose();

            MatPositionWVP = positionWVP;

            Use(renderContext.devContext);
        }
Пример #29
0
        public virtual void Draw3D(RenderContext11 renderContext, float transparancy, bool designTime)
        {
            if (texture == null || isDynamic)
            {
                InitializeTexture();
            }

            if (!isDesignTimeOnly || designTime)
            {
                InitiaizeGeometry();

                UpdateRotation(); ;

                Sprite2d.Draw(renderContext, points, points.Length, texture, TriangleStrip ? SharpDX.Direct3D.PrimitiveTopology.TriangleStrip : SharpDX.Direct3D.PrimitiveTopology.TriangleList);
            }
        }
Пример #30
0
        public void Draw(RenderContext11 renderContext, float Opacity, Color drawColor)
        {
            if (glyphCache == null || glyphCache.Version > glyphVersion)
            {
                PrepareBatch();
            }

            //todo11 Use Shader

            renderContext.SetupBasicEffect(BasicEffect.TextureColorOpacity, Opacity, drawColor);
            renderContext.MainTexture = glyphCache.Texture;
            renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;

            renderContext.PreDraw();

            if (layout == null)
            {
                layout = new SharpDX.Direct3D11.InputLayout(renderContext.Device, renderContext.Shader.InputSignature, new[]
                           {
                               new SharpDX.Direct3D11.InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32_Float,     0, 0),
                               new SharpDX.Direct3D11.InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float,       12, 0),
                           });
            }
            renderContext.Device.ImmediateContext.InputAssembler.InputLayout = layout;

            renderContext.SetVertexBuffer(vertexBuffer);

            renderContext.devContext.Draw(vertexBuffer.Count, 0);
        }