Exemplo n.º 1
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);
            SharpDX.Matrix mvp = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            mvp.Transpose();
            PointSpriteShader11.WVPMatrix = mvp;
            PointSpriteShader11.Color     = SharpDX.Color.White;

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

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

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

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

            renderContext.Device.ImmediateContext.GeometryShader.Set(null);
        }
Exemplo n.º 2
0
        public override bool Draw3D(RenderContext11 renderContext, float opacity, Tile parent)
        {
            InViewFrustum      = true;
            RenderedGeneration = CurrentRenderGeneration;
            if (!ReadyToRender)
            {
                TileCache.AddTileToQueue(this);
                return(false);
            }

            InViewFrustum = true;

            if (starVertexBuffer == null)
            {
                starProfile = Texture11.FromBitmap(Properties.Resources.StarProfile);

                int count = stars.Count;
                int index = 0;
                starCount = count;

                starVertexBuffer = new PositionColorSizeVertexBuffer11(count, RenderContext11.PrepDevice);

                PositionColorSize[] points = (PositionColorSize[])starVertexBuffer.Lock(0, 0); // Lock the buffer (which will return our structs)
                foreach (Star star in stars)
                {
                    Vector3d pos = Coordinates.RADecTo3d(star.RA + 12, star.Dec, 1f);
                    points[index].Position = pos.Vector3;
                    points[index].Color    = star.Col;
                    double radDec = (.5) / Math.Pow(1.6, star.Magnitude);
                    points[index].size = (float)radDec;
                    index++;
                }
                starVertexBuffer.Unlock();
            }

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

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

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

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


            renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.PointList;
            renderContext.devContext.Draw(starCount, 0);

            renderContext.Device.ImmediateContext.GeometryShader.Set(null);

            // Reset blend mode so we don't mess up subsequent sky layer rendering
            renderContext.BlendMode = BlendMode.Alpha;

            return(true);
        }
Exemplo n.º 3
0
        // ** Begin
        public static void DrawMPC3D(RenderContext11 renderContext, float opacity, Vector3d centerPoint)
        {
            double zoom      = Earth3d.MainWindow.ZoomFactor;
            double distAlpha = ((Math.Log(Math.Max(1, zoom), 4)) - 15.5) * 90;

            int alpha = Math.Min(255, Math.Max(0, (int)distAlpha));


            if (alpha > 254)
            {
                return;
            }


            if (mpcVertexBuffer == null)
            {
                for (int i = 0; i < 7; i++)
                {
                    mpcBlendStates[i] = new BlendState(false, 1000, 0);
                }

                if (!initBegun)
                {
                    MethodInvoker initDelegate = new MethodInvoker(StartInit);

                    initDelegate.BeginInvoke(null, null);
                    initBegun = true;
                }
                return;
            }


            renderContext.DepthStencilMode = DepthStencilMode.Off;


            renderContext.setRasterizerState(TriangleCullMode.Off);


            Matrix3d offset    = Matrix3d.Translation(-centerPoint);
            Matrix3d world     = renderContext.World * offset;
            Matrix   matrixWVP = (world * renderContext.View * renderContext.Projection).Matrix11;

            matrixWVP.Transpose();


            Vector3 cam = Vector3.TransformCoordinate(renderContext.CameraPosition.Vector311, Matrix.Invert(renderContext.World.Matrix11));



            renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, Grids.StarProfile.ResourceView);
            renderContext.BlendMode = BlendMode.Additive;

            if (mpcVertexBuffer != null)
            {
                for (int i = 0; i < 7; i++)
                {
                    mpcBlendStates[i].TargetState = ((Properties.Settings.Default.MinorPlanetsFilter & (int)Math.Pow(2, i)) != 0);

                    if (mpcBlendStates[i].State)
                    {
                        if (mpcVertexBuffer[i].Downlevel)
                        {
                            DownlevelKeplerPointSpriteShader11.Constants.JNow                = (float)(SpaceTimeController.JNow - KeplerVertex.baseDate);
                            DownlevelKeplerPointSpriteShader11.Constants.Opacity             = opacity * mpcBlendStates[i].Opacity;
                            DownlevelKeplerPointSpriteShader11.Constants.MM                  = 0;
                            DownlevelKeplerPointSpriteShader11.Constants.WorldViewProjection = matrixWVP;
                            DownlevelKeplerPointSpriteShader11.Constants.Scale               = new SharpDX.Vector2(100f, 100f);
                            DownlevelKeplerPointSpriteShader11.Constants.ViewportScale       = new SharpDX.Vector2(2f / renderContext.ViewPort.Width, 2f / renderContext.ViewPort.Height);
                            DownlevelKeplerPointSpriteShader11.Constants.CameraPosition      = new SharpDX.Vector4(cam, 1);
                            DownlevelKeplerPointSpriteShader11.Use(renderContext.devContext, mpcVertexBuffer[i].Instanced);
                        }
                        else
                        {
                            KeplerPointSpriteShader11.Constants.JNow                = (float)(SpaceTimeController.JNow - KeplerVertex.baseDate);
                            KeplerPointSpriteShader11.Constants.Opacity             = opacity * mpcBlendStates[i].Opacity;
                            KeplerPointSpriteShader11.Constants.MM                  = 0;
                            KeplerPointSpriteShader11.Constants.WorldViewProjection = matrixWVP;
                            KeplerPointSpriteShader11.Constants.Scale               = new SharpDX.Vector2(100f, 100f);
                            KeplerPointSpriteShader11.Constants.ViewportScale       = new SharpDX.Vector2(2f / renderContext.ViewPort.Width, 2 / renderContext.ViewPort.Height);
                            KeplerPointSpriteShader11.Constants.CameraPosition      = new SharpDX.Vector4(cam, 1);
                            KeplerPointSpriteShader11.Use(renderContext.devContext);
                        }

                        mpcVertexBuffer[i].Draw(renderContext, mpcVertexBuffer[i].Count, null, opacity);
                    }
                }
            }
            renderContext.BlendMode = BlendMode.Alpha;

            renderContext.Device.ImmediateContext.GeometryShader.Set(null);
        }
