Exemplo 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the angle of the road
        /// </summary>
        /// <param name="baseObject">The road to get the angle from</param>
        /// <returns>The angle of the road</returns>
        public float GetAngleOfRoad(Vector3 baseObject)
        {
            Vector3 endPosition = transform.position;
            Vector3 diff        = endPosition - baseObject;

            return(MathsHelper.GetAngleFrom(diff.x, diff.z) - Mathf.PI / 2);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get the angle of the road
        /// </summary>
        /// <param name="roadNetworkNode">The main node</param>
        /// <param name="index">Index of the road</param>
        /// <returns>The angle of the road</returns>
        public static float GetAngleOfRoadClampped(RoadNetworkNode roadNetworkNode, int index)
        {
            GameObject StartObj = roadNetworkNode.gameObject;
            GameObject EndObj   = roadNetworkNode.Details.Roads[index].gameObject;

            Vector3 startPosition = StartObj.transform.position;
            Vector3 endPosition   = EndObj.transform.position;
            Vector3 diff          = startPosition - endPosition;

            return(MathsHelper.ClampAngle(MathsHelper.GetAngleFrom(diff.x, diff.z)));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get the best angle from all the roads
        /// </summary>
        /// <returns>The best angle</returns>
        private float GetCurrentAngle()
        {
            if (Details.Union == UNION_TYPE.NONE)
            {
                return(0);
            }

            Vector3 pos = Details.Roads[0].transform.position - transform.position;

            return(MathsHelper.GetAngleFrom(pos.x, pos.z));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get the angle of the road
        /// </summary>
        /// <param name="roadNetworkNode">The main node</param>
        /// <returns>The angle of the road</returns>
        private float GetAngleOfRoad(RoadNetworkNode rnn)
        {
            GameObject StartObj = _roadNetworkNode.gameObject;
            GameObject EndObj   = rnn.gameObject;

            Vector3 startPosition = StartObj.transform.position;
            Vector3 endPosition   = EndObj.transform.position;
            Vector3 diff          = startPosition - endPosition;

            return(MathsHelper.GetAngleFrom(diff.x, diff.z));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Get the sortest inner cross for the roads
        /// </summary>
        /// <param name="order">The road order list</param>
        /// <param name="mainRoad">The road to get the middle of</param>
        /// <returns>The cross section of the road</returns>
        private RoadCrossSection GetInner(RoadFiveRoadOrder order, int mainRoad)
        {
            int rightRoad = order.GetNextRightIndex(mainRoad);
            int leftRoad  = order.GetNextLeftIndex(mainRoad);

            Vector3 posLeft;
            Vector3 posRight;

            FindOverlapPoint(order.Road(mainRoad).Angle, order.Road(rightRoad).Angle, order.Road(mainRoad).Right, order.Road(rightRoad).Left, out posLeft);
            FindOverlapPoint(order.Road(leftRoad).Angle, order.Road(mainRoad).Angle, order.Road(leftRoad).Right, order.Road(mainRoad).Left, out posRight);

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

            return(order.Road(mainRoad).GetIntersection(newRoadAngle, posLeft));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Find the smallest road needed for this junction
        /// </summary>
        /// <param name="currentroadNode">The road node</param>
        /// <param name="crossSections">The cross section of the road</param>
        /// <param name="middlePoint">The middle point in the cross section</param>
        /// <returns>The cross seciton of the road that is nearest to the junction</returns>
        private RoadCrossSection FindSmallestRoadForJunction(RoadNetworkNode currentroadNode, RoadCrossSection crossSections, Vector3 middlePoint)
        {
            Vector3 a        = crossSections.Middle;
            Vector3 diffline = a - middlePoint;
            float   angleA   = MathsHelper.GetAngleFrom(diffline.x, diffline.z);

            angleA = RoadUnionHelper.AngleClamp(crossSections.Angle - angleA) - Mathf.PI / 2;
            Vector3 diff = a - crossSections.CurbLeftEndDrop;
            float   mag2 = diff.magnitude * Mathf.Cos(angleA);

            if (mag2 < 0)
            {
                mag2 = -mag2;
            }
            Vector3          roadPointA = currentroadNode.GetOffSetDownRoad(crossSections.Middle, mag2);
            float            angleB     = RoadUnionHelper.AngleClamp(GetAngleOfRoad(currentroadNode) + Mathf.PI / 2);
            RoadCrossSection rA         = new RoadCrossSection(roadPointA, angleB - (float)(Math.PI / 2), RoadConstructorHelper.CrossSection(currentroadNode), RoadConstructorHelper.Materials(currentroadNode));

            return(rA);
        }
        /// <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);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Get the angle of the road
        /// </summary>
        /// <param name="position">The base position</param>
        /// <returns>The angle of the road</returns>
        private float GetRoadAngle(Vector3 position)
        {
            Vector3 pos = position - transform.position;

            return(MathsHelper.GetAngleFrom(pos.x, pos.z));
        }
Exemplo n.º 10
0
    /// <summary>
    /// Gets the angle between two vectors
    /// </summary>
    /// <param name="startPosition">The first vector</param>
    /// <param name="endPosition">The second vectot</param>
    /// <returns>The angle between the two vectors</returns>
    public static float GetAngle(Vector3 startPosition, Vector3 endPosition)
    {
        Vector3 diff = startPosition - endPosition;

        return(MathsHelper.GetAngleFrom(diff.x, diff.z));
    }