为了账号安全,请及时绑定邮箱和手机立即绑定

LibGDX 相机旋转问题

LibGDX 相机旋转问题

郎朗坤 2021-07-27 08:31:14
我正在尝试围绕我的模型旋转我的透视相机。模型位于中心 (0,0,0) 点。这是我的旋转相机方法:private void rotateCameraAroundModel() {    camera.position.set(0,0,0);    camera.position.rotate(Vector3.Y, 5);    camera.position.add(0f, 0f, 200f);    camera.up.set(Vector3.Y);    camera.lookAt(0,0,0);    camera.update();}我试图去中心,旋转 5 度,然后返回到相同的距离。但是,旋转似乎不起作用,我不知道为什么,非常感谢任何帮助。
查看完整描述

1 回答

?
婷婷同学_

TA贡献1844条经验 获得超8个赞

我想到了 :)


private void rotateCameraAroundModel(float angle) {

    camera.position.set(centreX, centerY, centerZ);

    camera.rotate(Vector3.Y, (float) Math.toDegrees(angle)); // Rotate around Y axis by angle in degrees

    float x = (float) (centerX + radius * (Math.sin(totalPhi)));

    float z =  (float) (centerZ + radius * (Math.cos(totalPhi)));

    camera.position.add(x, 0f, z); //Move back out 2m using pythagorean theorem to calculate the position on the circle

    camera.up.set(Vector3.Y);

    camera.lookAt(0, 0, 0);

    camera.update();

}

所以我需要在旋转时计算圆上的新位置,我使用了一些基本的三角函数


查看完整回答
反对 回复 2021-08-04
  • 1 回答
  • 0 关注
  • 146 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信