2017-06-22 52 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