Beispiel #1
0
        private void DrawSelectionHandles(RenderContext11 renderContext, Overlay overlay, Texture11 handleTexture)
        {
            RectangleF[] handles = MakeHandles(overlay);
            float        angle   = overlay.RotationAngle;

            int i = 0;
            int j = 0;

            foreach (RectangleF 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, SharpDX.Direct3D.PrimitiveTopology.TriangleList);
            }
            else
            {
                Sprite2d.Draw(renderContext, points, points.Length, handleTexture, SharpDX.Direct3D.PrimitiveTopology.TriangleList);
            }
        }
Beispiel #2
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);
        }
        private void DrawFOV(RenderContext11 renderContext, float opacity, double ra, double dec)
        {
            Color color = Color.FromArgb((int)(opacity * 255f), Properties.Settings.Default.FovColor);

            foreach (Imager chip in Camera.Chips)
            {
                double halfWidth  = (Math.Atan(chip.Width / (2 * Telescope.FocalLength))) / RC;
                double halfHeight = (Math.Atan(chip.Height / (2 * Telescope.FocalLength))) / RC;

                double centerOffsetY = 2 * (Math.Atan(chip.CenterY / (2 * Telescope.FocalLength))) / RC;
                double centerOffsetX = 2 * (Math.Atan(chip.CenterX / (2 * Telescope.FocalLength))) / RC;

                SharpDX.Matrix mat = SharpDX.Matrix.RotationX((float)(((chip.Rotation + angle)) / 180f * Math.PI));
                mat = SharpDX.Matrix.Multiply(mat, SharpDX.Matrix.RotationZ((float)((dec) / 180f * Math.PI)));
                mat = SharpDX.Matrix.Multiply(mat, SharpDX.Matrix.RotationY((float)(((24 - (ra + 12))) / 12f * Math.PI)));

                int count = 4;

                points = new PositionColoredTextured[count + 1];
                int index = 0;

                points[index].Position = RaDecTo3d(-halfWidth + centerOffsetX, -halfHeight + centerOffsetY).Vector4;
                points[index].Color    = color;

                index++;
                points[index].Position = RaDecTo3d(halfWidth + centerOffsetX, -halfHeight + centerOffsetY).Vector4;
                points[index].Color    = color;

                index++;
                points[index].Position = RaDecTo3d(halfWidth + centerOffsetX, halfHeight + centerOffsetY).Vector4;
                points[index].Color    = color;

                index++;
                points[index].Position = RaDecTo3d(-halfWidth + centerOffsetX, halfHeight + centerOffsetY).Vector4;
                points[index].Color    = color;

                index++;
                points[index].Position = RaDecTo3d(-halfWidth + centerOffsetX, -halfHeight + centerOffsetY).Vector4;
                points[index].Color    = color;


                for (int i = 0; i < points.Length; i++)
                {
                    points[i].Pos3 = SharpDX.Vector3.TransformCoordinate(points[i].Pos3, mat);
                }

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

                Sprite2d.DrawLines(renderContext, points, 5, matV, true);
            }
        }
        public void Render(Earth3d window)
        {
            //todo11 reanble this
            if (texture == null)
            {
                Bitmap bmp = null;
                bmp = GetChartImageBitmap(window);
                bmp.Dispose();
            }


            Sprite2d.Draw2D(window.RenderContext11, texture, new SizeF(texture.Width, texture.Height), new PointF(0, 0), 0, new PointF(Left + texture.Width / 2, Top + texture.Height / 2), Color.White);


            if (!String.IsNullOrEmpty(HoverText))
            {
                Rectangle recttext = new Rectangle((int)(hoverPoint.X + 15), (int)(hoverPoint.Y - 8), 0, 0);
            }


            return;
        }
Beispiel #5
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);
                }
            }
        }
