H1rono / physical-simulation

Processing (Java)で物理シミュレーション
MIT License
0 stars 0 forks source link

箱が落ちる #6

Closed H1rono closed 3 years ago

H1rono commented 3 years ago

サンプルコード:

World world;

void setup() {
    size(720, 720);
    // World(gravity, air_resistance, delta_time)
    world = new World(new PVector(0, 10), 0, 0.05);
    // Box(position, velocity, mass, w_len, h_len)
    // Box1
    world.add_obj(new Box(new PVector(100, 560), new PVector(0, 0), 100, 60, 40));
    // Box2
    world.add_obj(new Box(new PVector(130, 539), new PVector(0, 0), 10, 30, 20));
    // Floor(height)
    world.add_obj(new Floor(600));
}

/*
        +------------------+
        |                  |         Box1
        |                  |
        +------------------+
    +--------------------------+
    |                          |
    |                          |
    |                          |     Box2
    |                          |
    +--------------------------+
------------------------------------ Floor
*/

void draw() {
    background(255);
    world.reset_gravity();
    world.calc_collide();
    world.update();
    world.draw();
}

Worldなどのクラスはこのコミットのものです。 このプログラムを実行すると、Box1Box2にめりこんでしまいます。

H1rono commented 3 years ago

7 で作り直します