如何解决Three.js Blender 风格的轨道控制 - 沿球面经度无限制移动
// 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 举报,一经查实,本站将立刻删除。