コード例 #1
0
        //bool hitTestInit = false;

        //void InitHitTest(RenderContext renderContext)
        //{
        //    Vector2d center = new Vector2d();
        //    double radius = 0;
        //    Vector2d[] screenPoints = new Vector2d[points.Count];
        //    int index = 0;
        //    foreach (Vector3d pnt in points)
        //    {
        //        Vector3d screenSpacePnt = renderContext.ViewMatrix.Transform(pnt);
        //        if (screenSpacePnt.Z < 0)
        //        {
        //            return;
        //        }
        //        if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .55)
        //        {
        //            return;
        //        }
        //        screenPoints[index] = new Vector2d(screenSpacePnt.X, screenSpacePnt.Y);
        //        index++;
        //    }

        //    ConvexHull.FindEnclosingCircle(screenPoints, out center, out radius);
        //}

        public override void Draw(RenderContext renderContext)
        {
            if (renderContext.gl != null)
            {
                //todo draw in WebGL
            }
            else
            {
                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();
                ctx.Alpha = Opacity;

                ctx.BeginPath();

                bool first = true;
                foreach (Vector3d pnt in points)
                {
                    Vector3d screenSpacePnt = renderContext.WVP.Transform(pnt);
                    if (screenSpacePnt.Z < 0)
                    {
                        ctx.Restore();

                        return;
                    }

                    if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .75)
                    {
                        ctx.Restore();
                        return;
                    }

                    if (first)
                    {
                        first = false;
                        ctx.MoveTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                    else
                    {
                        ctx.LineTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                }
                ctx.ClosePath();

                ctx.LineWidth = strokeWidth;
                if (fill)
                {
                    ctx.FillStyle = fillColor.ToString();
                    ctx.Fill();
                }

                ctx.StrokeStyle = lineColor.ToString();
                ctx.Alpha       = 1;
                ctx.Stroke();

                ctx.Restore();
            }
        }
コード例 #2
0
ファイル: Overlay.cs プロジェクト: itguy327/wwt-web-client
        private void CreateCircleGeometry(RenderContext renderContext)
        {
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Scale(1, Width / Height);
            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);
            ctx.BeginPath();
            ctx.Arc(0, 0, Width, 0, Math.PI * 2, false);
            ctx.ClosePath();
            ctx.LineWidth = 0;
            ctx.FillStyle = Color.ToString();
            ctx.Alpha     = Opacity;
            ctx.Fill();
            ctx.Restore();
        }
コード例 #3
0
        public override void Draw(RenderContext renderContext)
        {
            double rad = radius;

            if (skyRelative)
            {
                rad /= renderContext.FovScale / 3600;
            }
            Vector3d screenSpacePnt = renderContext.WVP.Transform(center);

            if (screenSpacePnt.Z < 0)
            {
                return;
            }

            if (Vector3d.Dot((Vector3d)renderContext.ViewPoint, (Vector3d)center) < .55)
            {
                return;
            }
            if (renderContext.gl != null)
            {
                //todo draw in WebGL
            }
            else
            {
                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();
                ctx.Alpha = Opacity;
                ctx.BeginPath();
                ctx.Arc(screenSpacePnt.X, screenSpacePnt.Y, rad, 0, Math.PI * 2, true);
                ctx.LineWidth = strokeWidth;
                ctx.FillStyle = fillColor.ToString();
                if (fill)
                {
                    ctx.Fill();
                }
                ctx.Alpha       = 1.0;
                ctx.StrokeStyle = lineColor.ToString();
                ctx.Stroke();

                ctx.Restore();
            }
        }
コード例 #4
0
ファイル: Overlay.cs プロジェクト: itguy327/wwt-web-client
        private void CreateStarGeometry(RenderContext renderContext)
        {
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);
            ctx.BeginPath();

            double centerX = 0;
            double centerY = 0;
            double radius  = Width / 2;

            double radiansPerSegment = ((double)Math.PI * 2) / 5;

            bool first = true;

            for (int i = 0; i < 5; i++)
            {
                double rads = i * radiansPerSegment - (Math.PI / 2);
                if (first)
                {
                    first = false;
                    ctx.MoveTo(centerX + Math.Cos(rads) * (Width / 2), centerY + Math.Sin(rads) * (Height / 2));
                }
                else
                {
                    ctx.LineTo(centerX + Math.Cos(rads) * (Width / 2), centerY + Math.Sin(rads) * (Height / 2));
                }

                double rads2 = i * radiansPerSegment + (radiansPerSegment / 2) - (Math.PI / 2);
                ctx.LineTo(centerX + Math.Cos(rads2) * (Width / 5.3), centerY + Math.Sin(rads2) * (Height / 5.3));
            }

            ctx.ClosePath();
            ctx.LineWidth = 0;
            ctx.FillStyle = Color.ToString();


            ctx.Alpha = Opacity;
            ctx.Fill();
            ctx.Restore();
        }
