public override void SetupPoints()
        {
            if (tetraPoints == null || tetraPoints.Length == 0)
            {
                tetraPoints = TensegrityUtil.GetTetraPoints(radius);
            }

            for (int i = 0; i < tetraPoints.Length; i++)
            {
                int to    = i;
                int from1 = i + 1 < tetraPoints.Length - 1 ? i + 1 : 0;
                int from2 = from1 + 1 < tetraPoints.Length - 1 ? from1 + 1 : 0;
                int from3 = i < tetraPoints.Length - 1 ? 3 : from2 + 1;
                var p0    = tetraPoints[to];
                var p1    = tetraPoints[from1];
                var p2    = tetraPoints[from2];
                var p3    = tetraPoints[from3];

                var cen = (p1 + p2 + p3) / 3;

                var d1 = cen - p1;
                var d2 = cen - p2;
                var d3 = cen - p3;
                elements.ConstructionPoints.Add(offsetParameter * d1 + cen);
                elements.ConstructionPoints.Add(offsetParameter * d2 + cen);
                elements.ConstructionPoints.Add(offsetParameter * d3 + cen);
            }

            int index = 0;

            for (int i = 0; i < elements.ConstructionPoints.Count; i++)
            {
                elements.ConstructionPoints[i] = TensegrityUtil.CleanUp(elements.ConstructionPoints[i]);
                var p  = elements.ConstructionPoints[i];
                var ep = Instantiate(prefabs.m_PointPrefab, transform);
                ep.transform.localPosition = p;
                ep.transform.localScale    = Vector3.one * param.PointSize;
                ep.name  = "endpoint_" + index;
                ep.index = index;
                if (ep.GetComponentInChildren <Text>())
                {
                    ep.GetComponentInChildren <Text>().text = $"{index}";
                }
                ep.UpdatePosition();
                elements.EndPoints.Add(ep);
                index++;
            }
            elements.center = Instantiate(prefabs.m_Center, transform);
            elements.center.defaultPosition = transform.position;
            elements.center.UpdateCenter(this);
        }
예제 #2
0
        public override void SetupPoints()
        {
            if (tetraPoints == null || tetraPoints.Length == 0)
            {
                tetraPoints = TensegrityUtil.GetTetraPoints(radius);
            }

            /// <summary>
            ///  choose the type!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            /// </summary>
            /// <param name="v0"></param>
            /// <param name="v1"></param>
            /// <param name="v2"></param>
            /// <returns></returns>
            SetPointsByType();
            int index = 0;

            for (int i = 0; i < elements.ConstructionPoints.Count; i++)
            {
                elements.ConstructionPoints[i] = TensegrityUtil.CleanUp(elements.ConstructionPoints[i]);
                var p  = elements.ConstructionPoints[i];
                var ep = Instantiate(prefabs.m_PointPrefab, transform);
                ep.transform.localPosition = p;
                ep.transform.localScale    = Vector3.one * param.PointSize;
                ep.name  = "endpoint_" + index;
                ep.index = index;
                if (ep.GetComponentInChildren <Text>())
                {
                    ep.GetComponentInChildren <Text>().text = $"{index}";
                }
                ep.UpdatePosition();
                elements.EndPoints.Add(ep);
                index++;
            }
            elements.center = Instantiate(prefabs.m_Center, transform);
            elements.center.defaultPosition = transform.position;
            elements.center.UpdateCenter(this);
        }
        public override void SetupPoints()
        {
            if (tetraPoints == null || tetraPoints.Length == 0)
            {
                tetraPoints = TensegrityUtil.GetTetraPoints(radius);
            }

            Vector3[] PointsContainer = new Vector3[8];
            var       t0 = tetraPoints[0];
            var       t1 = tetraPoints[1];
            var       t2 = tetraPoints[2];
            var       t3 = tetraPoints[3];
            //print(tetraPoints.Length);
            var p4 = new Vector3();
            var p5 = new Vector3();
            var p6 = new Vector3();
            var p7 = new Vector3();

            for (int i = 0; i < tetraPoints.Length; i++)
            {
                PointsContainer[0] = (t0 - t1 + t2 - t1) * 0.5f * 0.25f + t1;
                PointsContainer[1] = (t1 - t0 + t3 - t0) * 0.5f * 0.25f + t0;
                PointsContainer[2] = (t0 - t3 + t2 - t3) * 0.5f * 0.25f + t3;
                PointsContainer[3] = (t1 - t2 + t3 - t2) * 0.5f * 0.25f + t2;

                p4 = (t1 - t2 + t3 - t2) * 0.5f * 0.75f + t2;
                p5 = (t1 - t0 + t3 - t0) * 0.5f * 0.75f + t0;
                p6 = (t0 - t1 + t2 - t1) * 0.5f * 0.75f + t1;
                p7 = (t0 - t3 + t2 - t3) * 0.5f * 0.75f + t3;

                PointsContainer[4] = p4 + (p4 - p6) * 0.5f;
                PointsContainer[5] = p5 + (p5 - p7) * 0.5f;
                PointsContainer[6] = p6 + (p6 - p4) * 0.5f;
                PointsContainer[7] = p7 + (p7 - p5) * 0.5f;
            }

            for (int i = 0; i < PointsContainer.Length; i++)
            {
                elements.ConstructionPoints.Add(PointsContainer[i]);
            }

            int index = 0;

            for (int i = 0; i < elements.ConstructionPoints.Count; i++)
            {
                elements.ConstructionPoints[i] = TensegrityUtil.CleanUp(elements.ConstructionPoints[i]);
                var p  = elements.ConstructionPoints[i];
                var ep = Instantiate(prefabs.m_PointPrefab, transform);
                ep.transform.localPosition = p;
                ep.transform.localScale    = Vector3.one * param.PointSize;
                ep.name  = "endpoint_" + index;
                ep.index = index;
                if (ep.GetComponentInChildren <Text>())
                {
                    ep.GetComponentInChildren <Text>().text = $"{index}";
                }
                ep.UpdatePosition();
                elements.EndPoints.Add(ep);
                index++;
            }
            elements.center = Instantiate(prefabs.m_Center, transform);
            elements.center.defaultPosition = transform.position;
            elements.center.UpdateCenter(this);
        }
