Ejemplo n.º 1
0
        /// <summary>
        /// Update all of the end points of the cross roads
        /// </summary>
        /// <param name="order">The orderd list of roads</param>
        /// <param name="mbs">The created mesg builder</param>
        /// <param name="leftIntersectionInner">The inner left cross section</param>
        /// <param name="leftIntersectionOutter">The outter left cross section</param>
        /// <param name="rightIntersectionInner">The inner right cross section</param>
        /// <param name="rightIntersectionOutter">The outter right cross section</param>
        /// <param name="middleIntersectionInner">The middle road cross sections</param>
        /// <param name="oppositeIntersectionInner">The opposite road cross sections</param>
        private void UpdateRoadNodesEndPoints(out RoadCrossRoadOrder order, out MeshBuilderSection mbs, out RoadCrossSection leftIntersectionInner, out RoadCrossSection leftIntersectionOutter, out RoadCrossSection rightIntersectionInner, out RoadCrossSection rightIntersectionOutter, out RoadCrossSection middleIntersectionInner, out RoadCrossSection oppositeIntersectionInner)
        {
            RoadNetworkNode roadA = _roadNetworkNode.Details.Roads[0];
            RoadNetworkNode roadB = _roadNetworkNode.Details.Roads[1];
            RoadNetworkNode roadC = _roadNetworkNode.Details.Roads[2];
            RoadNetworkNode roadD = _roadNetworkNode.Details.Roads[3];

            order = new RoadCrossRoadOrder(
                _list[0], roadA,
                _list[1], roadB,
                _list[2], roadC,
                _list[3], roadD);
            mbs = new MeshBuilderSection(_roadObject, null, _materialName, 0);

            // left road
            Vector3 posA;
            Vector3 posA2;
            Vector3 posB;

            FindOverlapPoint(order.MiddleRoad.Angle, order.LeftRoad.Angle, order.MiddleRoad.CurbLeftEnd, order.LeftRoad.CurbRightEnd, out posA);
            FindOverlapPoint(order.MiddleRoad.Angle, order.LeftRoad.Angle, order.MiddleRoad.Left, order.LeftRoad.CurbRightEnd, out posA2);
            FindOverlapPoint(order.OppositeRoad.Angle, order.LeftRoad.Angle, order.OppositeRoad.CurbRightEnd, order.LeftRoad.CurbLeftEnd, out posB);

            Vector3 curbToCurb   = posA - posB;
            float   newRoadAngle = -MathsHelper.GetAngleFrom(curbToCurb.z, curbToCurb.x) + (Mathf.PI / 2);

            leftIntersectionInner  = order.LeftRoad.GetIntersection(newRoadAngle, posA);
            leftIntersectionOutter = order.LeftRoad.GetIntersection(newRoadAngle, posA2);
            FindOverlapPoint(order.MiddleRoad.Angle, order.RightRoad.Angle, order.MiddleRoad.CurbRightEnd, order.RightRoad.CurbLeftEnd, out posA);
            FindOverlapPoint(order.MiddleRoad.Angle, order.RightRoad.Angle, order.MiddleRoad.Right, order.RightRoad.CurbLeftEnd, out posA2);
            FindOverlapPoint(order.OppositeRoad.Angle, order.RightRoad.Angle, order.OppositeRoad.CurbLeftEnd, order.RightRoad.CurbRightEnd, out posB);
            curbToCurb = posB - posA;

            newRoadAngle            = -MathsHelper.GetAngleFrom(curbToCurb.z, curbToCurb.x) + (Mathf.PI / 2);
            rightIntersectionInner  = order.RightRoad.GetIntersection(newRoadAngle, posA);
            rightIntersectionOutter = order.RightRoad.GetIntersection(newRoadAngle, posA2);
            curbToCurb              = rightIntersectionInner.CurbLeftEnd - leftIntersectionInner.CurbRightEnd;
            newRoadAngle            = -MathsHelper.GetAngleFrom(curbToCurb.z, curbToCurb.x) + (Mathf.PI / 2);
            middleIntersectionInner = order.MiddleRoad.GetIntersection(newRoadAngle, rightIntersectionInner.CurbLeftEnd);
            curbToCurb              = rightIntersectionInner.CurbRightEnd - leftIntersectionInner.CurbLeftEnd;
            newRoadAngle            = -MathsHelper.GetAngleFrom(curbToCurb.z, curbToCurb.x) - (Mathf.PI / 2);

            oppositeIntersectionInner = order.OppositeRoad.GetIntersection(newRoadAngle, rightIntersectionInner.CurbRightEnd);

            // Store the ids so we know where to update them later
            Guid leftRoadNodeId     = order.LeftRoad.ID;
            Guid rightRoadNodeId    = order.RightRoad.ID;
            Guid middleRoadNodeId   = order.MiddleRoad.ID;
            Guid oppositeRoadNodeId = order.OppositeRoad.ID;

            order.ReSetLeft(FindSmallestRoadForJunction(order.LeftRoadNode, leftIntersectionInner, order.LeftRoad.Middle));
            order.ReSetRight(FindSmallestRoadForJunction(order.RightRoadNode, rightIntersectionInner, order.RightRoad.Middle));
            order.ReSetMiddle(FindSmallestRoadForJunction(order.MiddleRoadNode, middleIntersectionInner, order.MiddleRoad.Middle));
            order.ReSetOpposite(FindSmallestRoadForJunction(order.OppositeRoadNode, oppositeIntersectionInner, order.OppositeRoad.Middle));

            IntersectionManager.Instance.SetIntersection(leftRoadNodeId, order.LeftRoad);
            IntersectionManager.Instance.SetIntersection(middleRoadNodeId, order.MiddleRoad);
            IntersectionManager.Instance.SetIntersection(rightRoadNodeId, order.RightRoad);
            IntersectionManager.Instance.SetIntersection(oppositeRoadNodeId, order.OppositeRoad);
        }
 /// <summary>
 /// Update the end points
 /// </summary>
 /// <param name="roadBuilderObject">The base object</param>
 public void UpdateEndPoints(IRoadBuildData roadBuilderObject)
 {
     List <Guid>        list = IntersectionManager.Instance[_connectionSet];
     MeshBuilderSection jb   = new MeshBuilderSection(
         roadBuilderObject,
         list,
         _materialName,
         _subDivide);
     // TODO: Do we need this for basic roads
     // jb.UpdateEndPoints();
 }
        /// <summary>
        /// Create the mesh for this section
        /// </summary>
        /// <param name="roadBuilderObject">The object to create the mesh on</param>
        public void DrawMesh(IRoadBuildData roadBuilderObject)
        {
            List <Guid> list = IntersectionManager.Instance[_connectionSet];

            MeshBuilderSection jb = new MeshBuilderSection(
                roadBuilderObject,
                list,
                _materialName,
                _subDivide);

            jb.Build();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Update all of the end points of the cross roads
        /// </summary>
        /// <param name="order">The orderd list of roads</param>
        /// <param name="mbs">The created mesg builder</param>
        /// <param name="outterInner">Holds the list of outter and inner cross sections</param>
        private void UpdateRoadNodesEndPoints(out RoadFiveRoadOrder order, out MeshBuilderSection mbs, out OutterInner outterInner)
        {
            outterInner = new OutterInner();
            order       = new RoadFiveRoadOrder(_list, _roadNetworkNode.Details.Roads);

            mbs = new MeshBuilderSection(_roadObject, null, _materialName, 0);

            for (int i = 0; i < _totalRoads; i++)
            {
                outterInner.Outter[i] = GetOutter(order, i);
                outterInner.Inner[i]  = GetInner(order, i);
            }

            // Store the ids so we know where to update them later
            for (int i = 0; i < _totalRoads; i++)
            {
                Guid id = order.Road(i).ID;
                order.ReSet(i, FindSmallestRoadForJunction(order.RoadNode(i), outterInner.Outter[i], order.Road(i).Middle));
                IntersectionManager.Instance.SetIntersection(id, order.Road(i));
            }
        }
        /// <summary>
        /// Update all of the end points of the jucntions
        /// </summary>
        /// <param name="order">The orderd list of roads</param>
        /// <param name="mbs">The created mesg builder</param>
        /// <param name="leftIntersectionInner">The inner left cross section</param>
        /// <param name="leftIntersectionOutter">The outter left cross section</param>
        /// <param name="rightIntersectionInner">The inner right cross section</param>
        /// <param name="rightIntersectionOutter">The outter right cross section</param>
        /// <param name="middleIntersectionInner">The middle road cross sections</param>
        private void UpdateRoadNodesEndPoint(out RoadJunctionOrder order, out MeshBuilderSection mbs, out RoadCrossSection leftIntersectionInner,
                                             out RoadCrossSection leftIntersectionOutter, out RoadCrossSection rightIntersectionInner, out RoadCrossSection rightIntersectionOutter,
                                             out RoadCrossSection middleIntersectionInner)
        {
            RoadNetworkNode roadA = _roadNetworkNode.Details.Roads[0];
            RoadNetworkNode roadB = _roadNetworkNode.Details.Roads[1];
            RoadNetworkNode roadC = _roadNetworkNode.Details.Roads[2];

            order = new RoadJunctionOrder(
                _list[0], roadA,
                _list[1], roadB,
                _list[2], roadC);
            mbs = new MeshBuilderSection(_roadObject, null, _materialName, 0);

            // left road
            leftIntersectionInner        = order.LeftRoad.GetIntersection(order.MiddleRoad.Angle, order.MiddleRoad.CurbLeftEnd);
            leftIntersectionOutter       = order.LeftRoad.GetIntersection(order.MiddleRoad.Angle, order.MiddleRoad.Left);
            leftIntersectionInner.Angle += (float)(Math.PI);

            rightIntersectionInner  = order.RightRoad.GetIntersection(order.MiddleRoad.Angle, order.MiddleRoad.CurbRightEnd);
            rightIntersectionOutter = order.RightRoad.GetIntersection(order.MiddleRoad.Angle, order.MiddleRoad.Right);
            Vector3 curbToCurb   = rightIntersectionInner.CurbLeftEnd - leftIntersectionInner.CurbRightEnd;
            float   newRoadAngle = -MathsHelper.GetAngleFrom(curbToCurb.z, curbToCurb.x) + (Mathf.PI / 2);

            middleIntersectionInner = order.MiddleRoad.GetIntersection(newRoadAngle, leftIntersectionInner.CurbRightEnd);

            // Store the ids so we know where to update them later
            Guid leftRoadNodeId   = order.LeftRoad.ID;
            Guid rightRoadNodeId  = order.RightRoad.ID;
            Guid middleRoadNodeId = order.MiddleRoad.ID;

            // reduce the run off roads
            order.ReSetLeft(FindSmallestRoadForJunction(order.LeftRoadNode, leftIntersectionInner, order.LeftRoad.Middle));
            order.ReSetRight(FindSmallestRoadForJunction(order.RightRoadNode, rightIntersectionInner, order.RightRoad.Middle));
            order.ReSetMiddle(FindSmallestRoadForJunction(order.MiddleRoadNode, middleIntersectionInner, order.MiddleRoad.Middle));

            IntersectionManager.Instance.SetIntersection(leftRoadNodeId, order.LeftRoad);
            IntersectionManager.Instance.SetIntersection(middleRoadNodeId, order.MiddleRoad);
            IntersectionManager.Instance.SetIntersection(rightRoadNodeId, order.RightRoad);
        }