1

私はPhysicsJSを学んでおり、ユニオンを次のように使用してみました:

// Window bounds
var rect1 = Physics.aabb(0, 100, 300, 200);
var rect2 = Physics.aabb(100, 0, 200, 300);
var viewportBounds = Physics.aabb.union(rect1, rect2);

// Constrain bodies to these bounds
world.add(Physics.behavior('edge-collision-detection', {
  aabb: viewportBounds,
  restitution: 0.99,
  cof: 0.99
}));

しかし、ボールは下に落ちるだけです。

Physics(function(world){

  var viewWidth = 300;
  var viewHeight = 300;

  var renderer = Physics.renderer('canvas', {
    el: 'viewport',
    width: viewWidth,
    height: viewHeight,
    meta: false
  });

  // add the renderer
  world.add(renderer);
  // render on each step
  world.subscribe('step', function(){
    world.render();
  });

  // Window bounds
    var rect1 = Physics.aabb(0, 100, 300, 200);
    var rect2 = Physics.aabb(100, 0, 200, 300);
    var viewportBounds = Physics.aabb.union(rect1, rect2);
  
  // Constrain bodies to these bounds
  world.add(Physics.behavior('edge-collision-detection', {
      aabb: viewportBounds,
      restitution: 0.99,
      cof: 0.99
  }));

  // Add the ball
  world.add(
      Physics.body('circle', {
        x: 0, // x-coordinate
        y: 0, // y-coordinate
        vx: 0.2, // x-velocity
        vy: 0.01, // y-velocity
        radius: 2.0
      })
  );

  // ensure objects bounce when edge collision is detected
  world.add( Physics.behavior('body-impulse-response') );

  // add some gravity
  world.add( Physics.behavior('constant-acceleration') );

  // subscribe to ticker to advance the simulation
  Physics.util.ticker.subscribe(function( time, dt ){

      world.step( time );
  });

  // start the ticker
  Physics.util.ticker.start();

});
body {
  /*background: #121212;*/
}
.pjs-meta {
  display: none;
}

#viewport {
  border: 1px solid #666;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src='http://wellcaffeinated.net/PhysicsJS/assets/scripts/vendor/physicsjs-0.5.0/physicsjs-full-0.5.0.min.js'></script>

<canvas id="viewport" width="300" height="300"></canvas>

GitHub またはそれを使用しているどこにもコードが見つかりません。どなたか手引きをお願いできますか?

4

2 に答える 2

1

GitHub またはそれを使用しているどこにもコードが見つかりません。どなたか手引きをお願いできますか?

Github の .spec の単体テストを読んでみてください。

Javascript をほとんど知らない場合でも非常に読みやすいはずのサンプル テスト:

it("should initialize provided a width/height and point", function() {
    var aabb = Physics.aabb( 4, 5, { x: 20, y: 9 } );
    matches( aabb, { x: 20, y: 9, hw: 2, hh: 2.5 });
});

spec.js はテスト コードのようです。テストは実際にはドキュメンテーションを兼ねており、spec のようなライブラリは、テスト コードをドキュメンテーションのように読めるようにします。さらに、テスト コードは、もちろん、コードの使用方法の例を集めたものです。楽しみ。

他のテスト コードを読んでみてください。

于 2016-02-16T02:56:55.113 に答える
-1

理解した。私は超古いバージョン(physicsjs-0.5.0)で作業していました。私は最新バージョン ( physicsjs-0.7.0 ) にリンクしました。これには、より多くの機能 (これら 2 つのバージョンの間に 4,088 行の新しいコード) があります。更新された仕様に合わせてコードを少しリファクタリングする必要がありましたが、問題ありません。

于 2016-02-17T00:09:01.690 に答える