javascript - 在场景轴上旋转,而不是对象
问题描述
我如何围绕世界的轴而不是对象本身旋转对象?我一直在寻找答案,但没有什么对我有用。
如果我想要旋转的漩涡,我创建了一个层次结构,使它看起来有点像波浪。不幸的是,即使我已经检查并测试了所有的角度,它仍会摇摆不定,而且我无法让它保持正常。
以下是我正在使用的功能:
function spinThePortal(portal, axis, speed, rotation) {
if (axis === 0) {
portal.rotation.y += speed;
} else {
portal.rotation.x += speed;
}
setTimeout(function () {spinThePortal(portal, axis, speed, rotation);}, 50);
}
function createPortals(firstDoubleCoor, secondDoubleCoor, number) {
var direction = 1, notDirection = 0;
if (firstDoubleCoor[0][0] === firstDoubleCoor[1][0]) {
direction = 0; //vertical lines
notDirection = 1;
}
var amount = difference(firstDoubleCoor[0][notDirection], firstDoubleCoor[1][notDirection]);
var material = new THREE.MeshBasicMaterial({color: portalColorList[number]});
var block = new THREE.CubeGeometry(baseSize / 20, baseSize / 20, baseSize / 20);
function squiggle(coor) {
var root = new THREE.Mesh(block, material);
root.position.set(coor[0][0] * baseSize, coor[0][1] * baseSize, baseSize);
var parent = root;
for (var i = 0; i < amount * 43; i++) {
object = new THREE.Mesh(block, material);
object.position.x = baseSize / 30;
parent.add(object);
parent = object;
}
scene.add(root);
root.traverse(function(object) {
object.rotation.set(Math.PI / 10, Math.PI / 10, 0);
});
if (direction === 1) root.rotation.set(0, 0, -Math.PI / 4);
else root.rotation.set(0, 0, Math.PI / 4);
if (spinPortals) spinThePortal(root, direction, portalSpinSpeed, 0);
}
squiggle(firstDoubleCoor);
squiggle(secondDoubleCoor);
}
我不知道问题出在哪里,但是如果您需要查看我的完整创作,请点击以下链接:单击
解决方案
推荐阅读
- angular - 如何在 Angular 的“饼图”上使用“transloco”?
- firebase - 如何使用颤振在 Firebase 存储中流式传输随机视频?
- jasper-reports - 在生成的 Excel 文件中设置工作表选项卡的颜色很热门?
- sql - Rails 6 - 没有问号(?)的“where”sql查询
- python - 将 python 嵌入到 C++ 中
- sql-server - 在两个 SQL Server 数据库之间迁移数据
- android - Coordinator 布局内的回收站视图
- android - 如何在颤动中更改 FutureBuilder 的 connection.state
- google-chrome-extension - 使用 manifest.json 中的键字段将 chrome 扩展发布到 chrome webstore 时出现问题
- node.js - 是否有必要对我的 nodeJS API 实现多线程?