0

我有一个非常简单的动画——只是一个位于多边形上的矩形。当我使多边形静态时,它会缩小。最终,我只想做一个斜面模型。很简单。我错过了什么?:

define(
    [
    'underscore',
    'jquery',
    'physicsjs'

    ], 
    function(underscore,$,
        Physics
   ) {

Physics(function(world){
      var viewWidth = 700;
      var viewHeight = 500;
      var center = Physics.vector(viewWidth, viewHeight).mult(0.5)
      var renderer = Physics.renderer('canvas', {
        el: 'viewport',
        width: viewWidth,
        height: viewHeight,

    });

  // add the renderer
  world.add( renderer );

var  ang = 38
var square = Physics.body('rectangle',{
  x: 320,
  y: 380,
  width: 50,
  height: 25,
  vx:0.0,

  angle:ang*Math.PI/180.,
  styles: {
    fillStyle: '#d33682'
  }

});
world.add(square);


world.add( Physics.body('convex-polygon', {
    x: 400,
    y: 500,
    vx: 0,
    cof: 1,
    vertices: [
        {x: 0, y: 0},
        {x: 400, y: 0},
        {x: 0, y: -300},

    ],
    treatment: 'static',
  styles: {
    fillStyle: '#FFEF73'
  }
}) );



world.add(Physics.behavior('constant-acceleration'))

var bounds = Physics.aabb(0,0,viewWidth,viewHeight);

world.add(Physics.behavior('edge-collision-detection', {
  aabb: bounds,
  restitution: 0.3
}));
world.add(Physics.behavior('body-impulse-response'))


world.add(Physics.behavior('body-collision-detection', {
}));
world.add(Physics.behavior('sweep-prune'));

Physics.util.ticker.on(function(time,dt){
  world.step(time);
});

Physics.util.ticker.start();

world.on('step',function(){
  world.render();
});

});
});
4

1 回答 1

2

有多种因素使它看起来像“缩小”。

实际发生的是您的视口大小小于三角形。当您将其设置为静态时,它不会被限制在边缘内,因此它的一部分位于渲染区域之外。当您将其设置为“动态”时,它将按照“边缘碰撞检测”的指示跳入渲染区域。

所以解决这个问题,尝试缩小三角形,或增加视口的大小。

于 2014-05-07T16:32:30.717 回答