Exemplo n.º 4
0
        public void DrawLines(RenderContext11 renderContext, float opacity)
        {
            if (linePoints.Count < 2 || opacity <= 0)
            {
                return;
            }
            InitLineBuffer();
            Matrix3d savedWorld = renderContext.World;
            Matrix3d savedView  = renderContext.View;

            if (localCenter != Vector3d.Empty)
            {
                usingLocalCenter = true;
                Vector3d temp = localCenter;
                if (UseNonRotatingFrame)
                {
                    renderContext.World = Matrix3d.Translation(temp) * renderContext.WorldBaseNonRotating * Matrix3d.Translation(-renderContext.CameraPosition);
                }
                else
                {
                    renderContext.World = Matrix3d.Translation(temp) * renderContext.WorldBase * Matrix3d.Translation(-renderContext.CameraPosition);
                }
                renderContext.View = Matrix3d.Translation(renderContext.CameraPosition) * renderContext.ViewBase;
            }

            DateTime baseDate = new DateTime(2010, 1, 1, 12, 00, 00);

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


            LineShaderNormalDates11.Constants.JNow        = (float)(SpaceTimeController.JNow - SpaceTimeController.UtcToJulian(baseDate));
            LineShaderNormalDates11.Constants.Sky         = Sky ? 1 : 0;
            LineShaderNormalDates11.Constants.ShowFarSide = ShowFarSide ? 1 : 0;
            if (TimeSeries)
            {
                LineShaderNormalDates11.Constants.Decay = (float)Decay;
            }
            else
            {
                LineShaderNormalDates11.Constants.Decay = 0;
            }

            LineShaderNormalDates11.Constants.Opacity        = opacity;
            LineShaderNormalDates11.Constants.CameraPosition = new SharpDX.Vector4(Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.Invert(renderContext.World)).Vector311, 1);
            SharpDX.Matrix mat = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            mat.Transpose();

            LineShaderNormalDates11.Constants.WorldViewProjection = mat;

            LineShaderNormalDates11.Use(renderContext.devContext);

            renderContext.DepthStencilMode = DepthBuffered ? DepthStencilMode.ZReadWrite : DepthStencilMode.Off;

            int index = 0;

            foreach (TimeSeriesLineVertexBuffer11 lineBuffer in lineBuffers)
            {
                renderContext.SetVertexBuffer(lineBuffer);
                renderContext.devContext.Draw(lineBuffer.Count, 0);
            }

            renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite;

            if (usingLocalCenter)
            {
                renderContext.World = savedWorld;
                renderContext.View  = savedView;
            }
        }