Beispiel #6
0
        public void DrawPlaceMarks()
        {
            // todo11 port this Maybe instancing later?
            Matrix   projection = Earth3d.MainWindow.RenderContext11.Projection.Matrix11;
            Matrix   view       = Earth3d.MainWindow.RenderContext11.View.Matrix11;
            Matrix   world      = Earth3d.MainWindow.RenderContext11.World.Matrix11;
            Matrix3d worldD     = Earth3d.MainWindow.RenderContext11.World;
            Matrix   wvp        = (world * view * projection);

            try
            {
                Vector3 center = new Vector3(0f, 0f, 0);

                foreach (KmlPlacemark placemark in Placemarks)
                {
                    if (placemark.ShouldDisplay())
                    {
                        SharpDX.Direct3D11.Viewport vp = Earth3d.MainWindow.RenderContext11.ViewPort;
                        double   alt     = placemark.Point.altitude + EGM96Geoid.Height(placemark.Point.latitude, placemark.Point.longitude);
                        Vector3d point3d = Coordinates.GeoTo3dDouble(placemark.Point.latitude, placemark.Point.longitude, 1 + (alt / Earth3d.MainWindow.RenderContext11.NominalRadius));
                        Vector3  point   = Vector3.Project(point3d.Vector311, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0, 1, wvp);
                        // point.Z = 1;
                        KmlStyle  style   = placemark.Style.GetStyle(placemark.Selected);
                        Texture11 texture = style.IconStyle.Icon.Texture;

                        if (String.IsNullOrEmpty(style.IconStyle.Icon.Href))
                        {
                            texture = Star;
                        }

                        double sizeFactor = 1;

                        if (placemark.Selected)
                        {
                            double ticks          = HiResTimer.TickCount;
                            double elapsedSeconds = ((double)(ticks - TicksAtLastSelect)) / HiResTimer.Frequency;
                            sizeFactor = 1 + .3 * (Math.Sin(elapsedSeconds * 15) * Math.Max(0, (1 - elapsedSeconds)));
                        }

                        point3d.TransformCoordinate(worldD);
                        Vector3d dist     = Earth3d.MainWindow.RenderContext11.CameraPosition - point3d;
                        double   distance = dist.Length() * Earth3d.MainWindow.RenderContext11.NominalRadius;
                        dist.Normalize();
                        double dot = Vector3d.Dot(point3d, dist);
                        // if (dot > -.2)
                        {
                            double baseSize = Math.Min(40, 25 * ((2 * Math.Atan(.5 * (5884764 / distance))) / .7853)) * sizeFactor;
                            float  size     = (float)baseSize * style.IconStyle.Scale;
                            //todo fix this with real centers and offset by KML data
                            placemark.hitTestRect = new Rectangle((int)(point.X - (size / 2)), (int)(point.Y - (size / 2)), (int)(size + .5), (int)(size + .5));
                            if (texture != null)
                            {
                                center = new Vector3((float)texture.Width / 2f, (float)texture.Height / 2f, 0);

                                Sprite2d.Draw2D(Earth3d.MainWindow.RenderContext11, texture, new SizeF(size, size), new PointF(center.X, center.Y), (float)(style.IconStyle.Heading * Math.PI / 180f), new PointF(point.X, point.Y), Color.White);
                            }

                            if (style.LabelStyle.Color.A > 0 && style.LabelStyle.Scale > 0)
                            {
                                Rectangle recttext = new Rectangle((int)(point.X + (size / 2) + 10), (int)(point.Y - (size / 2)), 1000, 100);
                                //todo11 Earth3d.MainWindow.labelFont.DrawText(null, placemark.Name, recttext, DrawTextFormat.NoClip, style.LabelStyle.Color);
                            }
                        }
                    }
                }
            }
            finally
            {
            }
        }
Beispiel #7
0
        public void Draw(RenderContext11 renderContext, bool space3d)
        {
            Vector3d cam = Vector3d.TransformCoordinate(Earth3d.MainWindow.RenderContext11.CameraPosition, Matrix3d.Invert(Earth3d.WorldMatrix));

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

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

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

            Vector3 screenPos = Vector3.Project(temp.Vector311, renderContext.ViewPort.X, renderContext.ViewPort.Y, 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.
            double 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((float)(int)screenPos.X, (float)(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)
            {
                Matrix3d worldMatrix      = renderContext.World;
                Matrix3d viewMatrix       = renderContext.View;
                Matrix3d projectionMatrix = renderContext.Projection;

                double 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();
        }