1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
float x,y,z;
float vx,vy,vz;
long t;
public void onStart(float x0, float y0, float z0, float vx0, float vy0, float vz0)
{
this.t = System.currentTimeMillis();
this.x = x0;
this.y = y0;
this.z = z0;
this.vx = vx0;
this.vy = vy0;
this.vz = vz0;
}
public void onNewAcceleration(float ax, float ay, float az)
{
long t1 = System.currentTimeMillis();
float dt = ((float)(t1 - this.t))/1000.0f;
float dx = ax * dt;
float dy = ay * dt;
float dz = az * dt;
// on prend la moyenne de la vitesse (pour l'intégration)
float vxa = this.vx + dx / 2.f;
float vya = this.vy + dy / 2.f;
float vza = this.vz + dz / 2.f;
// on integre l'accélération entre 0 et dt pour la vitesse.
float vx1 = this.vx + dx;
float vy1 = this.vy + dy;
float vz1 = this.vz + dz;
// on integre la vitesse entre 0 et dt pour la position
float x1 = this.x + vxa * dt;
float y1 = this.y + vya * dt;
float z1 = this.z + vza * dt;
this.x = x1;
this.y = y1;
this.z = z1;
this.vx = vx1;
this.vy = vy1;
this.vz = vz1;
this.t = t1;
} |
Partager