Beispiel #1
0
        /// <summary>
        /// Calculate the position of the inner corner
        /// </summary>
        /// <param name="roadIndexA">The first road index</param>
        /// <param name="roadIndexB">The second road index</param>
        /// <param name="magnitude">The magnitude of the corner</param>
        /// <param name="posOut">The position of the innre corner</param>
        /// <returns>True if we have found a cross over</returns>
        public bool GetInnerCorner(int roadIndexA, int roadIndexB, float magnitude, out Vector3 posOut)
        {
            Vector3         pos        = gameObject.transform.position;
            RoadNetworkNode rnn        = Details.Roads[roadIndexA].GetComponent <RoadNetworkNode>();
            Vector3         roadPointA = rnn.GetOffSetDownRoad(pos, magnitude);

            RoadNetworkNode rnnB       = Details.Roads[roadIndexB].GetComponent <RoadNetworkNode>();
            Vector3         roadPointB = rnnB.GetOffSetDownRoad(pos, magnitude);

            Vector3 roadPointAEnd = MathsHelper.OffSetVector(
                roadPointA,
                Details.Roads[roadIndexA].GetAngleOfRoad(pos) + (float)(Math.PI / 2),
                magnitude);

            Vector3 roadPointBEnd = MathsHelper.OffSetVector(
                roadPointB,
                Details.Roads[roadIndexB].GetAngleOfRoad(pos) + (float)(Math.PI / 2),
                magnitude);

            posOut = new Vector3();
            Vector3 outB  = new Vector3();
            Vector3 diffA = roadPointA - roadPointAEnd;
            Vector3 diffB = roadPointB - roadPointBEnd;

            if (MathsHelper.ClosestPointsOnTwoLines(out posOut, out outB, roadPointA, diffA.normalized, roadPointB, diffB.normalized))
            {
                return(true);
            }

            posOut = (roadPointA + roadPointB) / 2;
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Draw all the roads linked
        /// </summary>
        /// <param name="gameObject"></param>
        internal void DrawRoads(GameObject gameObject)
        {
            if (Roads == null)
            {
                return;
            }

            Vector3 roadCorner = gameObject.transform.position;

            for (int i = 0; i < Roads.Count; i++)
            {
                if (Roads[i] == null)
                {
                    return;
                }

                Vector3 roadA = Roads[i].gameObject.transform.position;
                Gizmos.color = Color.yellow;
                if (Modified || Roads[i].Details.Modified)
                {
                    Gizmos.color = Color.cyan;
                }

                Gizmos.DrawLine(roadA, roadCorner);
                float roadWidth = RoadConstructorHelper.CrossSectionDetails.RoadWidthValue / 2;

                Gizmos.color = Color.green;
                Vector3 intersectionDown = Roads[i].GetOffSetDownRoad(roadCorner, 0);
                float   a    = Roads[i].GetAngleOfRoad(roadCorner);
                Vector3 endA = MathsHelper.OffSetVector(intersectionDown, a + (Mathf.PI / 2), roadWidth);
                Vector3 endB = MathsHelper.OffSetVector(intersectionDown, a - (Mathf.PI / 2), roadWidth);

                Gizmos.DrawLine(endA, endB);
            }
        }
        /// <summary>
        /// Get the intersection of two points
        /// </summary>
        /// <param name="angleA">The first angle</param>
        /// <param name="angleB">The second angle</param>
        /// <param name="pointA">The first point</param>
        /// <param name="pointB">the second point</param>
        /// <param name="intersectionPoint">The intersection of the two angles</param>
        private static void GetPointFrom(float angleA, float angleB, Vector3 pointA, Vector3 pointB, out Vector3 intersectionPoint)
        {
            Vector3 offSetPointA = MathsHelper.OffSetVector(pointA, angleA - (float)(Math.PI / 2), 50);
            Vector3 offsetPointB = MathsHelper.OffSetVector(pointB, angleB - (float)(Math.PI / 2), 50);
            Vector3 outB         = new Vector3();
            Vector3 diffA        = offSetPointA - pointA;
            Vector3 diffB        = offsetPointB - pointB;

            MathsHelper.ClosestPointsOnTwoLines(out intersectionPoint, out outB, pointA, diffA.normalized, pointB, diffB.normalized);
        }
Beispiel #4
0
        /// <summary>
        /// Find the overlap point of two angles
        /// </summary>
        /// <param name="angleA">Angle a</param>
        /// <param name="angleB">angle B</param>
        /// <param name="posA">Starting point A</param>
        /// <param name="posB">Starting point B</param>
        /// <param name="retPos">The overlap point of the two angles</param>
        /// <returns>The magnitude of the point</returns>
        private static float FindOverlapPoint(float angleA, float angleB, Vector3 posA, Vector3 posB, out Vector3 retPos)
        {
            Vector3 offSetPosA = MathsHelper.OffSetVector(posA, angleA - (float)(Math.PI / 2), 50);
            Vector3 offSetPosB = MathsHelper.OffSetVector(posB, angleB - (float)(Math.PI / 2), 50);
            Vector3 outB       = new Vector3();
            Vector3 diffA      = offSetPosA - posA;
            Vector3 diffB      = offSetPosB - posB;

            MathsHelper.ClosestPointsOnTwoLines(out retPos, out outB, posA, diffA.normalized, posB, diffB.normalized);
            Vector3 gap = retPos - posA;

            return(gap.magnitude);
        }
Beispiel #5
0
        /// <summary>
        /// Extrude the road out, by creating a new node
        /// </summary>
        /// <returns>The newly created road section</returns>
        public GameObject ExtrudeRoad()
        {
            Details.CompressRoads();
            Details.Modified = true;

            float roadAngle = GetCurrentAngle() + (float)(Math.PI / 2);

            if (Details.Union != UNION_TYPE.END)
            {
                roadAngle += (float)(Math.PI / 2);
            }

            Vector3    pos     = MathsHelper.OffSetVector(transform.position, roadAngle, 100);
            GameObject newNode = RoadNetworkNodeHelper.CreateBasicNode(pos, RoadConstructorHelper.GetUniqueRoadName(gameObject), gameObject);

            GameObject rnnB = gameObject;

            RoadNetworkLayout.AddRoadToNode(newNode.GetComponent <RoadNetworkNode>(), rnnB.GetComponent <RoadNetworkNode>());
            RoadNetworkLayout.AddRoadToNode(rnnB.GetComponent <RoadNetworkNode>(), newNode.GetComponent <RoadNetworkNode>());

            ICrossSection sc = gameObject.GetComponent <ICrossSection>();

            if (sc != null)
            {
                newNode.AddComponent <OverridableCrossSection>();
                OverridableCrossSection ocs = newNode.GetComponent <OverridableCrossSection>();
                ocs.Copy(sc);
            }

            IMaterialFrequency fm = gameObject.GetComponent <IMaterialFrequency>();

            if (fm != null)
            {
                newNode.AddComponent <OverridableMaterialFrequency>();
                OverridableMaterialFrequency ocs = newNode.GetComponent <OverridableMaterialFrequency>();
                ocs.Copy(fm);
            }

            return(newNode);
        }
Beispiel #6
0
        /// <summary>
        /// Appiles the off set of the road
        /// </summary>
        /// <param name="baseObject">The base road to apply the off set to</param>
        /// <param name="magitude">The size (distance) of the off set</param>
        /// <returns>The off set postion</returns>
        public Vector3 GetOffSetDownRoad(Vector3 baseObject, float magitude)
        {
            float angle = GetAngleOfRoad(baseObject);

            return(MathsHelper.OffSetVector(baseObject, angle, magitude));
        }