问题描述
// Initialization
const offset = new Vector3();
let quat = new Quaternion();
let quatInverse = new Quaternion();
const v = new Vector3(0,0);
const spherical = new Spherical();
const sphericalD = new Spherical();
const cameraLookAt = new Vector3(0,0);
// Render
const speed = 5;
let updateController = false;
if (keypressed["ArrowLeft"]) {
sphericalD.theta -= (2 * Math.PI * speed) / domElement.clientHeight;
updateController = true;
}
if (keypressed["ArrowRight"]) {
sphericalD.theta += (2 * Math.PI * speed) / domElement.clientHeight;
updateController = true;
}
if (keypressed["ArrowUp"]) {
sphericalD.phi -= (2 * Math.PI * speed * 0.5) / domElement.clientHeight;
updateController = true;
}
if (keypressed["ArrowDown"]) {
sphericalD.phi += (2 * Math.PI * speed * 0.5) / domElement.clientHeight;
updateController = true;
}
if (updateController) {
offset.copy(camera.position).sub(cameraLookAt);
quat.setFromunitVectors(camera.up,v);
offset.applyQuaternion(quat);
quatInverse = quat.invert();
spherical.setFromVector3(offset);
spherical.theta += sphericalD.theta;
spherical.phi += sphericalD.phi;
spherical.phi = Math.max(-Math.PI,Math.min(Math.PI,spherical.phi));
spherical.makeSafe();
offset.setFromSpherical(spherical);
offset.applyQuaternion(quatInverse);
camera.position.copy(cameraLookAt).add(offset);
updateController = false;
sphericalD.theta = 0;
sphericalD.phi = 0;
}
camera.lookAt(cameraLookAt);
我确实可以沿球面的纬度不受限制地移动相机,但纵向移动仅限于极点。
有人可以帮助我沿经度不受限制地移动吗。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)