예제 #4
0
        public override void SetupPoints()
        {
            if (tetraPoints == null || tetraPoints.Length == 0)
            {
                tetraPoints = TensegrityUtil.GetTetraPoints(radius);
            }

            List <Vector3> PointsContainer = new List <Vector3>();
            var            p1 = new Vector3();
            var            p2 = new Vector3();
            var            p3 = new Vector3();

            print(tetraPoints.Length);


            for (int i = 0; i < tetraPoints.Length; i++)
            {
                var cenPoint = new Vector3();

                if (i + 1 < 3)
                {
                    cenPoint = (tetraPoints[i] + tetraPoints[i + 1] + tetraPoints[i + 2]) / 3.0f;
                    p1       = -(tetraPoints[i] - cenPoint) * offsetParameter;
                    p2       = -(tetraPoints[i + 1] - cenPoint) * offsetParameter;
                    p3       = -(tetraPoints[i + 2] - cenPoint) * offsetParameter;
                }
                else if (i + 1 == 3)
                {
                    cenPoint = (tetraPoints[i] + tetraPoints[i + 1] + tetraPoints[i - 2]) / 3.0f;
                    p1       = -(tetraPoints[i] - cenPoint) * offsetParameter;
                    p2       = -(tetraPoints[i + 1] - cenPoint) * offsetParameter;
                    p3       = -(tetraPoints[i - 2] - cenPoint) * offsetParameter;
                }
                else if (i + 1 > 3)
                {
                    cenPoint = (tetraPoints[i] + tetraPoints[i - 2] + tetraPoints[i - 3]) / 3.0f;
                    p1       = -(tetraPoints[i] - cenPoint) * offsetParameter;
                    p2       = -(tetraPoints[i - 3] - cenPoint) * offsetParameter;
                    p3       = -(tetraPoints[i - 2] - cenPoint) * offsetParameter;
                }
                PointsContainer.Add(p1);
                PointsContainer.Add(p2);
                PointsContainer.Add(p3);
            }

            //int no = 0;
            //foreach (var pc in PointsContainer)
            //{
            //    GameObject poingt = Instantiate(GameObject.CreatePrimitive(PrimitiveType.Sphere), pc, Quaternion.identity);
            //    poingt.name = "no." + no;
            //    no++;
            //}
            elements.ConstructionPoints.Add(PointsContainer[9]);
            elements.ConstructionPoints.Add(PointsContainer[7]);
            elements.ConstructionPoints.Add(PointsContainer[5]);
            elements.ConstructionPoints.Add(PointsContainer[6]);
            elements.ConstructionPoints.Add(PointsContainer[2]);
            elements.ConstructionPoints.Add(PointsContainer[4]);
            elements.ConstructionPoints.Add(PointsContainer[1]);
            elements.ConstructionPoints.Add(PointsContainer[11]);
            elements.ConstructionPoints.Add(PointsContainer[3]);
            elements.ConstructionPoints.Add(PointsContainer[0]);
            elements.ConstructionPoints.Add(PointsContainer[10]);
            elements.ConstructionPoints.Add(PointsContainer[8]);

            int index = 0;

            for (int i = 0; i < elements.ConstructionPoints.Count; i++)
            {
                elements.ConstructionPoints[i] = TensegrityUtil.CleanUp(elements.ConstructionPoints[i]);
                var p  = elements.ConstructionPoints[i];
                var ep = Instantiate(prefabs.m_PointPrefab, transform);
                ep.transform.localPosition = p;
                ep.transform.localScale    = Vector3.one * param.PointSize;
                ep.name  = "endpoint_" + index;
                ep.index = index;
                if (ep.GetComponentInChildren <Text>())
                {
                    ep.GetComponentInChildren <Text>().text = $"{index}";
                }
                ep.UpdatePosition();
                elements.EndPoints.Add(ep);
                index++;
            }
            elements.center = Instantiate(prefabs.m_Center, transform);
            elements.center.defaultPosition = transform.position;
            elements.center.UpdateCenter(this);
        }