[英]How can I rotate around a scene in webgl on mousedrag (emulating a camera moving around a position)
[英]Rotate camera around the scene
我想将相机在场景周围旋转90度。 我试过用
cosole.log(camera.position);
并将相机设置到我在日志中看到的所需位置,但这根本不起作用。
这是相机初始化的方式(对于第一张图像):
var width = window.innerWidth,
height = window.innerHeight;
var camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 1000);
camera.position.set(0, -22, 22);
这就是我的意思:
这就是我想要的(90度逆时针相机转动):
编辑
我注意到我可以自己旋转对象(:这样做:
plane.rotation.z = 90 * Math.PI / 180;
但我仍然很好奇如何旋转相机达到同样的效果。
你必须将相机位置移动一个圆圈,lookAt位置应该是对象或场景:
var rotSpeed = .02
camera.position.x = x * Math.cos(rotSpeed) - z * Math.sin(rotSpeed);
camera.position.z = z * Math.cos(rotSpeed) + x * Math.sin(rotSpeed);
camera.lookAt(scene.position);
这是顺时针方向,另一方向交换加号和减号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.