Beispiel #1
0
        public void Draw(RenderContext context)
        {
            if (context.layerPass != RenderContext.LayerPass.UI_PASS)
            {
                return;
            }
            if (debugLinesBuffer == null)
            {
                BlobCollection blobs = OSMReader.GetAllBlobs(sector);
                debugLinesBuffer = OSMLineBufferGenerator.GenerateDebugLines(context.graphicsDevice, blobs);
            }
            // draw those lines
            Effect effect = GlobalContent.DebugLinesShader;

            effect.Parameters["Texture"].SetValue(debugLinesBuffer.texture);
            effect.Parameters["WVP"].SetValue(context.WVP.toMatrix());
            effect.Parameters["LineWidth"].SetValue((float)Math.Pow(0.5, context.cameraZoom) * 50);
            context.graphicsDevice.Indices = debugLinesBuffer.indices;
            context.graphicsDevice.SetVertexBuffer(debugLinesBuffer.vertices);
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                context.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, debugLinesBuffer.indices.IndexCount / 3);
            }
            // TODO: need to call this once for all debug buffers somehow
            string  text = $"Nothing Selected";
            Vector2 size = GlobalContent.Arial.MeasureString(text);

            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, DepthStencilState.Default, null, null, null);
            spriteBatch.DrawString(GlobalContent.Arial, text, new Vector2(context.graphicsDevice.Viewport.Width - 5 - size.X, 5), Color.White);
            spriteBatch.End();
        }
Beispiel #2
0
 static void Main(string[] args)
 {
     try
     {
         XmlReader city = XmlReader.Create("C:\\Users\\User\\source\\repos\\practice\\practice\\urk_town.osm");
         OSMReader read = new OSMReader();
         read.read(city);
     }
     catch
     {
         Console.WriteLine("Помилка");
         Console.ReadLine();
     }
 }
Beispiel #3
0
        public void LoadLinesFromFile()
        {
            BlobCollection blobs = OSMReader.GetAllBlobs(sector);

            BlobsIntersector.DoIntersections(blobs);

            var allDescriptors = new List <IDescriptor>();

            allDescriptors.AddRange(descriptors);
            allDescriptors.AddRange(treeDescriptors);
            allDescriptors.AddRange(grassDescriptors);
            foreach (var descriptor in allDescriptors)
            {
                descriptor.Load(blobs);
                descriptor.Init(blobs);
            }
        }
    public void BuildMap()
    {
        ClearMap();
        if (reader == null)
        {
            reader = GetComponent <OSMReader>();
        }
        if (data == null)
        {
            data = reader.GetOSMData();
        }
        foreach (Way way in data.ways)
        {
            GameObject go;
            Vector3[]  points = new Vector3[way.nodes.Count];
            for (int i = 0; i < way.nodes.Count; i++)
            {
                points[i] = data.nodes[way.nodes[i]].GetPosition();
            }
            switch (way.type)
            {
            case WayType.line_thin:
                go = Instantiate(line_thin, linethinParent);
                go.GetComponent <Line_thin>().UpdateLineRenderer(points);
                go.GetComponent <Line_thin>().SetElementID(way.id);
                MapDictionary.Add(way.id, go.GetComponent <MapElement>());
                break;

            case WayType.stop_line:
                go = Instantiate(stop_line, stoplineParent);
                go.GetComponent <Stop_line>().UpdateLineRenderer(points);
                go.GetComponent <Stop_line>().SetElementID(way.id);
                MapDictionary.Add(way.id, go.GetComponent <MapElement>());
                break;

            case WayType.traffic_light:
                Vector3 trafficPos = (points[0] + points[1]) / 2;
                go = Instantiate(traffic_light, trafficlightParent);
                go.transform.position = trafficPos;
                go.GetComponent <Traffic_light>().SetElementID(way.id);
                MapDictionary.Add(way.id, go.GetComponent <MapElement>());
                break;

            case WayType.traffic_sign:
                go = Instantiate(traffic_sign, trafficsignParent);
                go.GetComponent <Traffic_sign>().UpdateLineRenderer(points);
                go.GetComponent <Traffic_sign>().SetElementID(way.id);
                MapDictionary.Add(way.id, go.GetComponent <MapElement>());
                break;

            default:
                break;
            }
        }

        foreach (Relation relation in data.relations)
        {
            if (relation.subType == RelationSubType.traffic_light)
            {
                Vector3       targetPos = new Vector3();
                Traffic_light light     = new Traffic_light();
                foreach (Member member in relation.menbers)
                {
                    if (MapDictionary.TryGetValue(member.refID, out MapElement element))
                    {
                        if (member.roleType == RoleType.ref_line)
                        {
                            Line line = element.GetComponent <Line>();
                            targetPos  = line.lineRenderer.GetPosition(0) + line.lineRenderer.GetPosition(1);
                            targetPos *= 0.5f;
                        }
                        else if (member.roleType == RoleType.refers)
                        {
                            light = element.GetComponent <Traffic_light>();
                        }
                    }
                }
                targetPos.y = light.transform.position.y;
                light.transform.LookAt(targetPos);
            }
        }
    }