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

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

 2011-01-05 10:14:17 来源:本站整理   
核心提示: Particle() { final float r = ((float) Math.random() - 0.5f) * 0.2f; mOneMinusFriction = 1.0f - sFriction + r; } public void computePhysics(float sx, float

     Particle() {
         final float r = ((float) Math.random() - 0.5f) * 0.2f;
         mOneMinusFriction = 1.0f - sFriction + r;
       }

     public void computePhysics(float sx, float sy, float dT, float dTC) {
         final float m = 1000.0f; // mass of our virtual object
         final float gx = -sx * m;
         final float gy = -sy * m;

      final float invm = 1.0f / m;
         final float ax = gx * invm;
         final float ay = gy * invm;

       final float dTdT = dT * dT;
         final float x = mPosX + mOneMinusFriction * dTC * (mPosX - mLastPosX) + mAccelX
             * dTdT;
         final float y = mPosY + mOneMinusFriction * dTC * (mPosY - mLastPosY) + mAccelY
             * dTdT;
         mLastPosX = mPosX;
         mLastPosY = mPosY;
         mPosX = x;
         mPosY = y;
         mAccelX = ax;
         mAccelY = ay;
       }

     public void resolveCollisionWithBounds() {
         final float xmax = mHorizontalBound;
         final float ymax = mVerticalBound;
         final float x = mPosX;
         final float y = mPosY;
         if (x > xmax) {
           mPosX = xmax;
         } else if (x < -xmax) {
           mPosX = -xmax;
         }
         if (y > ymax) {
           mPosY = ymax;
         } else if (y < -ymax) {
           mPosY = -ymax;
         }
       }
     }

   class ParticleSystem { //收集取样感应器数据来绘制小球位置
       static final int NUM_PARTICLES = 15;

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

Tags:Android 加速 感应器

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