コード例 #1
0
  /**
   * Déplace les hitbox passées en paramètre en leur point de collision. On suppose que les objets
   * s'interpénètrent à t = <tt>time</tt>, et ne se touche pas à t = 0. Cette méthode trouve un
   * point de collision approximé par dichotomie.
   */
  protected final CollisionPoint findCollisionPointDefault(Hitbox other, float time) {
    Hitbox both[] = new Hitbox[] {this, other};

    float lower = Math.max(this.lastCollision, other.lastCollision);
    float higher = time;

    while (higher - lower > 0.0001) {
      float bound = (higher + lower) / 2;

      for (Hitbox hb : both) {
        hb.applyVelocity(bound - hb.timeOffset);
      }

      if (this.intersects(other)) {
        higher = bound;
      } else {
        lower = bound;
      }
    }

    return new CollisionPoint(lower, this, other);
  }
コード例 #2
0
 protected void ensureSameTimeOffset(Hitbox other) {
   if (Math.abs(this.timeOffset - other.timeOffset) > 0.001) {
     other.applyVelocity(this.timeOffset - other.timeOffset);
   }
 }