コード例 #1
0
        public override void SetupPath()
        {
            chainRail.Clear();
            for (int i = 0; i < ControlPoints.Count - (Loop ? 0 : 2); i++)
            {
                Vector3 startpos = CalcKnot(i);
                startpos = transform.TransformPoint(startpos);
                Vector3    starttangent = KnotTangent(i);
                Quaternion startrot     = transform.rotation * Quaternion.LookRotation(starttangent, UpWards[i]);

                Vector3 endpos = CalcKnot((i + 1) % ControlPoints.Count);
                endpos = transform.TransformPoint(endpos);
                Vector3    endtangent = KnotTangent((i + 1) % ControlPoints.Count);
                Quaternion endrot     = transform.rotation * Quaternion.LookRotation(endtangent, UpWards[(i + 1) % UpWards.Count]);

                if (Quaternion.Angle(startrot, endrot) < 1f)
                {
                    var newrail = new LerpRail(startpos, endpos, transform.up);
                    newrail.HeightFunc = (z) => 0;
                    chainRail.AddRail(newrail);
                }
                else
                {
                    var newrail = new InvoluteRail();
                    newrail.Interpolate(startpos, startrot, endpos, endrot);
                    newrail.HeightFunc = (z) => 0;
                    chainRail.AddRail(newrail);
                }
            }
        }
コード例 #2
0
        //制御点に従ってレールを配置する
        public override void SetupPath()
        {
            chainRail.Clear();
            for (int i = 0; i < ControlPoints.Count - (Loop ? 0 : 2); i++)
            {
                Vector3 startpos    = CalcKnot(i);
                float   startHeight = startpos.y;
                startpos.y = 0;
                startpos   = transform.TransformPoint(startpos);
                Vector3 starttangent  = KnotTangent(i);
                float   startgradient = starttangent.y / new Vector2(starttangent.x, starttangent.z).magnitude;
                starttangent.y = 0;
                Quaternion startrot = transform.rotation * Quaternion.LookRotation(starttangent, Vector3.up);

                Vector3 endpos    = CalcKnot((i + 1) % ControlPoints.Count);
                float   endHeight = endpos.y;
                endpos.y = 0;
                endpos   = transform.TransformPoint(endpos);
                Vector3 endtangent  = KnotTangent((i + 1) % ControlPoints.Count);
                float   endgradient = endtangent.y / new Vector2(endtangent.x, endtangent.z).magnitude;
                endtangent.y = 0;
                Quaternion endrot = transform.rotation * Quaternion.LookRotation(endtangent, Vector3.up);

                if (Quaternion.Angle(startrot, endrot) < 1f)
                {
                    var newrail = new LerpRail(startpos, endpos, transform.up);
                    var func    = new HermiteFunc(startHeight, startgradient * newrail.Length, endHeight, endgradient * newrail.Length);
                    newrail.HeightFunc = (z) => func.Hermite(z / newrail.Length);
                    chainRail.AddRail(newrail);
                }
                else
                {
                    var newrail = new InvoluteRail();
                    newrail.Interpolate(startpos, startrot, endpos, endrot);
                    var func = new HermiteFunc(startHeight, startgradient * newrail.Length, endHeight, endgradient * newrail.Length);
                    newrail.HeightFunc = (z) => func.Hermite(z / newrail.Length);
                    chainRail.AddRail(newrail);
                }
            }
        }