Beispiel #1
0
        /// <summary>
        ///     METHOD TO UPDATE WALL POSITIONS ACCORDING TO WANTED ANGLE
        ///     NOT USED CURRENTLY, WAS CANCELLED
        /// </summary>
        /// <param name="angle"></param>
        public void SetAngle(float angle)
        {
            var diff = angle - m_angle;

            if (diff == 0)
            {
                return;
            }
            var v = WallFunctions.GetCommonPosition(w1, w2);

            var q    = Quaternion.Euler(0, 0, diff / 2f * m_directionw1w2);
            var qInv = Quaternion.Euler(0, 0, -diff / 2f * m_directionw1w2);

            var neww1dir = q * w1.Direction;
            var neww2dir = qInv * w2.Direction;

            var neww1P1 = w1.P2 - neww1dir * w1.Length;
            var neww1P2 = w1.P1 + neww1dir * w1.Length;
            var neww2P1 = w2.P2 - neww2dir * w2.Length;
            var neww2P2 = w2.P1 + neww2dir * w2.Length;

            if (w1.P1 == v)
            {
                if (w2.P1 == v)
                {
                    // Update w1p2 and w2p2

                    WallFunctions.SetNewPointsForWall(w1, w1.P1, neww1P2, false, true);
                    WallFunctions.SetNewPointsForWall(w2, w2.P1, neww2P2, false, true);
                }
                else
                {
                    // Update w1p2 and w2p1
                    WallFunctions.SetNewPointsForWall(w1, w1.P1, neww1P2, false, true);
                    WallFunctions.SetNewPointsForWall(w1, neww2P1, w2.P2, false, true);
                }
            }
            else
            {
                if (w2.P1 == v)
                {
                    // Update w1p1 and w2p2
                    WallFunctions.SetNewPointsForWall(w1, neww1P1, w1.P2, false, true);
                    WallFunctions.SetNewPointsForWall(w1, w2.P1, neww2P2, false, true);
                }
                else
                {
                    // Update w1p1 and w2p1
                    WallFunctions.SetNewPointsForWall(w1, neww1P1, w1.P2, false, true);
                    WallFunctions.SetNewPointsForWall(w1, neww2P1, w2.P2, false, true);
                }
            }


            m_angle = angle;
        }
    private void generateWalls()
    {
        GameObject[] walls = new GameObject[point_pairs_array.Length];
        for (int i = 0; i < point_pairs_array.Length; i++)
        {
            GameObject wall_object = new GameObject();
            wall_object.layer            = 10;
            wall_object.name             = "Wall " + i;
            wall_object.transform.parent = _3DContainer.transform;
            walls[i] = wall_object;
            WallFunctions wall_script = wall_object.AddComponent <WallFunctions>();
            wall_script.generateWall(point_pairs_array[i][0], point_pairs_array[i][1]);
        }
        this.walls = walls;

        //Create a dictionary of all nodes and coincident walls
        //To be used for adjusting walls and floor generation
        foreach (GameObject wall_object in walls)
        {
            nodeAddOrUpdate(wall_object.GetComponent <WallFunctions>().Start_pt, wall_object);
            nodeAddOrUpdate(wall_object.GetComponent <WallFunctions>().End_pt, wall_object);
        }
    }
Beispiel #3
0
        /// <summary>
        ///     Draw the computed angle
        /// </summary>
        public void DrawAngle()
        {
            m_angle = WallFunctions.GetAngleBetweenWalls(w1, w2);

            float startAngle = 0;
            var   common     = WallFunctions.GetCommonPosition(w1, w2);

            if (common == w1.P1)
            {
                startAngle = Vector3.SignedAngle(Vector3.left, -w1.Direction, Vector3.forward);
            }
            else if (common == w1.P2)
            {
                startAngle = Vector3.SignedAngle(Vector3.left, w1.Direction, Vector3.forward);
            }

            var arcPoints = new List <Vector3>();

            m_segments = Mathf.RoundToInt(m_angle);

            if (m_segments < 0)
            {
                m_directionw1w2 = 1f;
                startAngle      = Vector3.SignedAngle(Vector3.left, w2.Direction, Vector3.forward);
                m_angle         = WallFunctions.GetAngleBetweenWalls(w2, w1);
                m_segments      = Mathf.RoundToInt(m_angle);

                if (common == w2.P1)
                {
                    startAngle = Vector3.SignedAngle(Vector3.left, -w2.Direction, Vector3.forward);
                }
                else if (common == w2.P2)
                {
                    startAngle = Vector3.SignedAngle(Vector3.left, w2.Direction, Vector3.forward);
                }
            }
            else
            {
                m_directionw1w2 = -1f;
            }

            var center = common;
            var sin    = Mathf.Sin(Mathf.Deg2Rad * m_angle);
            var cos    = Mathf.Cos(Mathf.Deg2Rad * m_angle);

            center += w1.Thickness / 2f * w1.Perpendicular * sin + w2.Thickness / 2f * w2.Perpendicular * sin;
            center += w1.Thickness / 2f * w1.Direction * cos * m_directionw1w2 +
                      w2.Thickness / 2f * w2.Direction * cos * -m_directionw1w2;

            //if (Input.GetKeyDown(KeyCode.D))
            //{
            //    var go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            //    go.transform.position = v;
            //    go.transform.localScale = Vector3.one * 0.5f;
            //}

            var angle = startAngle;

            for (var i = 0; i <= m_segments; i++)
            {
                var x = Mathf.Cos(Mathf.Deg2Rad * angle) * Radius;
                var y = Mathf.Sin(Mathf.Deg2Rad * angle) * Radius;

                var pos = new Vector3(x, y, -0.00001f) + center;
                arcPoints.Add(pos);

                if (i == m_segments / 2)
                {
                    AngleTM.transform.position = pos + (pos - center) * 0.15f;
                    AngleTM.text = m_segments + "";
                }

                angle += m_angle / m_segments;
            }

            LineRend.positionCount = arcPoints.Count;
            LineRend.SetPositions(arcPoints.ToArray());
            LineRend.startColor = Color.white * 0.1f;
            LineRend.endColor   = Color.white * 0.1f;


            LineRend.gameObject.SetActive(m_angle != -999 && AngleTM.text != "180");
            AngleTM.gameObject.SetActive(m_angle != -999 && AngleTM.text != "180");

            // Show cotations ? (from room params)

            var r  = WallFunctions.GetRoomsFromWall(w1, WallsCreator.Instance.GetRooms());
            var r2 = WallFunctions.GetRoomsFromWall(w2, WallsCreator.Instance.GetRooms());

            if (r.Count > 0 && r2.Count > 0 && r[0] == r2[0])
            {
                LineRend.gameObject.SetActive(LineRend.gameObject.activeInHierarchy && r[0].ShowCotations);
                AngleTM.gameObject.SetActive(AngleTM.gameObject.activeInHierarchy && r[0].ShowCotations);
            }
        }
