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