简体   繁体   English

PHYSICSJS:身体在静止时收缩

[英]PHYSICSJS: body shrinks when static

I have a very simple animation- just a rectangle sitting on a polygon. 我有一个非常简单的动画 - 只是一个坐在多边形上的矩形。 When I make the polygon static, it shrinks. 当我将多边形设为静态时,它会收缩。 Ultimately, I just want to do an inclined plane model. 最后,我只想做一个倾斜的飞机模型。 Very simple. 很简单。 What am I missing?: 我错过了什么?:

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();
});

});
});

There are a combination of things that make it look like the shape is "shrinking". 有一些组合使它看起来像是“缩小”的形状。

What's actually happening is that your viewport size is smaller than the triangle. 实际发生的是您的视口大小小于三角形。 When you set it to static, it won't be constrained within the edges so part of it is outside the rendering area. 当您将其设置为静态时,它不会被限制在边缘内,因此它的一部分位于渲染区域之外。 When you set it to "dynamic" it will jump up into the rendering area as dictated by the "edge-collision-detection". 当您将其设置为“动态”时,它将按照“边缘碰撞检测”的指示跳转到渲染区域。

So solve this, try shrinking the triangle, or increasing the size of your viewport. 因此,解决此问题,尝试缩小三角形,或增加视口的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM