Ale*_*yer 6 java 3d android opengl-es libgdx
我试图在我的世界中围绕模型以球形运动移动我的相机.我已经看到将球面坐标(rho,theta,phi)转换为笛卡尔坐标(x,y,z),但我不确定如何设置它.这是我到目前为止所尝试过的,但它没有连续围绕模型运行.它到达某个点,然后旋转似乎逆转自己.
初始化theta和phi:
private float theta = 0.0f;
private float phi = 0.0f;
Run Code Online (Sandbox Code Playgroud)
更新theta和phi每个框架:
// This should move the camera toward the upper-right continuously, correct?
theta = (theta+1.0f)%360;
phi = (phi+1.0f)%360;
Run Code Online (Sandbox Code Playgroud)
转换theta并phi为摄像头直角坐标系:
camera.position.x = CAMERA_DISTANCE * (float)Math.sin(theta*MathHelper.PIOVER180) * (float)Math.cos(phi*MathHelper.PIOVER180);
camera.position.y = CAMERA_DISTANCE * (float)Math.sin(theta*MathHelper.PIOVER180) * (float)Math.sin(phi*MathHelper.PIOVER180);
camera.position.z = CAMERA_DISTANCE * (float)Math.cos(theta*MathHelper.PIOVER180);
Run Code Online (Sandbox Code Playgroud)
然后更新相机看点和视图矩阵:
camera.lookAt(0, 0, 0);
camera.update();
Run Code Online (Sandbox Code Playgroud)
注意:
我在Android上使用带有libGDX框架的Java,我试图使用2D屏幕虚拟操纵杆来控制旋转,我仍然需要找到一种方法来将操纵杆映射到theta和phi.
任何帮助是极大的赞赏!
我最近做了这样的事情.这个网站帮助我了解了我需要做的事情.
你需要做的是将你的本地操纵杆坐标(相对于它的中心)转换为俯仰和偏航值:
public float getPitch()
{
return (position.X - center.X) * MathHelper.PIOVER180;
}
public float getYaw()
{
return (position.Y - center.Y) * MathHelper.PIOVER180;
}
Run Code Online (Sandbox Code Playgroud)
然后你可以使用四元数来表示它的旋转:
public void rotate(float pitch, float yaw, float roll)
{
newQuat.setEulerAngles(-pitch, -yaw, roll);
rotationQuat.mulLeft(newQuat);
}
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用libGDX的内置rotate(quaternion)方法将四元数应用于相机的视图矩阵:
camera.view.rotate(rotationQuat);
// Remember to set the camera to "look at" your model
camera.lookAt(0, 0, 0);
Run Code Online (Sandbox Code Playgroud)