2017-06-22 36 views
0

這裏中心點是我的代碼:Libgdx相機繞上爲:eulerAngles

private Quaternion getRotatedQuaternion(float pitch, float yaw, float roll) { 
    tempQuat.setEulerAngles(pitch, yaw, roll); 
    rotationQuat.mulLeft(tempQuat); 

    return rotationQuat; 
} 

  camera.view.setToLookAt(tempPos, tempLookat, Axis.UP); 

      Quaternion rotQuat = getRotatedQuaternion(gestureListener.getXAngle(), gestureListener.getYAngle(), 0); 
      camera.view.rotate(rotQuat); 
      camera.combined.set(camera.projection); 

      Matrix4.mul(camera.combined.val, camera.view.val); 

這是中央的攝像頭轉動,對0,0,0。通過這種方式解決了萬向節鎖問題。但是,我怎樣才能爲它添加一個新的中心點?

基本上我想旋轉的攝像頭在我的對象,而不是0,0,0

感謝

回答

0

我結束了兩個的Matrox旋轉和作爲軌跡球旋轉

0

我認爲你可以做到這一點的唯一方法是,首先,將攝像機移動到該對象的位置,旋轉並將相機移回原來的位置。

因此,像:

Camera.setposition(object.pos) 
Camera.rotate() 
Camera.setposition(original-camera-pos) 
+0

使用矢量這將做萬向節鎖定,是不是對我好! – lacas

+0

「雲臺鎖」是什麼意思? –

+0

https://en.m.wikipedia.org/wiki/Gimbal_lock – lacas

0

你需要從極座標轉換(R,θ)到直角座標(X,Y) 公式如下:

X = R× COS(θ)

Y = R×SIN(θ)

的角度是相對於你的對象中心點(0°至360°),半徑是距離f將你的物體拍攝到你的相機。

這裏有一個簡單的方法是不適合您:

public static Vector3 returnPosArroundObj(Vector3 posObject, Float angleDegrees, Float radius, Float height) { 
    Float angleRadians = angleDegrees * MathUtils.degreesToRadians; 
    Vector3 position = new Vector3(); 
    position.set(radius * MathUtils.sin(angleRadians), height, radius * MathUtils.cos(angleRadians)); 
    position.add(posObject); //add the position so it would be arround object 
    return position; 
} 
+0

我需要做這個沒有萬向節鎖的旋轉。另外我有2個角度。 AngleX和AngleY。順便說一下,我的舊代碼看起來像這個 – lacas

+0

相同,所以你只需要使用數學,x = r sinθcosφ, y = r sinθsinφ, z = r cosθ – Hllink