Beispiel #4
0
        // Update is called once per frame
        private void Update()
        {
            /////////////////


            cotationTM.color = Color.black;

            if (myElement == null && !isUp && !isDown && !isLeft && !isRight && !isMeasure)
            {
                Destroy(gameObject);
            }

            if (!cotationField)
            {
                foreach (var inf in FindObjectsOfType <InputField>())
                {
                    // ceinture bretelles
                    if (inf.name == "CotationField" || inf.tag == "Cotation")
                    {
                        cotationField = inf;
                    }
                }
            }

            if (!is3D)
            {
                start.z = -0.05f;
                end.z   = -0.05f;
            }

            var show = Length > 0.005 && Length != float.PositiveInfinity && !IsExterior;

            /*start != Vector3.positiveInfinity && end != Vector3.positiveInfinity && */

            arrow1.gameObject.SetActive(show);
            arrow2.gameObject.SetActive(show);
            middle1.gameObject.SetActive(show);
            middle2.gameObject.SetActive(show);
            cotationTM.gameObject.SetActive(show);
            if (!show)
            {
                return;
            }


            var approxDist = Mathf.Floor(Vector3.Distance(start, end) * 100f);
            var offset     = approxDist > 999 ? 0.4f : 0.3f;

            var dir = (end - start).normalized;

            transform.position = (start + end) / 2f;

            transform.rotation = Quaternion.FromToRotation(Vector3.up, dir);

            arrow1.position = start;
            arrow2.position = end;

            var mid     = (arrow1.position + arrow2.position) / 2f;
            var dist    = Vector3.Distance(arrow1.position, arrow2.position);
            var midSize = new Vector2(0.025f, dist / 2f - offset);

            middle1.transform.position = (arrow1.position + mid) / 2f - dir * offset / 4f;
            middle1.size = midSize;

            middle2.transform.position = (arrow2.position + mid) / 2f + dir * offset / 4f;
            middle2.size = midSize;

            cotationTM.transform.position = mid + textOffset + Perp * decalTextOffset;

            if (!is3D)
            {
                cotationTM.transform.localEulerAngles = -transform.localEulerAngles;
            }

            //cotationTM.characterSize = 0.4f;
            cotationTM.text = approxDist + "";

            if (!isMeasure)
            {
                if (is3D)
                {
                    cotationTM.GetComponent <BoxCollider>().size =
                        new Vector3(Mathf.Clamp(Mathf.Log10(approxDist) * 0.13f, 0f, 2f), 0.18f, 0.1f);
                }
                //cotationTM.transform.Translate(cotationTM.)
                else
                {
                    cotationTM.GetComponent <BoxCollider2D>().size =
                        new Vector2(Mathf.Clamp(Mathf.Log10(approxDist) * 0.1f, 0f, 2f), 0.18f);
                }
            }

            // Scale in function of cam Z in 2D
            if (!is3D)
            {
                cotationTM.transform.localScale =
                    Vector3.one * Mathf.Abs(GlobalManager.Instance.cam2DTop.transform.position.z / 10f);
            }

            // Show cotations ? (from room params)
            if (myElement is Wall)
            {
                var r = WallFunctions.GetRoomsFromWall(myElement as Wall, WallsCreator.Instance.GetRooms());
                if (r.Count > 0)
                {
                    for (var i = 0; i < transform.childCount; i++)
                    {
                        transform.GetChild(i).gameObject
                        .SetActive(transform.GetChild(i).gameObject.activeInHierarchy&& r[0].ShowCotations);
                    }
                }
            }

            // Live Update
            if (Input.GetMouseButtonDown(0))
            {
                GameObject go;
                if (is3D)
                {
                    go = InputFunctions.GetHoveredObject(GlobalManager.Instance.cam3D.GetComponent <Camera>());
                }
                else
                {
                    go = InputFunctions.GetHoveredObject2D(GlobalManager.Instance.cam2DTop.GetComponent <Camera>());
                }
                if (go)
                {
                    if (go == cotationTM.gameObject)
                    {
                        SelectedObjectManager.Instance.SetCurrentCotation(this);
                    }
                }
            }

            // Rotation measure
            if (isMeasure)
            {
                Transform camTrans = GlobalManager.Instance.GetActiveCamera().transform;

                List <Transform> transformList = new List <Transform> {
                    middle1.transform, middle2.transform
                };
                foreach (var _transform in transformList)
                {
                    _transform.LookAt(camTrans);
                    _transform.localEulerAngles = new Vector3(0, _transform.localEulerAngles.y, 180);
                }
            }
        }