Exemplo n.º 5
0
        public void Draw(RenderContext11 renderContext, float opacity, CullMode cull)
        {
            renderContext.BlendMode = BlendMode.Alpha;

            if (trianglePoints.Count < 1 && !dataToDraw)
            {
                return;
            }

            InitTriangleBuffer();

            renderContext.DepthStencilMode = DepthBuffered ? (WriteZbuffer  ? DepthStencilMode.ZReadWrite : DepthStencilMode.ZReadOnly) : DepthStencilMode.Off;

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

            switch (cull)
            {
            case CullMode.Clockwise:
                renderContext.setRasterizerState(TriangleCullMode.CullClockwise);
                break;

            case CullMode.CounterClockwise:
                renderContext.setRasterizerState(TriangleCullMode.CullCounterClockwise);
                break;

            case CullMode.None:
                renderContext.setRasterizerState(TriangleCullMode.Off);
                break;

            default:
                break;
            }


            if (AutoTime)
            {
                DateTime baseDate = new DateTime(2010, 1, 1, 12, 00, 00);
                LineShaderNormalDates11.Constants.JNow = (float)(SpaceTimeController.JNow - SpaceTimeController.UtcToJulian(baseDate));
            }
            else
            {
                LineShaderNormalDates11.Constants.JNow = (float)JNow;
            }

            LineShaderNormalDates11.Constants.Sky         = 0;
            LineShaderNormalDates11.Constants.ShowFarSide = ShowFarSide ? 1 : 0;
            if (TimeSeries)
            {
                LineShaderNormalDates11.Constants.Decay = (float)Decay;
            }
            else
            {
                LineShaderNormalDates11.Constants.Decay = 0;
            }
            LineShaderNormalDates11.Constants.Opacity        = opacity;
            LineShaderNormalDates11.Constants.CameraPosition = new SharpDX.Vector4(Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.Invert(renderContext.World)).Vector311, 1);

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

            LineShaderNormalDates11.Constants.WorldViewProjection = mat;

            LineShaderNormalDates11.Use(renderContext.devContext);

            foreach (TimeSeriesLineVertexBuffer11 vertBuffer in triangleBuffers)
            {
                renderContext.SetVertexBuffer(vertBuffer);
                renderContext.devContext.Draw(vertBuffer.Count, 0);
            }
        }
Exemplo n.º 6
0
        public void DrawLines(RenderContext11 renderContext, float opacity, Color color)
        {
            if (linePoints.Count < 2)
            {
                return;
            }

            InitLineBuffer();



            Matrix3d savedWorld = renderContext.World;
            Matrix3d savedView  = renderContext.View;

            if (localCenter != Vector3d.Empty)
            {
                usingLocalCenter = true;
                Vector3d temp = localCenter;
                if (UseNonRotatingFrame)
                {
                    renderContext.World = Matrix3d.Translation(temp) * renderContext.WorldBaseNonRotating * Matrix3d.Translation(-renderContext.CameraPosition);
                }
                else
                {
                    renderContext.World = Matrix3d.Translation(temp) * renderContext.WorldBase * Matrix3d.Translation(-renderContext.CameraPosition);
                }
                renderContext.View = Matrix3d.Translation(renderContext.CameraPosition) * renderContext.ViewBase;
            }

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

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


            SimpleLineShader11.Color = col;

            SharpDX.Matrix 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    = true;
            SimpleLineShader11.Sky            = Sky;

            renderContext.setRasterizerState(TriangleCullMode.CullClockwise);
            if (DepthBuffered)
            {
                renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite;
            }
            else
            {
                renderContext.DepthStencilMode = DepthStencilMode.Off;
            }

            SimpleLineShader11.Use(renderContext.devContext);

            if (aaFix)
            {
                renderContext.setRasterizerState(TriangleCullMode.Off, false);
            }

            foreach (PositionVertexBuffer11 lineBuffer in lineBuffers)
            {
                renderContext.SetVertexBuffer(lineBuffer);
                renderContext.SetIndexBuffer(null);
                renderContext.devContext.Draw(lineBuffer.Count, 0);
            }

            if (aaFix)
            {
                renderContext.setRasterizerState(TriangleCullMode.Off, true);
            }

            if (usingLocalCenter)
            {
                renderContext.World = savedWorld;
                renderContext.View  = savedView;
            }
        }
