가속 감지기의 사용에 관하여

2260 단어 androidUP
   1. public static final int CWJ_UP = 0;
   2. public static final int CWJ_DOWN = 1;
   3. public static final int CWJ_LEFT = 2;
   4. public static final int CWJ_RIGHT = 4;
   5. public static final int CWJ_FORWARD = 8; //  
   6. public static final int CWJ_BACKWARD = 16; //   

                 ,    yaw、pitch roll,    3D             ,          y、x、z       ,        3D       Android           Cube     Render                 。

Yaw (0,0,0) ,  xOz        y   ,           CWJ_YAW_LEFT       ,        :

   1. public static final int CWJ_YAW_LEFT = 0;
   2. public static final int CWJ_YAW_RIGHT = 1;
   3. public static final int CWJ_PITCH_UP = 2;
   4. public static final int CWJ_PITCH_DOWN = 4;
   5. public static final int CWJ_ROLL_LEFT = 8;
   6. public static final int CWJ_ROLL_RIGHT = 16; 

              SensorEvent    ,  Android123         ,       , public int accuracy 、public Sensor sensor 、public long timestamp     public final float[] values  ,    values          。

      int nAndroid123=CWJ_UP //  


     float ax = values[0];

      float ay = values[1];

      float az = values[2];

      

      float absx = Math.abs(ax);

      float absy = Math.abs(ay);

      float absz = Math.abs(az);

        

      if (absx > absy && absx > absz) {


      if (ax > 0) {

        nAndroid123 = CWJ_RIGHT;

      } else {

        nAndroid123 = CWJ_LEFT;

      }

      } else if (absy > absx && absy > absz) {

   

      if (ay > 0) {

      nAndroid123= CWJ_FORWARD;

      } else {

      nAndroid123= CWJ_BACKWARD;

      }

      } else if (absz > absx && absz > absy) {


      if (az > 0) {

        nAndroid123 = CWJ_UP;

      } else {

        nAndroid123 = CWJ_DOWN;

      }

      } else {

     nAndroid123 = CWJ_UNKNOWN;
     } 

좋은 웹페이지 즐겨찾기