public static double UnpackEpoch(string packed)
        {
            int year = GetMappedDatePart(packed[0]) * 100 + Convert.ToInt32(packed.Substring(1, 2));

            DateTime date = new DateTime(year, GetMappedDatePart(packed[3]), GetMappedDatePart(packed[4]));

            return(SpaceTimeController.UtcToJulian(date));
        }
Example #2
0
        public void Render(Earth3d window)
        {
            window.SetupMatricesOverlays();
            window.RenderContext11.DepthStencilMode = DepthStencilMode.Off;


            if (tour == null || tour.CurrentTourStop == null)
            {
                return;
            }

            if (ProjectorServer)
            {
                overlayBlend.State = true;
            }

            if (!onTarget && !ProjectorServer)
            {
                slideStartTime = SpaceTimeController.MetaNow;
                if (Earth3d.MainWindow.OnTarget(Tour.CurrentTourStop.Target))
                {
                    onTarget                 = true;
                    overlayBlend.State       = !Tour.CurrentTourStop.FadeInOverlays;
                    overlayBlend.TargetState = true;

                    if (!PreRoll)
                    {
                        if (tour.CurrentTourStop.MusicTrack != null)
                        {
                            tour.CurrentTourStop.MusicTrack.Play();
                        }

                        if (tour.CurrentTourStop.VoiceTrack != null)
                        {
                            tour.CurrentTourStop.VoiceTrack.Play();
                        }

                        foreach (Overlay overlay in tour.CurrentTourStop.Overlays)
                        {
                            overlay.Play();
                        }
                    }

                    LayerManager.SetVisibleLayerList(tour.CurrentTourStop.Layers);


                    if (tour.CurrentTourStop.KeyFramed)
                    {
                        tour.CurrentTourStop.KeyFrameMover.CurrentDateTime = tour.CurrentTourStop.StartTime;
                        tour.CurrentTourStop.KeyFrameMover.CurrentPosition = tour.CurrentTourStop.Target.CamParams;
                        tour.CurrentTourStop.KeyFrameMover.MoveTime        = (double)(tour.CurrentTourStop.Duration.TotalMilliseconds / 1000.0);
                        Earth3d.MainWindow.Mover = tour.CurrentTourStop.KeyFrameMover;
                    }
                    else if (tour.CurrentTourStop.EndTarget != null && tour.CurrentTourStop.EndTarget.ZoomLevel != -1)
                    {
                        if (tour.CurrentTourStop.Target.Type == ImageSetType.SolarSystem)
                        {
                            tour.CurrentTourStop.Target.UpdatePlanetLocation(SpaceTimeController.UtcToJulian(tour.CurrentTourStop.StartTime));
                            tour.CurrentTourStop.EndTarget.UpdatePlanetLocation(SpaceTimeController.UtcToJulian(tour.CurrentTourStop.EndTime));
                        }


                        Earth3d.MainWindow.Mover = new ViewMoverKenBurnsStyle(tour.CurrentTourStop.Target.CamParams, tour.CurrentTourStop.EndTarget.CamParams, tour.CurrentTourStop.Duration.TotalMilliseconds / 1000.0, tour.CurrentTourStop.StartTime, tour.CurrentTourStop.EndTime, tour.CurrentTourStop.InterpolationType);
                    }

                    Settings.TourSettings           = tour.CurrentTourStop;
                    SpaceTimeController.Now         = tour.CurrentTourStop.StartTime;
                    SpaceTimeController.SyncToClock = false;
                }
            }

            if (currentMasterSlide != null)
            {
                foreach (Overlay overlay in currentMasterSlide.Overlays)
                {
                    overlay.TweenFactor = 1f;

                    overlay.Draw3D(window.RenderContext11, 1.0f, false);
                }
            }



            if (onTarget || ProjectorServer)
            {
                foreach (Overlay overlay in tour.CurrentTourStop.Overlays)
                {
                    if (!Tour.CurrentTourStop.KeyFramed || (overlay.Animate && overlay.AnimationTarget == null))
                    {
                        overlay.TweenFactor = (float)CameraParameters.EaseCurve(tour.CurrentTourStop.TweenPosition, overlay.InterpolationType == InterpolationType.Default ? tour.CurrentTourStop.InterpolationType : overlay.InterpolationType);
                    }
                    overlay.Draw3D(window.RenderContext11, overlayBlend.Opacity, false);
                }
            }
        }
        protected override bool PrepVertexBuffer(float opacity)
        {
            VoColumn col = table.GetColumnByUcd("meta.id");

            if (col == null)
            {
                col = table.Column[0];
            }

            if (shapeFileVertex == null)
            {
                bool siapSet = IsSiapResultSet();

                if (lineList2d == null)
                {
                    lineList2d = new LineList();
                }
                lineList2d.Clear();

                VoColumn stcsCol = table.GetColumnByUcd("phys.area;obs.field");

                if (stcsCol == null && table.Columns.ContainsKey("regionSTCS"))
                {
                    stcsCol = table.Columns["regionSTCS"];
                }

                if (PlotType == PlotTypes.Gaussian)
                {
                    MarkerScale = MarkerScales.World;
                }
                else
                {
                    MarkerScale = MarkerScales.Screen;
                }

                List <TimeSeriesPointVertex> vertList = new List <TimeSeriesPointVertex>();
                List <UInt32>         indexList       = new List <UInt32>();
                TimeSeriesPointVertex lastItem        = new TimeSeriesPointVertex();
                positions.Clear();
                UInt32 currentIndex = 0;
                Color  color        = Color.FromArgb((int)(opacity * (float)Color.A), Color);

                pointScaleType = PointScaleTypes.StellarMagnitude;

                foreach (VoRow row in table.Rows)
                {
                    try
                    {
                        if (lngColumn > -1 && latColumn > -1)
                        {
                            double Xcoord = Coordinates.ParseRA(row[this.LngColumn].ToString(), true) * 15 + 180;
                            double Ycoord = Coordinates.ParseDec(row[this.LatColumn].ToString());
                            lastItem.Position = Coordinates.GeoTo3dDouble(Ycoord, Xcoord).Vector311;
                            positions.Add(lastItem.Position);
                            lastItem.Color = color;
                            if (sizeColumn > -1)
                            {
                                try
                                {
                                    if (MarkerScale == MarkerScales.Screen)
                                    {
                                        lastItem.PointSize = 20f;
                                    }
                                    else
                                    {
                                        switch (pointScaleType)
                                        {
                                        case PointScaleTypes.Linear:
                                            lastItem.PointSize = Convert.ToSingle(row[sizeColumn]);
                                            break;

                                        case PointScaleTypes.Log:
                                            lastItem.PointSize = (float)Math.Log(Convert.ToSingle(row[sizeColumn]));
                                            break;

                                        case PointScaleTypes.Power:
                                            lastItem.PointSize = (float)Math.Pow(2, Convert.ToSingle(row[sizeColumn]));
                                            break;

                                        case PointScaleTypes.StellarMagnitude:
                                        {
                                            double size = Convert.ToSingle(row[sizeColumn]);
                                            lastItem.PointSize = (float)(40 / Math.Pow(1.6, size)) * 10;
                                        }
                                        break;

                                        case PointScaleTypes.Constant:
                                            lastItem.PointSize = 1;
                                            break;

                                        default:
                                            break;
                                        }
                                    }
                                }
                                catch
                                {
                                    lastItem.PointSize = .01f;
                                }
                            }
                            else
                            {
                                if (MarkerScale == MarkerScales.Screen)
                                {
                                    lastItem.PointSize = 20;
                                }
                                else
                                {
                                    lastItem.PointSize = (float)Math.Pow(2, 1) * 100;
                                }
                            }


                            if (startDateColumn > -1)
                            {
                                DateTime dateTime = DateTime.Parse(row[startDateColumn].ToString());
                                lastItem.Tu = (float)SpaceTimeController.UtcToJulian(dateTime);
                                lastItem.Tv = 0;
                            }


                            vertList.Add(lastItem);
                            currentIndex++;
                        }


                        if (siapSet && stcsCol != null)
                        {
                            AddSiapStcRow(stcsCol.Name, row, row == table.SelectedRow);
                        }
                    }

                    catch
                    {
                    }
                    lines = false;
                }

                if (siapSet && stcsCol != null)
                {
                    AddSiapStcRow(stcsCol.Name, table.SelectedRow, true);
                }


                shapeVertexCount = vertList.Count;
                if (shapeVertexCount == 0)
                {
                    shapeVertexCount = 1;
                }
                shapeFileVertex = new TimeSeriesPointSpriteSet(RenderContext11.PrepDevice, vertList.ToArray());
            }
            return(true);
        }
        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;
            }
        }
        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);
            }
        }
Example #6
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);
        }