WP7 SDK计步器

时间:2012-03-27 18:29:26

标签: windows-phone-7 windows-phone-7.1 winapi

如何在WP7中创建计步器?

我需要创建一个计步器来研究

但我不知道怎么做计步器?

        M = Math.Sqrt(args.X * args.X + args.Y * args.Y + args.Z * args.Z);

        if (Tec == true)
        {
            if (M >= 2)
            {
                if (Magnitude == true)
                {
                    counter = counter + 1;
                    Magnitude = false;
                }

            }
            else 
            {
                Magnitude = true;
            }
        }

1 个答案:

答案 0 :(得分:4)

这对我有用:

       private bool hasChanged;
       private int counter;

       private void checkIsMouvement(SensorReadingEventArgs<AccelerometerReading> e)
       {
            float x = e.get_SensorReading().get_Acceleration().X;
            float y = e.get_SensorReading().get_Acceleration().Y;
            float z = e.get_SensorReading().get_Acceleration().Z;
            double oldValue = ((x_old * x) + (y_old * y)) + (z_old * z);
            double oldValueSqrT = Math.Abs(Math.Sqrt((double) (((x_old * x_old) + (y_old * y_old)) + (z_old * z_old))));
            double newValue = Math.Abs(Math.Sqrt((double) (((x * x) + (y * y)) + (z * z))));
            oldValue /= oldValueSqrt * newValue;
            if ((oldValue <= 0.994) && (oldValue > 0.9))
            {
                if (!hasChanged)
                {
                    hasChanged = true;
                    counter++; //here the counter
                }
                else
                {
                    hasChanged = false;
                }
            }
            x_old = x;
            y_old = y;
            z_old = z;
      }