【发布时间】:2015-01-15 13:43:17
【问题描述】:
我正在使用 LibGDX 并试图在两个 Vector3s 之间徘徊......但是,当我这样做时,它不是线性的,它会以指数方式缓和它。我不想要这个,我想要它纯粹的线性!
这样我的模型就可以跟随一组 Vector3,就像跟随一条路径一样。
我的更新方法的代码sn-p在这里:
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);
}
}
谢谢!
编辑:
我已将代码更改为更简单的问题,并使用 FIXED new Vector3(5,0,5) 向量:
public void update(float delta) {
if (!this.pathQueue.isEmpty() && this.currentDestination == null) {
this.currentDestination = this.pathQueue.poll();
this.alpha = 0;
}
if (this.currentDestination != null) {
this.alpha += this.speed * delta;
this.currentPosition.lerp(new Vector3(5,0,5), this.alpha);
this.model.transform.setTranslation(this.currentPosition.x, 0, this.currentPosition.z);
}
}
它仍然会导致问题。同样的事情发生!我很困惑。
【问题讨论】:
标签: java vector libgdx linear-interpolation