コード例 #1
0
    void Start()
    {
        Road      ir            = new Road(45.0f, 0.5f);
        Query     iq            = new Query(new Vector2(0, 0), 0.0f);
        RoadQuery initial_query = new RoadQuery(0, 0, ir, iq, true);

        segments = new List <Segment>();

        q.Enqueue(initial_query, initial_query.timer);
        //!(q.Count == 0)

        int count = 0;

        while (count < 1000)
        {
            RoadQuery rq = q.Dequeue();

            if (!LocalConstraints(rq, segments))
            {
                continue;
            }

            segments.Add(CreateSegment(rq.road, rq.query));

            RoadQuery[] abc = GlobalGoals(rq.timer, rq.lifetime, rq.road, rq.query);

            q.Enqueue(abc[0], abc[0].timer);
            q.Enqueue(abc[1], abc[1].timer);
            q.Enqueue(abc[2], abc[2].timer);
            count++;
        }
    }
コード例 #2
0
    RoadQuery[] GlobalGoals(int t, int l, Road road, Query query)
    {
        double prev_angle = query.prev_angle + road.angle * Mathf.PI / 180.0;
        float  angle      = Random.Range(45.0f, -45.0f);
        float  p          = 1.0f;

        RoadQuery a = MakeRoad(road, (float)(angle - p * 90.0), t + 64, l + 3, 0.4f, (float)prev_angle, query);
        RoadQuery b = MakeRoad(road, angle, 1, l + 1, 0.5f, (float)prev_angle, query);
        RoadQuery c = MakeRoad(road, (float)(angle + p * 90.0), t + 64, l + 3, 0.4f, (float)prev_angle, query);

        return(new RoadQuery[3] {
            a, b, c
        });
    }
コード例 #3
0
    bool LocalConstraints(RoadQuery rq, List <Segment> segments)
    {
        Vector2 start = rq.query.origin;
        Vector2 end   = rq.road.end(rq.query);

        float exp = 6.0f;

        Segment current = new Segment(start, end);

        for (int i = 0; i < segments.Count; i++)
        {
            bool  intersects = current.Intersects(segments[i]);
            float err        = Mathf.Abs(current.start.x - segments[i].end.x) + Mathf.Abs(current.start.y - segments[i].end.y);
            bool  share      = err * err < 32.0f * Mathf.Epsilon;

            if (intersects && !share)
            {
                return(false);
            }
        }

        return(true);
    }