Exemplo n.º 7
0
        public override bool Draw(RenderContext11 renderContext, float opacity, bool flat)
        {
            if (bufferIsFlat != flat)
            {
                CleanUp();
                bufferIsFlat = flat;
            }

            if (!CleanAndReady)
            {
                PrepVertexBuffer(opacity);
            }

            Matrix3d oldWorld = renderContext.World;

            if (astronomical && !bufferIsFlat)
            {
                double ecliptic = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI;
                renderContext.World = Matrix3d.RotationX(ecliptic) * renderContext.World;
            }


            if (triangleList2d != null)
            {
                triangleList2d.Decay      = decay;
                triangleList2d.Sky        = this.Astronomical;
                triangleList2d.TimeSeries = timeSeries;
                triangleList2d.Draw(renderContext, opacity * Opacity, TerraViewer.TriangleList.CullMode.CounterClockwise);
            }

            if (triangleList != null)
            {
                triangleList.Decay      = decay;
                triangleList.Sky        = this.Astronomical;
                triangleList.TimeSeries = timeSeries;
                triangleList.Draw(renderContext, opacity * Opacity, TerraViewer.TriangleList.CullMode.CounterClockwise);
            }

            if (lineList != null)
            {
                lineList.Sky        = this.Astronomical;
                lineList.Decay      = decay;
                lineList.TimeSeries = timeSeries;

                lineList.DrawLines(renderContext, opacity * Opacity);
            }

            if (lineList2d != null)
            {
                lineList2d.Sky         = !this.Astronomical;
                lineList2d.Decay       = decay;
                lineList2d.TimeSeries  = timeSeries;
                lineList2d.ShowFarSide = ShowFarSide;
                lineList2d.DrawLines(renderContext, opacity * Opacity);
            }

            if (textBatch != null)
            {
                DepthStencilMode mode = renderContext.DepthStencilMode;

                renderContext.DepthStencilMode = DepthStencilMode.Off;

                textBatch.Draw(renderContext, 1, Color.White);
                renderContext.DepthStencilMode = mode;
            }

            if (astronomical && !bufferIsFlat)
            {
                renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite;
            }
            else
            {
                renderContext.DepthStencilMode = DepthStencilMode.Off;
            }

            DateTime baseDate = new DateTime(2010, 1, 1, 12, 00, 00);

            renderContext.setRasterizerState(TriangleCullMode.Off);

            Vector3 cam           = Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.Invert(renderContext.World)).Vector311;
            float   adjustedScale = scaleFactor;

            if (flat && astronomical && (markerScale == MarkerScales.World))
            {
                adjustedScale = (float)(scaleFactor / (Earth3d.MainWindow.ZoomFactor / 360));
            }

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

            matrixWVP.Transpose();
            switch (plotType)
            {
            default:
            case PlotTypes.Gaussian:
                renderContext.BlendMode = BlendMode.Additive;
                renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, Grids.StarProfile.ResourceView);
                break;

            case PlotTypes.Circle:
                renderContext.BlendMode = BlendMode.Alpha;
                renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, CircleTexture.ResourceView);
                break;

            case PlotTypes.Point:
                renderContext.BlendMode = BlendMode.Alpha;
                renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, PointTexture.ResourceView);
                break;

            case PlotTypes.Square:
                renderContext.BlendMode = BlendMode.Alpha;
                renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, SquareTexture.ResourceView);
                break;

            case PlotTypes.Target1:
                renderContext.BlendMode = BlendMode.Alpha;
                renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, Target1Texture.ResourceView);
                break;

            case PlotTypes.Target2:
                renderContext.BlendMode = BlendMode.Alpha;
                renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, Target2Texture.ResourceView);
                break;

            case PlotTypes.PushPin:
                renderContext.BlendMode = BlendMode.Alpha;
                renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, PushPin.GetPushPinTexture(markerIndex).ResourceView);
                break;
            }

            columnChartsActivate.TargetState = plotType == PlotTypes.Column;

            if (shapeFileVertex != null)
            {
                if (plotType == PlotTypes.Column && !RenderContext11.Downlevel) // column chart mode
                {
                    columnChartsActivate.TargetState = true;

                    renderContext.BlendMode = BlendMode.Alpha;
                    renderContext.setRasterizerState(TriangleCullMode.CullClockwise);
                    renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, null);
                    renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite;
                    TimeSeriesColumnChartShader11.Constants.CameraPosition = new SharpDX.Vector4(cam, 1);
                    TimeSeriesColumnChartShader11.Constants.JNow           = (float)(SpaceTimeController.JNow - SpaceTimeController.UtcToJulian(baseDate));
                    TimeSeriesColumnChartShader11.Constants.Decay          = timeSeries ? decay : 0f;
                    TimeSeriesColumnChartShader11.Constants.Scale          = (float)(adjustedScale);
                    TimeSeriesColumnChartShader11.Constants.Sky            = astronomical ? -1 : 1;
                    TimeSeriesColumnChartShader11.Constants.Opacity        = opacity * this.Opacity;
                    TimeSeriesColumnChartShader11.Constants.ShowFarSide    = ShowFarSide ? 1f : 0f;
                    TimeSeriesColumnChartShader11.Color = new SharpDX.Color4(Color.R / 255f, Color.G / 255f, Color.B / 255f, Color.A / 255f);
                    TimeSeriesColumnChartShader11.Constants.WorldViewProjection = matrixWVP;
                    TimeSeriesColumnChartShader11.ViewportScale = new SharpDX.Vector2(2.0f / renderContext.ViewPort.Width, 2.0f / renderContext.ViewPort.Height);
                    TimeSeriesColumnChartShader11.Use(renderContext.devContext);
                }
                else if (plotType == PlotTypes.Cylinder && !RenderContext11.Downlevel)
                {
                    renderContext.BlendMode = BlendMode.Alpha;
                    renderContext.setRasterizerState(TriangleCullMode.CullClockwise);
                    renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, null);
                    renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite;
                    TimeSeriesColumnChartShaderNGon11.Constants.CameraPosition = new SharpDX.Vector4(cam, 1);
                    TimeSeriesColumnChartShaderNGon11.Constants.JNow           = (float)(SpaceTimeController.JNow - SpaceTimeController.UtcToJulian(baseDate));
                    TimeSeriesColumnChartShaderNGon11.Constants.Decay          = timeSeries ? decay : 0f;
                    TimeSeriesColumnChartShaderNGon11.Constants.Scale          = (float)(adjustedScale);
                    TimeSeriesColumnChartShaderNGon11.Constants.Sky            = astronomical ? -1 : 1;
                    TimeSeriesColumnChartShaderNGon11.Constants.Opacity        = opacity * this.Opacity;
                    TimeSeriesColumnChartShaderNGon11.Constants.ShowFarSide    = ShowFarSide ? 1f : 0f;
                    TimeSeriesColumnChartShaderNGon11.Color = new SharpDX.Color4(Color.R / 255f, Color.G / 255f, Color.B / 255f, Color.A / 255f);
                    TimeSeriesColumnChartShaderNGon11.Constants.WorldViewProjection = matrixWVP;
                    TimeSeriesColumnChartShaderNGon11.ViewportScale = new SharpDX.Vector2(2.0f / renderContext.ViewPort.Width, 2.0f / renderContext.ViewPort.Height);
                    TimeSeriesColumnChartShaderNGon11.Use(renderContext.devContext);
                }
                else
                {
                    TimeSeriesPointSpriteShader11.Constants.CameraPosition = new SharpDX.Vector4(cam, 1);
                    double jBase = SpaceTimeController.UtcToJulian(baseDate);
                    TimeSeriesPointSpriteShader11.Constants.JNow        = (float)(SpaceTimeController.JNow - jBase);
                    TimeSeriesPointSpriteShader11.Constants.Decay       = timeSeries ? decay : 0f;
                    TimeSeriesPointSpriteShader11.Constants.Scale       = ((markerScale == MarkerScales.World) ? ((float)adjustedScale) : (-(float)adjustedScale));
                    TimeSeriesPointSpriteShader11.Constants.Sky         = astronomical ? -1 : 1;
                    TimeSeriesPointSpriteShader11.Constants.Opacity     = opacity * this.Opacity;
                    TimeSeriesPointSpriteShader11.Constants.ShowFarSide = ShowFarSide ? 1f : 0f;
                    TimeSeriesPointSpriteShader11.Color = new SharpDX.Color4(Color.R / 255f, Color.G / 255f, Color.B / 255f, Color.A / 255f);
                    TimeSeriesPointSpriteShader11.Constants.WorldViewProjection = matrixWVP;
                    TimeSeriesPointSpriteShader11.ViewportScale     = new SharpDX.Vector2(2.0f / renderContext.ViewPort.Width, 2.0f / renderContext.ViewPort.Height);
                    TimeSeriesPointSpriteShader11.PointScaleFactors = new SharpDX.Vector3(0.0f, 0.0f, 10.0f);
                    if (shapeFileVertex.Downlevel)
                    {
                        DownlevelTimeSeriesPointSpriteShader.Use(renderContext.devContext, shapeFileVertex.Instanced);
                    }
                    else
                    {
                        TimeSeriesPointSpriteShader11.Use(renderContext.devContext);
                    }
                }


                shapeFileVertex.Draw(renderContext, shapeFileVertex.Count, null, 1.0f);
            }
            renderContext.Device.ImmediateContext.GeometryShader.Set(null);
            renderContext.BlendMode = BlendMode.Alpha;


            renderContext.World = oldWorld;

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

            if (shapeFileVertex == null)
            {
                List <Vector3> vertList       = new List <Vector3>();
                List <UInt32>  indexList      = new List <UInt32>();
                UInt32         firstItemIndex = 0;
                Vector3        lastItem       = new Vector3();
                bool           firstItem      = true;



                bool   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;
                Color  color        = Color;
                int    count        = 360;
                for (int i = 0; i < shapefile.Shapes.Count; i++)
                {
                    if (shapefile.Shapes[i].GetType() == typeof(Polygon))
                    {
                        Polygon p = (Polygon)shapefile.Shapes[i];

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

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

                            for (int 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.
                                double Xcoord = p.Rings[z].Points[k].X;
                                double 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))
                    {
                        PolygonZ p = (PolygonZ)shapefile.Shapes[i];

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

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

                            for (int 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.
                                double Xcoord = p.Rings[z].Points[k].X;
                                double 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))
                    {
                        PolyLine p = (PolyLine)shapefile.Shapes[i];
                        for (int z = 0; z < p.Lines.Length; z++)
                        {
                            count = (p.Lines[z].Points.Length);

                            firstItem = true;
                            for (int 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.
                                double Xcoord = p.Lines[z].Points[k].X;
                                double 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))
                    {
                        PolyLineZ p = (PolyLineZ)shapefile.Shapes[i];
                        for (int z = 0; z < p.Lines.Length; z++)
                        {
                            count = (p.Lines[z].Points.Length);
                            Vector3[] points = new Vector3[(count)];

                            firstItem = true;
                            for (int 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.
                                double Xcoord = p.Lines[z].Points[k].X;
                                double 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(ShapefileTools.Point))
                    {
                        ShapefileTools.Point p = (ShapefileTools.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.
                        double Xcoord = p.X;
                        double 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);

                Vector3[] verts   = (Vector3[])shapeFileVertex.Lock(0, 0); // Lock the buffer (which will return our structs)
                int       indexer = 0;
                foreach (Vector3 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;
                        UInt32[] indexes = (UInt32[])shapeFileIndex.Lock();
                        foreach (UInt32 indexVal in indexList)
                        {
                            indexes[indexer++] = indexVal;
                        }
                        shapeFileIndex.Unlock();
                    }
                    else
                    {
                        indexer = 0;
                        short[] indexes = (short[])shapeFileIndex.Lock();
                        foreach (UInt32 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);

            SharpDX.Matrix 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 = SharpDX.Direct3D.PrimitiveTopology.LineList;
                renderContext.SetIndexBuffer(shapeFileIndex);
                renderContext.devContext.DrawIndexed(shapeFileIndex.Count, 0, 0);
            }
            else
            {
                renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.PointList;
                renderContext.devContext.Draw(shapeVertexCount, 0);
            }

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

            return(true);
        }