2017-01-03 2 views
0

私はlibgdxフレームワークを使用しています。私は、文字modelInstanceとVector3オブジェクトの配列を持っています。文字modelInstanceは、配列内の各Vector3オブジェクト間で変換されます。私が問題を抱えているのは、modelInstanceを、それが向いているベクトルに向けるように回転させることです。どのようにこれを一度達成することができますか?ベクトルを指すように変換を回転

public void move(float delta){ 

     Vector3 start = new Vector3(); 
     modelInstance.transform.getTranslation(start); 

     Vector3 end = pathVectors.get(0); 

     float distance = start.dst(end); 
     Vector3 direction = new Vector3(end); 
     direction.sub(start).nor(); 

     modelInstance.transform.trn(direction.x * moveSpeed * delta, direction.y * moveSpeed * delta, direction.z * moveSpeed * delta); 

     Vector3 currentPosition = new Vector3(); 
     modelInstance.transform.getTranslation(currentPosition); 

     if(start.dst(currentPosition) >= distance){ 

      modelInstance.transform.setTranslation(end); 

      pathVectors.remove(0); 
      if(pathVectors.isEmpty()){ 
       isMoving = false; 
      } 

     } 

    } 

答えて

0

あなたは自分のモデルの向きを変更しようとしている場合は、私はあなたがチェック勧め:以下はmodelinstanceを移動するための私の作業コード(この方法はisMovingプロパティがtrueの間、すべてのサイクルをレンダリングと呼ばれる)されますアウトthis question on StackOverflow。電話でやっていることを無視して、回転を変更する方法を示します。あなたはインクリメンタルその現在の向きとdirectionの間でモデルを回転させることができるようになるすべてが

あなたは回転をより緩やかにするためにしようとしている場合は、あなたがVector3#lerp()Vector3#slerp()、またはVector3#interpolate()を見てみたいかもしれません、あなたはあなたのコードで定義しました。

関連する問題