2012-03-27 52 views
1

如何在WP7中創建計步器?WP7 SDK計步器

我需要創建一個計步器研究

但我不怎麼辦計步器?

 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; 
      } 
     } 

回答

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; 
     } 
+0

哪裏是添加計數器計數? – Chicken 2012-03-28 04:18:30

+0

if(!hasChanged) { isChange = true; counter ++; } – 2012-03-28 09:12:07

+0

剛編輯得更明確 – Mentezza 2012-03-28 09:12:38