如何围绕任何线而不是X Y Z或通过坐标原点旋转对象

时间:2016-12-02 04:07:04

标签: javascript three.js rotation

enter image description here

有两个盒子,它们没有任何关系,第一个(中心是原点)在黑线上旋转而第二个(另一个)在黄线上同时旋转!

创建两个网格:

geometry = new THREE.CubeGeometry(50, 50, 50);
material = new THREE.MeshNormalMaterial();

mesh2 = new THREE.Mesh(geometry, material);
mesh2.position.x = 100;
mesh3 = new THREE.Mesh(geometry, material);

scene.add(mesh2);
scene.add(mesh3);

创建两行:

var geometryLine = new THREE.Geometry();
geometryLine.vertices.push(new THREE.Vector3(0, 80, 0));
geometryLine.vertices.push(new THREE.Vector3(0, 80, 180));
var line1 = new THREE.LineSegments(geometryLine, new THREE.LineBasicMaterial({color: 0xffffff}));
scene.add(line1);

var geometryLine2 = new THREE.Geometry();
geometryLine2.vertices.push(new THREE.Vector3(150, 0, 0));
geometryLine2.vertices.push(new THREE.Vector3(150, 0, 180));
var line2 = new THREE.LineSegments(geometryLine2, new THREE.LineBasicMaterial({color: 0xffff00}));
scene.add(line2);

每次使用旋转时,它只会在X Y Z或原点上旋转。

mesh3.rotation.x += 0.01;
mesh2.rotation.y += 0.02;

// I don't know how it works about rotation on specified line

但这不是我想要的?那么如何同时在指定的线上旋转!我是新人。希望问题能够得到解决!

0 个答案:

没有答案