コード例 #5
0
ファイル: Overlay.cs プロジェクト: itguy327/wwt-web-client
        private void CreateRectGeometry(RenderContext renderContext)
        {
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);

            ctx.BeginPath();
            ctx.MoveTo(-Width / 2, -Height / 2);
            ctx.LineTo(Width / 2, -Height / 2);
            ctx.LineTo(Width / 2, +Height / 2);
            ctx.LineTo(-Width / 2, +Height / 2);
            ctx.ClosePath();
            ctx.LineWidth = 0;
            ctx.FillStyle = Color.ToString();

            ctx.Alpha = Opacity;
            ctx.Fill();
            ctx.Restore();
        }
コード例 #6
0
        public void Draw(RenderContext renderContext, float opacity, bool cull)
        {
            InitBuffer(renderContext);



            if (renderContext.gl == null)
            {
                if (!imageReady)
                {
                    return;
                }
                renderContext.Device.Save();

                renderContext.WVP.ProjectArrayToScreen(worldList, transformedList);
                CanvasContext2D ctx = renderContext.Device;
                ctx.Alpha = .4;

                double width  = renderContext.Width;
                double height = renderContext.Height;

                Vector3d viewPoint = Vector3d.MakeCopy(renderContext.ViewPoint);

                double scaleFactor = renderContext.FovScale / 100;
                foreach (DataItem item in items)
                {
                    // todo filter by date

                    // if (Vector3d.Dot(viewPoint, item.Location) < 0)
                    if (item.Tranformed.Z < 1)
                    {
                        double x    = item.Tranformed.X;
                        double y    = item.Tranformed.Y;
                        double size = .1 * item.Size / scaleFactor;
                        double half = size / 2;
                        if (x > -half && x < width + half && y > -half && y < height + half)
                        {
                            //ctx.DrawImage(starProfile, x - size / 2, y - size / 2, size, size);

                            ctx.BeginPath();
                            // ctx.FillStyle = "rgb(200,0,0)";
                            ctx.FillStyle = item.Color.ToFormat();
                            ctx.Arc(x, y, size, 0, Math.PI * 2, true);
                            ctx.Fill();
                        }
                    }
                }

                renderContext.Device.Restore();
            }
            else
            {
                Vector3d zero   = new Vector3d();
                Matrix3d matInv = Matrix3d.MultiplyMatrix(renderContext.World, renderContext.View);
                matInv.Invert();
                Vector3d cam = Vector3d.TransformCoordinate(zero, matInv);

                foreach (TimeSeriesPointVertexBuffer pointBuffer in pointBuffers)
                {
                    TimeSeriesPointSpriteShader.Use(
                        renderContext, pointBuffer.VertexBuffer, starTexture.Texture2d,
                        Color.FromArgb(255 * opacity, 255, 255, 255), DepthBuffered, (float)(this.JNow),
                        this.TimeSeries ? (float)Decay : 0, cam, (float)(scale * (renderContext.Height / 960)), MinSize, ShowFarSide, Sky
                        );

                    renderContext.gl.drawArrays(GL.POINTS, 0, pointBuffer.Count);
                }

                // renderContext.gl.disable(0x8642);
            }
        }
コード例 #7
0
        //bool hitTestInit = false;

        //void InitHitTest(RenderContext renderContext)
        //{
        //    Vector2d center = new Vector2d();
        //    double radius = 0;
        //    Vector2d[] screenPoints = new Vector2d[points.Count];
        //    int index = 0;
        //    foreach (Vector3d pnt in points)
        //    {
        //        Vector3d screenSpacePnt = renderContext.ViewMatrix.Transform(pnt);
        //        if (screenSpacePnt.Z < 0)
        //        {
        //            return;
        //        }
        //        if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .55)
        //        {
        //            return;
        //        }
        //        screenPoints[index] = new Vector2d(screenSpacePnt.X, screenSpacePnt.Y);
        //        index++;
        //    }

        //    ConvexHull.FindEnclosingCircle(screenPoints, out center, out radius);
        //}

        public override void Draw(RenderContext renderContext)
        {
            if (renderContext.gl != null)
            {
                if (Annotation.BatchDirty || AnnotationDirty)
                {
                    //todo can we save this work for later?
                    List <Vector3d> vertexList = points;


                    if (strokeWidth > 0 && points.Count > 1)
                    {
                        for (int i = 0; i < (points.Count - 1); i++)
                        {
                            LineList.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates(0, 1));
                        }
                        LineList.AddLine(vertexList[points.Count - 1], vertexList[0], lineColor, new Dates(0, 1));
                    }
                    if (fill)
                    {
                        List <int> indexes = Tessellator.TesselateSimplePoly(vertexList);

                        for (int i = 0; i < indexes.Count; i += 3)
                        {
                            TriangleList.AddSubdividedTriangles(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], fillColor, new Dates(0, 1), 2);
                        }
                    }
                    AnnotationDirty = false;
                }
            }
            else
            {
                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();
                ctx.Alpha = Opacity;

                ctx.BeginPath();

                bool first = true;
                foreach (Vector3d pnt in points)
                {
                    Vector3d screenSpacePnt = renderContext.WVP.Transform(pnt);
                    if (screenSpacePnt.Z < 0)
                    {
                        ctx.Restore();

                        return;
                    }

                    if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .75)
                    {
                        ctx.Restore();
                        return;
                    }

                    if (first)
                    {
                        first = false;
                        ctx.MoveTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                    else
                    {
                        ctx.LineTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                }
                ctx.ClosePath();

                ctx.LineWidth = strokeWidth;
                if (fill)
                {
                    ctx.FillStyle = fillColor.ToString();
                    ctx.Fill();
                }

                ctx.StrokeStyle = lineColor.ToString();
                ctx.Alpha       = 1;
                ctx.Stroke();

                ctx.Restore();
            }
        }
コード例 #8
0
        public override void Draw(RenderContext renderContext)
        {
            bool   onScreen = true;
            double rad      = radius;

            if (skyRelative)
            {
                rad /= renderContext.FovScale / 3600;
            }
            Vector3d screenSpacePnt = renderContext.WVP.Transform(center);

            if (screenSpacePnt.Z < 0)
            {
                onScreen = false;
            }

            if (Vector3d.Dot((Vector3d)renderContext.ViewPoint, center) < .55)
            {
                onScreen = false;
            }

            if (renderContext.gl != null)
            {
                if (Annotation.BatchDirty || AnnotationDirty)
                {
                    Vector3d up = Vector3d.Create(0, 1, 0);

                    Vector3d xNormal = Vector3d.Cross(center, up);

                    Vector3d yNormal = Vector3d.Cross(center, xNormal);

                    double r = radius / 44;

                    int segments = 72;

                    double          radiansPerSegment = Math.PI * 2 / segments;
                    List <Vector3d> vertexList        = new List <Vector3d>();

                    for (int j = 0; j <= segments; j++)
                    {
                        double x = Math.Cos(j * radiansPerSegment) * r;
                        double y = Math.Sin(j * radiansPerSegment) * r;

                        vertexList.Add(Vector3d.Create(center.X + x * xNormal.X + y * yNormal.X, center.Y + x * xNormal.Y + y * yNormal.Y, center.Z + x * xNormal.Z + y * yNormal.Z));
                    }

                    if (strokeWidth > 0 && vertexList.Count > 1)
                    {
                        for (int i = 0; i < (vertexList.Count - 1); i++)
                        {
                            LineList.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates(0, 1));
                        }
                        LineList.AddLine(vertexList[vertexList.Count - 1], vertexList[0], lineColor, new Dates(0, 1));
                    }
                    if (fill)
                    {
                        List <int> indexes = Tessellator.TesselateSimplePoly(vertexList);

                        for (int i = 0; i < indexes.Count; i += 3)
                        {
                            TriangleList.AddSubdividedTriangles(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], fillColor, new Dates(0, 1), 2);
                        }
                    }
                    AnnotationDirty = false;
                }
            }
            else
            {
                if (onScreen)
                {
                    CanvasContext2D ctx = renderContext.Device;
                    ctx.Save();
                    ctx.Alpha = Opacity;
                    ctx.BeginPath();
                    ctx.Arc(screenSpacePnt.X, screenSpacePnt.Y, rad, 0, Math.PI * 2, true);
                    ctx.LineWidth = strokeWidth;
                    ctx.FillStyle = fillColor.ToString();
                    if (fill)
                    {
                        ctx.Fill();
                    }
                    ctx.Alpha       = 1.0;
                    ctx.StrokeStyle = lineColor.ToString();
                    ctx.Stroke();

                    ctx.Restore();
                }
            }
        }