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);
}
更多精彩
赞助商链接