예제 #1
0
    private void TouchFinished(int iID)
    {
        float fDistance = Vector3.Distance(m_aoTouchInfos[iID].m_vStartPosition, m_aoTouchInfos[iID].m_vEndPosition);

        if (fDistance >= mk_fMinDistanceForValidate)
        {
            m_aoTouchInfos[iID].m_fTimeElapsed = Time.time - m_aoTouchInfos[iID].m_fTimeElapsed;

            float fSpeed = fDistance / m_aoTouchInfos[iID].m_fTimeElapsed;
            if (fSpeed > mk_fMinSpeedForValidate)
            {
                Vector3 vDirection = m_aoTouchInfos[iID].m_vEndPosition - m_aoTouchInfos[iID].m_vStartPosition;
                vDirection.Normalize();

                float fAngle      = VectorUtils.Angle(mk_vReferenceDirection, mk_vUpVector, vDirection);
                bool  bValidAngle = VectorUtils.IsAngleWithinThreshold(vDirection, mk_vUpVector, mk_vReferenceDirection, mk_iAngleTreshold);

                Debug.Log("fDistance = " + fDistance + "fSpeed = " + fSpeed + " bValidAngle = " + bValidAngle + " fAngle = " + fAngle + " iID = " + iID);

                if (bValidAngle)
                {
                    InternalShootDetected();
                }
            }
        }

        m_aoTouchInfos[iID].m_bStarted = false;
    }
예제 #2
0
        public override void Mutate(bool canMove, Vector3 oldDirection, float oldSpeed, out Vector3 newDirection, out float newSpeed)
        {
            if (Source)
            {
                var direction = Source.transform.position.DirectionTo(transform.position).XY();
                var distance  = Source.transform.position.DistanceTo(transform.position);

                var speed = (MaxDistance / distance) * Acceleration * Time.deltaTime;
                speed = Mathf.Min(speed, MaxSpeed);

                var angle = VectorUtils.Angle(direction, oldDirection.XY());

                if (Math.Abs(oldDirection.sqrMagnitude) < float.Epsilon)
                {
                    newDirection = new Vector3(direction.x, direction.y);
                    newSpeed     = speed;
                }
                else
                {
                    var newDir = oldDirection.XZ().Rotate(angle);
                    newDirection = new Vector3(newDir.x, newDir.y);
                    newSpeed     = oldSpeed + speed;
                }
            }
            else
            {
                base.Mutate(canMove, oldDirection, oldSpeed, out newDirection, out newSpeed);
            }
        }
예제 #3
0
    private void TouchFinished(int iID)
    {
        float fDistance = Vector3.Distance(m_aoTouchInfos[iID].m_vStartPosition, m_aoTouchInfos[iID].m_vEndPosition);

        if (fDistance >= StaticConf.Input.MIN_DISTANCE_VALIDATE)
        {
            m_aoTouchInfos[iID].m_fTimeElapsed = Time.time - m_aoTouchInfos[iID].m_fTimeElapsed;

            float fSpeed = fDistance / m_aoTouchInfos[iID].m_fTimeElapsed;
            if (fSpeed > StaticConf.Input.MIN_SPEED_VALIDATE)
            {
                Vector3 vDirection = m_aoTouchInfos[iID].m_vEndPosition - m_aoTouchInfos[iID].m_vStartPosition;
                vDirection.Normalize();

                float fAngle      = VectorUtils.Angle(StaticConf.Input.DIRECTION_REFERENCE, StaticConf.Input.UP_VECTOR, vDirection);
                bool  bValidAngle = VectorUtils.IsAngleWithinThreshold(vDirection, StaticConf.Input.UP_VECTOR, StaticConf.Input.DIRECTION_REFERENCE, StaticConf.Input.ANGLE_TRESHOLD);

                //Debug.Log("fDistance = " + fDistance + "fSpeed = " + fSpeed + " bValidAngle = " + bValidAngle + " fAngle = " + fAngle + " iID = " + iID);

                if (bValidAngle)
                {
                    InternalSlideDetected(fDistance, fAngle);
                }
            }
        }

        m_aoTouchInfos[iID].m_bStarted = false;
    }
예제 #4
0
        public void ForwardAndBackwardMakeHalf()
        {
            var deg = VectorUtils.AngleDeg(forward, backward);

            Assert.AreEqual(deg, 180f, "Angle mismatch!");

            var rad = VectorUtils.Angle(forward, backward);

            Assert.AreEqual(rad, (float)math.PI, "Angle mismatch!");
        }
