WEB开发网
开发学院手机开发Android 开发 Android加速感应器开发平衡球代码解析 阅读

Android加速感应器开发平衡球代码解析

 2011-01-05 10:14:17 来源:本站整理   
核心提示: float dd = dx * dx + dy * dy; // Check for collisions if (dd <= sBallDiameter2) { dx += ((float) Math.random() - 0.5f) * 0.0001f; dy += ((float) Math.r

               float dd = dx * dx + dy * dy;
               // Check for collisions
               if (dd <= sBallDiameter2) {
                 dx += ((float) Math.random() - 0.5f) * 0.0001f;
                 dy += ((float) Math.random() - 0.5f) * 0.0001f;
                 dd = dx * dx + dy * dy;
                 // simulate the spring
                 final float d = (float) Math.sqrt(dd);
                 final float c = (0.5f * (sBallDiameter - d)) / d;
                 curr.mPosX -= dx * c;
                 curr.mPosY -= dy * c;
                 ball.mPosX += dx * c;
                 ball.mPosY += dy * c;
                 more = true;
               }
             }
             curr.resolveCollisionWithBounds();
           }
         }
       }

     public int getParticleCount() {
         return mBalls.length;
       }

     public float getPosX(int i) {
         return mBalls[i].mPosX;
       }

     public float getPosY(int i) {
         return mBalls[i].mPosY;
       }
     }

   public void startSimulation() {
       mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
     }

上一页  1 2 3 4 5 6  下一页

Tags:Android 加速 感应器

编辑录入:coldstar [复制链接] [打 印]
赞助商链接