Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.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 LibGDX矢量3 Lerp问题_Java_Vector_Libgdx_Linear Interpolation - Fatal编程技术网

Java LibGDX矢量3 Lerp问题

Java LibGDX矢量3 Lerp问题,java,vector,libgdx,linear-interpolation,Java,Vector,Libgdx,Linear Interpolation,我正在使用LibGDX并尝试在两个矢量之间进行lerp。。。然而,当我这样做的时候,它不是线性的,它以指数的方式缓和它。我不想要这个,我想要它纯粹的线性 这样我的模型就可以跟随一组矢量,就像跟随一条路径一样 我的更新方法的代码片段如下: public void update(float delta) { if (!this.pathQueue.isEmpty() && this.currentDestination == null) { this.curr

我正在使用LibGDX并尝试在两个矢量之间进行lerp。。。然而,当我这样做的时候,它不是线性的,它以指数的方式缓和它。我不想要这个,我想要它纯粹的线性

这样我的模型就可以跟随一组矢量,就像跟随一条路径一样

我的更新方法的代码片段如下:

public void update(float delta) {
    if (!this.pathQueue.isEmpty() && this.currentDestination == null) {
        this.currentDestination = this.pathQueue.poll();
        this.alpha = 0;
    }

    Vector3 position = new Vector3();
    position = this.model.transform.getTranslation(position);

    if (this.currentDestination != null) {
        this.alpha += this.speed * delta; 
        if (this.alpha >= 1) {
            this.currentDestination = this.pathQueue.poll();
            this.alpha = 0;
        }
        System.out.println(alpha);

        //position.interpolate(this.currentDestination.getPosition(), this.alpha, Interpolation.linear);
        position.lerp(this.currentDestination.getPosition(), this.alpha);
        //I have tried interpolate and lerp, same effect.
        this.model.transform.setTranslation(position.x, 0, position.z);
    }
}
谢谢

编辑:

我已将代码更改为一个更简单的问题,并使用了一个固定的新矢量3(5,0,5)矢量:


它仍然会引起问题。同样的事情也会发生!我很困惑。

我想你的问题是:

position.lerp(this.currentDestination.getPosition(), this.alpha);
您将从位置更新到目标,在每帧更新位置后,在下一帧中,您将有效地从新位置插值到终点。(因此,随着距离目标越来越近,要插值的位置之间的差异会越来越小。)


我认为您正在正确地更新
alpha
,因此您希望在每个帧上从起点到终点进行插值。因此,我认为在开始和结束之间进行插值之前,将“位置”向量重置为开始应该会提供您想要的行为。

是的,您是对的,我也认为是这样的。但即使我这样做:Vector3 newPosition=this.previousDestination.lerp(this.currentDestination.getPosition(),this.alpha);这个.model.transform.setTranslation(newPosition.x,0,newPosition.z);它不起作用。似乎每次调用lerp时都会更新previousDestination,这可能是正常行为?我认为这会修改previousDestination。您可能需要将以前的目标复制或克隆到位(可能?)。在println()中打印当前/上一个/位置,查看其中是否/如何变化……我编辑了我的问题,以获得更简单的问题版本。现在是早上6点,我明天继续
position.lerp(this.currentDestination.getPosition(), this.alpha);