Ejemplo n.º 1
0
        private float getFingerSpacing(MotionEvent e)
        {
            float x = e.GetX(0) - e.GetX(1);
            float y = e.GetY(0) - e.GetY(1);

            return((float)Math.Sqrt(x * x + y * y));
        }
Ejemplo n.º 2
0
        public void getQuaternion(float[] quaternion, int offset)
        {
            if (offset + 4 > quaternion.Length)
            {
                throw new IllegalArgumentException("Not enough space to write the result");
            }

            float[] m = mHeadView;
            float   t = m[0] + m[5] + m[10];
            float   s, w, x, y, z;

            if (t >= 0.0F)
            {
                s = (float)Math.Sqrt(t + 1.0F);
                w = 0.5F * s;
                s = 0.5F / s;
                x = (m[9] - m[6]) * s;
                y = (m[2] - m[8]) * s;
                z = (m[4] - m[1]) * s;
            }
            else
            {
                if ((m[0] > m[5]) && (m[0] > m[10]))
                {
                    s = (float)Math.Sqrt(1.0F + m[0] - m[5] - m[10]);
                    x = s * 0.5F;
                    s = 0.5F / s;
                    y = (m[4] + m[1]) * s;
                    z = (m[2] + m[8]) * s;
                    w = (m[9] - m[6]) * s;
                }
                else
                {
                    if (m[5] > m[10])
                    {
                        s = (float)Math.Sqrt(1.0F + m[5] - m[0] - m[10]);
                        y = s * 0.5F;
                        s = 0.5F / s;
                        x = (m[4] + m[1]) * s;
                        z = (m[9] + m[6]) * s;
                        w = (m[2] - m[8]) * s;
                    }
                    else
                    {
                        s = (float)Math.Sqrt(1.0F + m[10] - m[0] - m[5]);
                        z = s * 0.5F;
                        s = 0.5F / s;
                        x = (m[2] + m[8]) * s;
                        y = (m[9] + m[6]) * s;
                        w = (m[4] - m[1]) * s;
                    }
                }
            }
            quaternion[(offset + 0)] = x;
            quaternion[(offset + 1)] = y;
            quaternion[(offset + 2)] = z;
            quaternion[(offset + 3)] = w;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Three-dimensional data standardization method, which divides each
        /// number by the root of the sum of squares of all numbers.
        /// </summary>
        /// <param name="vector">vector.</param>
        public static void NormalizeVec3(float[] vector)
        {
            // This data has three dimensions(0,1,2)
            float length = 1.0f / (float)Math.Sqrt(vector[0] * vector[0] + vector[1] * vector[1] + vector[2] * vector[2]);

            vector[0] *= length;
            vector[1] *= length;
            vector[2] *= length;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Return the previous distance between the two pointers forming the
        /// gesture in progress.
        /// </summary>
        /// <returns>Previous distance between pointers in pixels.</returns>
        public float GetPreviousSpan()
        {
            try
            {
                if (MPrevLen == -1)
                {
                    float pvx = MPrevFingerDiffX;
                    float pvy = MPrevFingerDiffY;
                    MPrevLen = (float)Math.Sqrt(pvx * pvx + pvy * pvy);
                }

                return(MPrevLen);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(0);
            }
        }
Ejemplo n.º 5
0
        public float GetCurrentSpan()
        {
            try
            {
                if (MCurrLen == -1)
                {
                    float cvx = MCurrFingerDiffX;
                    float cvy = MCurrFingerDiffY;
                    MCurrLen = (float)Math.Sqrt(cvx * cvx + cvy * cvy);
                }

                return(MCurrLen);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(0);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Return the previous distance between the two pointers forming the
        /// gesture in progress.
        /// </summary>
        /// <returns>Previous distance between pointers in pixels.</returns>
        public float GetPreviousSpan()
        {
            try
            {
                if (MPrevLen == -1)
                {
                    float pvx = MPrevFingerDiffX;
                    float pvy = MPrevFingerDiffY;
                    MPrevLen = (float)Math.Sqrt(pvx * pvx + pvy * pvy);
                }

                return(MPrevLen);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
                return(0);
            }
        }
Ejemplo n.º 7
0
        public float GetCurrentSpan()
        {
            try
            {
                if (MCurrLen == -1)
                {
                    float cvx = MCurrFingerDiffX;
                    float cvy = MCurrFingerDiffY;
                    MCurrLen = (float)Math.Sqrt(cvx * cvx + cvy * cvy);
                }

                return(MCurrLen);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
                return(0);
            }
        }
Ejemplo n.º 8
0
        public void getEulerAngles(float[] eulerAngles, int offset)
        {
            if (offset + 3 > eulerAngles.Length)
            {
                throw new IllegalArgumentException("Not enough space to write the result");
            }

            float yaw, roll, pitch = (float)Math.Asin(mHeadView[6]);

            if ((float)Math.Sqrt(1.0F - mHeadView[6] * mHeadView[6]) >= GIMBAL_LOCK_EPSILON)
            {
                yaw  = (float)Math.Atan2(-mHeadView[2], mHeadView[10]);
                roll = (float)Math.Atan2(-mHeadView[4], mHeadView[5]);
            }
            else
            {
                yaw  = 0.0F;
                roll = (float)Math.Atan2(mHeadView[1], mHeadView[0]);
            }

            eulerAngles[(offset + 0)] = (-pitch);
            eulerAngles[(offset + 1)] = (-yaw);
            eulerAngles[(offset + 2)] = (-roll);
        }