コード例 #1
0
  Vec calc_collide_power(Ball p1, Ball p2, double dist) {
    if (dist > radius * 2) return new Vec(); // Friday, August 29, 2008 15:26:33: stickiness bug fix
    Vec speed_diff = p2.speed.sub(p1.speed);
    double force = 1000 * (dist - radius * 2);
    Vec npos1 = p1.pos.div(dist); // normalized
    Vec npos2 = p2.pos.div(dist);
    force += 10 * speed_diff.dot_mult(npos2.sub(npos1));
    Vec ans = npos2.sub(npos1).mult(force);
    return ans;
    /*    colide_power_x=force*(x2-x1)/dist;
    colide_power_y=force*(y2-y1)/dist;*/

  }
コード例 #2
0
  Vec calc_spring_power(Ball p1, Ball p2) {
    double dist = p1.pos.calc_dist(p2.pos);
    // if (abs(dist-STRING_LEN)<.1)
    //	return;
    Vec speed_diff = p2.speed.sub(p1.speed);
    double force = 1000 * (dist - STRING_LEN);
    Vec npos1 = p1.pos.div(dist); // normalized
    Vec npos2 = p2.pos.div(dist);
    force += 100 * speed_diff.dot_mult(npos2.sub(npos1));
    Vec ans = npos2.sub(npos1).mult(force);
    return ans;
    // force*=force;
    //    colide_power_x=(x2-x1)/dist*force;
    //   colide_power_y=(y2-y1)/dist*force;

  }
コード例 #3
0
  void animate() {
    dim = getSize();
    size = (int) (Math.min(dim.height, dim.width) / 2.2);
    timer.tell_time();
    if (timer.time_diff == 0) return; // not enought time has passed, dont animate-crach fix
    dragged_speed = dragged_vec.sub(last_dragged_vec).div(timer.time_diff);
    last_dragged_vec = dragged_vec;
    if (dragged_ball != -1) {
      balls.get2(dragged_ball).pos = dragged_vec.add(find_offset).trim(-1, 1);
      balls.get2(dragged_ball).speed = dragged_speed;
    }

    balls = new WorldAnimate().calc_new_frame(balls, springs, RADIUS, timer);
  }