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

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

 2011-01-05 10:14:17 来源:本站整理   
核心提示: private Particle mBalls[] = new Particle[NUM_PARTICLES]; ParticleSystem() { for (int i = 0; i < mBalls.length; i++) { mBalls[i] = new Particle(); } }

       private Particle mBalls[] = new Particle[NUM_PARTICLES];

     ParticleSystem() {
           for (int i = 0; i < mBalls.length; i++) {
           mBalls[i] = new Particle();
         }
       }

     private void updatePositions(float sx, float sy, long timestamp) {
         final long t = timestamp;
         if (mLastT != 0) {
           final float dT = (float) (t - mLastT) * (1.0f / 1000000000.0f);
           if (mLastDeltaT != 0) {
             final float dTC = dT / mLastDeltaT;
             final int count = mBalls.length;
             for (int i = 0; i < count; i++) {
               Particle ball = mBalls[i];
               ball.computePhysics(sx, sy, dT, dTC);
             }
           }
           mLastDeltaT = dT;
         }
         mLastT = t;
       }

     public void update(float sx, float sy, long now) {
         updatePositions(sx, sy, now);

        final int NUM_MAX_ITERATIONS = 10;

       boolean more = true;
         final int count = mBalls.length;
         for (int k = 0; k < NUM_MAX_ITERATIONS && more; k++) {
           more = false;
           for (int i = 0; i < count; i++) {
             Particle curr = mBalls[i];
             for (int j = i + 1; j < count; j++) {
               Particle ball = mBalls[j];
               float dx = ball.mPosX - curr.mPosX;
               float dy = ball.mPosY - curr.mPosY;

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

Tags:Android 加速 感应器

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