コード例 #1
0
        void UpdatePosition()
        {
            if (!this.mNeedUpdate)
            {
                return;
            }

            if (this.mPressTouch == null && !this.Approximately(this.mLastDelta, Vector3.zero))
            {
                this.mLastDelta   *= this.inertia;
                this.mLastDelta    = this.AdjustDeltaInRange(this.mLastDelta);
                this.mDestination += this.mLastDelta;
            }

            Vector3 force = XMath.Elastic(this.mDestination, this.itemRoot.localPosition, this.dragForce, 0, 0);

            if (Mathf.Approximately(force.sqrMagnitude, 0))
            {
                this.mNeedUpdate = false;
            }

            this.AddForce(force);
        }
コード例 #2
0
        void OnDrawGizmos()
        {
            int count = this.mRealPath.Count;

            if (count < 3)
            {
                return;
            }

            float time = 1.0f;
            float t    = 0;
            int   i    = 0;

            Gizmos.color = Color.white;
            while (i <= mRealPath.Count)
            {
                Vector3 p0 = mRealPath[(i + 0) % count];
                Vector3 p1 = mRealPath[(i + 1) % count];
                Vector3 p2 = mRealPath[(i + 2) % count];

                t += (Time.deltaTime / time);
                if (t > 1.0f)
                {
                    t  = 0.0f;
                    i += 2;
                }

                Vector3 pos = XMath.SampleBezierCurve(p0, p1, p2, t);
                Vector3 dir = (p1 + (p2 - p1) * t) - (p0 + (p1 - p0) * t);
                dir = dir.normalized * 0.5f;
                Gizmos.DrawLine(pos - dir, pos + dir);

                Gizmos.DrawSphere(p1, 0.1f);
                Gizmos.DrawLine(p0, p1);
                Gizmos.DrawLine(p1, p2);
            }
        }
コード例 #3
0
        void LayoutItems(bool kinematic)
        {
            if (!this.mNeedLayout)
            {
                return;
            }

            bool completed = true;

            Vector3 pos = Vector3.zero;

            this.mHead.transform.localPosition = pos;
            for (int i = 0; i < this.mItems.Count; i++)
            {
                var cur    = this.mItems[i];
                var curpos = cur.localPosition;
                pos += this.mDirection * cur.radius;
                if (kinematic)
                {
                    cur.transform.localPosition = pos;
                }
                else if (!this.Approximately(curpos, pos))
                {
                    completed = false;
                    Vector3 force = XMath.Elastic(pos, curpos, this.resilence, 0, 0);
                    this.AddForce(cur, force);
                }
                pos += this.mDirection * cur.radius;
            }
            this.mTail.transform.localPosition = pos;

            if (completed)
            {
                this.mNeedLayout = false;
            }
        }
コード例 #4
0
ファイル: XMath.cs プロジェクト: chqilin/projectx-framework
 public static bool FloatEqual(Vector3 a, Vector3 b)
 {
     return(XMath.FloatEqual(a.x, b.x) &&
            XMath.FloatEqual(a.y, b.y) &&
            XMath.FloatEqual(a.z, b.z));
 }
コード例 #5
0
ファイル: XMath.cs プロジェクト: chqilin/projectx-framework
        /// <summary>
        /// intersetion-test between sphere and line-segment
        /// </summary>
        /// <param name="center">sphere center</param>
        /// <param name="radius">sphere radius</param>
        /// <param name="p1">line-segment p1</param>
        /// <param name="p2">line-segment p2</param>
        /// <returns></returns>
        public static bool Intersect(Vector3 center, float radius, Vector3 p1, Vector3 p2)
        {
            Vector3 point = XMath.NearestPointOnLineSeg(center, p1, p2);

            return((center - point).sqrMagnitude <= radius * radius);
        }
コード例 #6
0
ファイル: XMath.cs プロジェクト: chqilin/projectx-framework
 public static bool FloatEqual(Vector2 a, Vector2 b)
 {
     return(XMath.FloatEqual(a.x, b.x) &&
            XMath.FloatEqual(a.y, b.y));
 }
コード例 #7
0
 bool Approximately(Vector3 a, Vector3 b)
 {
     return(XMath.FloatEqual(a.x, b.x) &&
            XMath.FloatEqual(a.y, b.y) &&
            XMath.FloatEqual(a.z, b.z));
 }
コード例 #8
0
        void AdjustPositionInRange()
        {
            if (this.mItems.Count == 0)
            {
                return;
            }

            Vector3 head = this.transform.InverseTransformPoint(this.mHead.position);
            Vector3 tail = this.transform.InverseTransformPoint(this.mTail.position);

            Vector3 min = this.transform.InverseTransformPoint(this.min.position);
            Vector3 max = this.transform.InverseTransformPoint(this.max.position);

            if (this.mHead == this.mTail)
            {
                this.mNeedUpdate = false;
                Vector3 force = XMath.Elastic(min, head, this.resilence, 0, 0);
                this.AddForce(force);
                return;
            }

            Vector3 min_head = head - min;
            Vector3 max_tail = tail - max;

            bool head_force = min_head.sqrMagnitude > 0.01f && Vector3.Angle(min_head, this.mDirection) <= 90;
            bool tail_force = max_tail.sqrMagnitude > 0.01f && Vector3.Angle(max_tail, this.mDirection) > 90;

            if (!head_force && !tail_force)
            {
                return;
            }

            this.mNeedUpdate = false;

            if (head_force != tail_force)
            {
                Vector3 min_max   = max - min;
                Vector3 head_tail = tail - head;
                if (head_tail.sqrMagnitude > min_max.sqrMagnitude)
                {
                    if (head_force)
                    {
                        Vector3 force = XMath.Elastic(min, head, this.resilence, 0, 0);
                        this.AddForce(force);
                    }
                    else if (tail_force)
                    {
                        Vector3 force = XMath.Elastic(max, tail, this.resilence, 0, 0);
                        this.AddForce(force);
                    }
                }
                else
                {
                    if (head_force)
                    {
                        Vector3 force = XMath.Elastic(min, head, this.resilence, 0, 0);
                        this.AddForce(force);
                    }
                }
            }
            else
            {
                Vector3 force = XMath.Elastic(min, head, this.resilence, 0, 0);
                this.AddForce(force);
            }
        }