Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Box2D插值和固定时间步长_Java_Box2d_Libgdx_Interpolation - Fatal编程技术网

Java Box2D插值和固定时间步长

Java Box2D插值和固定时间步长,java,box2d,libgdx,interpolation,Java,Box2d,Libgdx,Interpolation,我将Libgdx与Box2D和R.U.B.E.编辑器一起使用 我有个问题。不久前,我注意到物理行为因设备速度等不同而有所不同。 所以我搜索了这个问题,找到了问题所在,我感到困惑:D 现在,它终于找到了一种方法,可以让物理在我所有的设备上都表现相同;) 但我看到在我更快的设备上,我的动态身体在跳动/闪烁?或者诸如此类的。 嗯,我发现我可以插值我身体的位置,但有个问题。 我找不到任何能使身体位置之间的插值有效的东西 有谁能给我看一些代码片段,告诉我如何在场景中获取所有的动态实体,并使它们插值它们的位

我将Libgdx与Box2D和R.U.B.E.编辑器一起使用

我有个问题。不久前,我注意到物理行为因设备速度等不同而有所不同。 所以我搜索了这个问题,找到了问题所在,我感到困惑:D 现在,它终于找到了一种方法,可以让物理在我所有的设备上都表现相同;)

但我看到在我更快的设备上,我的动态身体在跳动/闪烁?或者诸如此类的。 嗯,我发现我可以插值我身体的位置,但有个问题。 我找不到任何能使身体位置之间的插值有效的东西

有谁能给我看一些代码片段,告诉我如何在场景中获取所有的动态实体,并使它们插值它们的位置? 请帮帮我:

我把我做的东西寄给你

对于固定时间步长:

代码:全选

public float BOX2D_MAX = 0.25f;
public float BOX2D_STEP = 1 / 60f;

in render() method:

accumulator += dt;          

    if (dt > BOX2D_MAX){
            dt = BOX2D_MAX;
         }
         while (accumulator >= BOX2D_STEP)
         {
            resetsmooth();    

            scene.world.step(BOX2D_STEP, scene.velocityIterations, scene.positionIterations);
            accumulator -= BOX2D_STEP;

         }

         interpolation = accumulator / BOX2D_STEP;
         scene.world.clearForces();             
         smooth();
public void smooth( ) {


         float minusOne = 1.0f - interpolation;

         bod = scene.world.getBodies();

         //looking up for the bodies in my world
         while(bod.hasNext() == true){

               n = bod.next();

               if(n.getType() == BodyType.DynamicBody){

               smoothX = interpolation * n.getPosition().x + minusOne * nPosX;
               smoothY = interpolation * n.getPosition().y + minusOne * nPosY;
               smoothA = interpolation * n.getAngle() + minusOne * nAng;

               //transform the position
               n.setTransform(smoothX, smoothY, smoothA);   

               }
         }
   }

   public void resetsmooth(){

         bod = scene.world.getBodies();

         //looking up for the bodies in my world
         while(bod.hasNext() == true){

            n = bod.next();

            if(n.getType() == BodyType.DynamicBody){

            //getting bodies position
            nPosX = n.getPosition().x;
            nPosY = n.getPosition().y;
            nAng  = n.getAngle();      

            }
         }
      }
而我的身体也在尝试着插值:

代码:全选

public float BOX2D_MAX = 0.25f;
public float BOX2D_STEP = 1 / 60f;

in render() method:

accumulator += dt;          

    if (dt > BOX2D_MAX){
            dt = BOX2D_MAX;
         }
         while (accumulator >= BOX2D_STEP)
         {
            resetsmooth();    

            scene.world.step(BOX2D_STEP, scene.velocityIterations, scene.positionIterations);
            accumulator -= BOX2D_STEP;

         }

         interpolation = accumulator / BOX2D_STEP;
         scene.world.clearForces();             
         smooth();
public void smooth( ) {


         float minusOne = 1.0f - interpolation;

         bod = scene.world.getBodies();

         //looking up for the bodies in my world
         while(bod.hasNext() == true){

               n = bod.next();

               if(n.getType() == BodyType.DynamicBody){

               smoothX = interpolation * n.getPosition().x + minusOne * nPosX;
               smoothY = interpolation * n.getPosition().y + minusOne * nPosY;
               smoothA = interpolation * n.getAngle() + minusOne * nAng;

               //transform the position
               n.setTransform(smoothX, smoothY, smoothA);   

               }
         }
   }

   public void resetsmooth(){

         bod = scene.world.getBodies();

         //looking up for the bodies in my world
         while(bod.hasNext() == true){

            n = bod.next();

            if(n.getType() == BodyType.DynamicBody){

            //getting bodies position
            nPosX = n.getPosition().x;
            nPosY = n.getPosition().y;
            nAng  = n.getAngle();      

            }
         }
      }