コード例 #1
0
        private void AddPolygon(bool sky, KmlLineList geo, float lineWidth, Color polyColor, Color lineColor, bool extrude, bool fill, Dates date)
        {
            //todo can we save this work for later?
            List <Vector3d> vertexList       = new List <Vector3d>();
            List <Vector3d> vertexListGround = new List <Vector3d>();

            //todo list
            // We need to Wrap Around for complete polygone
            // we aldo need to do intereor
            //todo space? using RA/DEC
            for (int i = 0; i < (geo.PointList.Count); i++)
            {
                vertexList.Add(Coordinates.GeoTo3dDoubleRad(geo.PointList[i].Lat, geo.PointList[i].Lng, 1 + (geo.PointList[i].Alt / meanRadius)));
                vertexListGround.Add(Coordinates.GeoTo3dDoubleRad(geo.PointList[i].Lat, geo.PointList[i].Lng, 1));
            }


            for (int i = 0; i < (geo.PointList.Count - 1); i++)
            {
                if (sky)
                {
                    //tdo reenable this
                    //this.lineList2d.AddLine
                    //    (Coordinates.RADecTo3d(-(180.0 - geo.PointList[i].Lng) / 15 + 12, geo.PointList[i].Lat, 1), Coordinates.RADecTo3d(-(180.0 - geo.PointList[i + 1].Lng) / 15 + 12, geo.PointList[i + 1].Lat, 1), lineColor, date);
                }
                else
                {
                    if (extrude)
                    {
                        this.triangleList.AddQuad(vertexList[i], vertexList[i + 1], vertexListGround[i], vertexListGround[i + 1], polyColor, date);
                    }
                    if (lineWidth > 0)
                    {
                        if (extrude)
                        {
                            this.lineList.AddLine(vertexList[i], vertexList[i + 1], lineColor, date);
                        }
                        else
                        {
                            this.lineList2d.AddLine(vertexList[i], vertexList[i + 1], lineColor, date);
                        }
                        if (extrude)
                        {
                            this.lineList.AddLine(vertexListGround[i], vertexListGround[i + 1], lineColor, date);
                            this.lineList.AddLine(vertexList[i], vertexListGround[i], lineColor, date);
                            this.lineList.AddLine(vertexList[i + 1], vertexListGround[i + 1], lineColor, date);
                        }
                    }
                }
            }
            if (fill)
            {
                List <int> indexes = Tessellator.TesselateSimplePoly(vertexList);

                for (int i = 0; i < indexes.Count; i += 3)
                {
                    this.triangleList.AddTriangle(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], polyColor, date);
                }
            }
        }
コード例 #2
0
        public static List<int> TesselateSimplePoly(List<Vector3d> inputList)
        {
            List<int> results = new List<int>();

            Tessellator tess = new Tessellator();

            tess.Process(inputList, results);

            return results;
        }
コード例 #3
0
        public static List <int> TesselateSimplePoly(List <Vector3d> inputList)
        {
            List <int> results = new List <int>();

            Tessellator tess = new Tessellator();

            tess.Process(inputList, results);

            return(results);
        }
コード例 #4
0
        private void AddPolygonFlat(bool sky, KmlLineList geo, float lineWidth, Color polyColor, Color lineColor, bool extrude, bool fill, Dates date)
        {
            //todo can we save this work for later?
            List <Vector3d> vertexList = new List <Vector3d>();

            for (int i = 0; i < (geo.PointList.Count); i++)
            {
                vertexList.Add(Coordinates.GeoTo3dDoubleRad(geo.PointList[i].Lat, geo.PointList[i].Lng, 1 + (geo.PointList[i].Alt / meanRadius)));
            }


            for (int i = 0; i < (geo.PointList.Count - 1); i++)
            {
                if (sky)
                {
                    //this.lineList2d.AddLine
                    //    (Coordinates.RADecTo3d(-(180.0 - geo.PointList[i].Lng) / 15 + 12, geo.PointList[i].Lat, 1), Coordinates.RADecTo3d(-(180.0 - geo.PointList[i + 1].Lng) / 15 + 12, geo.PointList[i + 1].Lat, 1), lineColor, date);
                }
                else
                {
                    if (lineWidth > 0)
                    {
                        this.lineList2d.AddLine(vertexList[i], vertexList[i + 1], lineColor, date);
                    }
                }
            }
            if (fill)
            {
                List <int> indexes = Tessellator.TesselateSimplePoly(vertexList);

                for (int i = 0; i < indexes.Count; i += 3)
                {
                    this.triangleList2d.AddSubdividedTriangles(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], polyColor, date, 2);
                }
            }
        }
コード例 #5
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();
            }
        }
コード例 #6
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();
                }
            }
        }