2015-01-15 5 views
1

LibGDX를 사용하고 있는데 두 Vector3s 사이를 lerp하려고합니다. 그러나 이렇게하면 선형이 아니며 기하 급수적으로 쉽게 줄 수 있습니다. 나는 이것을 원하지 않는다, 나는 그것을 순수하게 선형으로 원한다!LibGDX Vector3 Lerp 문제

내 모델이 경로를 따르는 것처럼 Vector3s를 따라갈 수 있습니다.

내 업데이트 방법의 코드는 여기에 있습니다 :

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

감사합니다!

편집 :

내가 더 간단한 문제가 내 코드를 변경하고, 고정 새로운 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); 
    } 
} 

아직 문제가 발생합니다. 같은 일이 일어난다! 나는 너무 비웃었다.

답변

3

나는 당신의 문제가이 생각 :

position.lerp(this.currentDestination.getPosition(), this.alpha); 

당신은 다음 프레임에, 그래서 당신은 효과적으로 당신의 새로운 위치에서 보간하고 당신이 위치를 업데이트 각 프레임 후, 목적지까지의 위치에서 업데이트 종료. 따라서 목적지에 가까워 질수록 위치를 보간하는 위치의 차이가 작아집니다.

alpha을 올바르게 업데이트하고 있으므로 처음부터 각 프레임에서 대상까지 보간을 수행하려고합니다. 따라서 시작과 끝 사이를 보간하기 전에 "위치"벡터를 시작 위치로 재설정하면 원하는 동작을 얻을 수 있습니다.

+0

네가 옳다. 나는 또한 이것과 비슷한 것으로 생각한다. 그러나 내가 이렇게하더라도 : Vector3 newPosition = this.previousDestination.lerp (this.currentDestination.getPosition(), this.alpha); \t \t \t this.model.transform.setTranslation (newPosition.x, 0, newPosition.z); 작동하지 않습니다. lerp가 호출 될 때마다 this.previousDestination이 업데이트되는 것 같습니다. 정상적인 동작 일 수 있습니까? – Dolan

+0

나는 previousDestination을 수정한다고 생각합니다. 이전 목적지를 복사하거나 복제해야 할 수도 있습니다 (아마?). println()에서 현재/이전/위치를 인쇄하여 이들 중 어느 것이 변경되고 있는지 확인하십시오. –

+0

더 간단한 버전의 문제에 대한 제 질문을 편집했습니다. 그것의 6am 지금, 아픈이 내일과 함께 계속 – Dolan