예제 #5
0
        public void OneAndFourOClockMake120()
        {
            var fourOClock = RotationUtils.RotateAbout(float3.zero, 120, 1);
            var deg        = VectorUtils.AngleDeg(forward, fourOClock);

            Assert.AreEqual(120, deg, "Angle mismatch!");

            var rad = VectorUtils.Angle(forward, fourOClock);

            Assert.AreEqual(120f * ((float)math.PI) / 180f, rad, "Angle mismatch!");
        }
예제 #6
0
        public void RightAndUpMakePerpendicular()
        {
            var forward = new float3(0, 0, 1);
            var right   = new float3(1, 0, 0);

            var deg = VectorUtils.AngleDeg(forward, right);

            Assert.AreEqual(deg, 90, "Angle mismatch!");

            var rad = VectorUtils.Angle(forward, right);

            Assert.AreEqual(rad, (float)(math.PI / 2), "Angle mismatch!");
        }
예제 #7
0
    private void CheckGesture()
    {
        Vector3 vDirection = m_vEndPosition - m_vStartPosition;
        float   fDistance  = vDirection.magnitude;

        if (fDistance >= mk_fMinDistanceForValidate)
        {
            float fSpeed = fDistance / m_fTimeElapsed;
            if (fSpeed > mk_fMinSpeedForValidate)
            {
                vDirection.Normalize();

                bool bValidAngle = VectorUtils.IsAngleWithinThreshold(mk_vReferenceDirection, mk_vUpVector, vDirection, mk_iAngleTreshold);

                float fAngle = VectorUtils.Angle(mk_vReferenceDirection, mk_vUpVector, vDirection);
                Debug.Log("fDistance = " + fDistance + "fSpeed = " + fSpeed + " bValidAngle = " + bValidAngle + " fAngle = " + fAngle);

                //if(bValidAngle)
                //{
                float VerticOffset = m_vEndPosition.y > m_vStartPosition.y ? m_vEndPosition.y - m_vStartPosition.y : m_vStartPosition.y - m_vEndPosition.y;
                float HorizOffset  = m_vEndPosition.x > m_vStartPosition.x ? m_vEndPosition.x - m_vStartPosition.x : m_vStartPosition.x - m_vEndPosition.x;

                if (VerticOffset > HorizOffset)
                {
                    if (m_vEndPosition.y < m_vStartPosition.y)
                    {
                        Int_SlideToBottomDect();
                    }
                    else if (m_vEndPosition.y > m_vStartPosition.y)
                    {
                        Int_SlideToTopDect();
                    }
                }
                else
                {
                    if (m_vEndPosition.x < m_vStartPosition.x)
                    {
                        Int_SlideToLeftDect();
                    }
                    else if (m_vEndPosition.x > m_vStartPosition.x)
                    {
                        Int_SlideToRightDect();
                    }
                }
                //}
            }
        }
    }
예제 #8
0
    private void CheckGesture()
    {
        Vector3 vDirection = m_vEndPosition - m_vStartPosition;
        float   fDistance  = vDirection.magnitude;

        if (fDistance >= StaticConf.Input.MIN_DISTANCE_VALIDATE)
        {
            float fSpeed = fDistance / m_fTimeElapsed;
            if (fSpeed > StaticConf.Input.MIN_DISTANCE_VALIDATE)
            {
                vDirection.Normalize();

                bool bValidAngle = VectorUtils.IsAngleWithinThreshold(StaticConf.Input.DIRECTION_REFERENCE, StaticConf.Input.UP_VECTOR, vDirection, StaticConf.Input.ANGLE_TRESHOLD);

                float fAngle = VectorUtils.Angle(StaticConf.Input.DIRECTION_REFERENCE, StaticConf.Input.UP_VECTOR, vDirection);
                //Debug.Log("fDistance = " + fDistance + "fSpeed = " + fSpeed + " bValidAngle = " + bValidAngle + " fAngle = " + fAngle);

                if (bValidAngle)
                {
                    InternalSlideDetected(fDistance, fAngle);
                }
            }
        }
    }
예제 #9
0
    public static bool IsAngleWithinThreshold(Vector3 v3Dir1, Vector3 v3Up, Vector3 v3Dir2, int iAngleThreshold)
    {
        float fAngle = VectorUtils.Angle(v3Dir1, v3Up, v3Dir2);

        return(Mathf.Abs(fAngle) <= iAngleThreshold);
    }