Exemplo n.º 1
0
    private Vector3 CoordinateForRoadWithAbstractRoadInfos(Intersection intersection, Road connectedRoad, RightOrLeft rtlt,
                                                           AbstractWayInfo[] infos)
    {
        infos = AbstractWayInfo.sortAbstractWayInfos(infos);

        // convert the road to an abstract way info
        AbstractWayInfo info = new AbstractWayInfo(IntersectionMath.getOutgoingVector(intersection, connectedRoad).normalized,
                                                   connectedRoad.GetRoadWidth());
        // TODO : CHECK FOR nonexistent index
        int index = 0;

        for (int i = 0; i < infos.Length; i++)
        {
            if (infos[i] == info)
            {
                index = i;
            }
        }

        Vector3[] vertices = MeshVerticesForAbstractWayInfos(infos);

        switch (rtlt)
        {
        case RightOrLeft.LEFT:
            return(vertices[index - 1 < 0 ? infos.Length - 1 : index - 1]);

        case RightOrLeft.RIGHT:
            return(vertices[index]);
        }
        Debug.LogError("Semantics Error, please check");

        return(Vector3.zero);
    }
Exemplo n.º 2
0
 private Vector3 CoordinateForMultiwayIntersection(Intersection intersection, Road connectedRoad, RightOrLeft rtlt)
 {
     AbstractWayInfo[] infos = AbstractWayInfosForMultiwayIntersection(intersection, intersection.getConnectedRoads());
     return(CoordinateForRoadWithAbstractRoadInfos(intersection, connectedRoad, rtlt, infos));
 }
Exemplo n.º 3
0
    private Vector3 CoordinateForOneWayIntersection(Intersection intersection, Road connectedRoad, RightOrLeft rtlt)
    {
        Vector3 outVec   = getOutgoingVectorForOneWayIntersection(intersection, connectedRoad);
        Vector3 rightVec = Quaternion.Euler(0, 90, 0) * outVec;
        Vector3 leftVec  = Quaternion.Euler(0, -90, 0) * outVec;

        switch (rtlt)
        {
        case RightOrLeft.LEFT:
            return(leftVec);

        case RightOrLeft.RIGHT:
            return(rightVec);
        }

        Debug.LogError("Semantics Error, please check");
        return(Vector3.zero);
    }
Exemplo n.º 4
0
    private Vector3 CoordinateForTwoWayIntersection(Intersection intersection, Road connectedRoad, RightOrLeft rtlt)
    {
        switch (GetTwoWayIntersectionType(intersection))
        {
        case TwoWayIntersectionType.SKEW:
        case TwoWayIntersectionType.TRANSITION:
            AbstractWayInfo[] infos = AbstractWayInfosForTwoWayIntersection(intersection, intersection.getConnectedRoads()[0],
                                                                            intersection.getConnectedRoads()[1]);
            return(CoordinateForRoadWithAbstractRoadInfos(intersection, connectedRoad, rtlt, infos));

        case TwoWayIntersectionType.SMOOTH:
            // basically it is the same as one way

            return(CoordinateForOneWayIntersection(intersection, connectedRoad, rtlt));
        }

        Debug.LogError("Semantics Error, please check");
        return(Vector3.zero);
    }
Exemplo n.º 5
0
    /**
     * @brief Returns the coordinate for the left edge and right edge of the road.
     *
     *
     * The behavior is undefined when road is not attached to the intersection.
     *
     *
     * Right or left is regarding the direction going out from intersection
     *
     *
     * @param intersection the subject intersection
     * @param road which road to test
     * @param rtlt: Right : the point on the right of the outgoing vector <br>
     *              Left : the point on the left of the outgoing vector <br>
     *              Note: This direction is the reverse of what traditionally known as left or right
     *
     */
    public Vector3 coordinateForRoadAtIntersection(Intersection intersection, Road road, RightOrLeft rtlt)
    {
        Road[] roads = intersection.getConnectedRoads();
        Debug.Assert(roads.Contains(road));
        // no intersection if no roads
        switch (GetIntersectionType(intersection))
        {
        case IntersectionType.NONE:
            return(Vector3.zero);

        case IntersectionType.ONE_WAY:
            return(CoordinateForOneWayIntersection(intersection, road, rtlt));

        case IntersectionType.TWO_WAY:
            return(CoordinateForTwoWayIntersection(intersection, road, rtlt));

        case IntersectionType.MULTI_WAY:
            return(CoordinateForMultiwayIntersection(intersection, road, rtlt));
        }
        Debug.LogError("Semantics Error, please check");

        return(Vector3.zero);
    }