在 x、y 和 z 轴上旋转立方体?

时间:2020-12-19 22:55:11

标签: three.js rotation

我有一个位于 (0, 0, 0) 处的立方体。我试图在 x、y 和 z 轴上旋转它。目前我正在这样做:

function rotation(axis)
{

    var quaternion = new THREE.Quaternion().setFromAxisAngle(axis, angle);
    cube.quaternion.copy(quaternion);
    
    cube.updateMatrix(); 
    cube.geometry.applyMatrix(cube.matrix);
    cube.matrix.identity();

    cube.rotation.set(0,0,0);
}

function rotate_x()
{
    rotateX = requestAnimationFrame(rotate_x);
    rotation(new THREE.Vector3(1, 0, 0));

    render(scene, camera);
}
function rotate_y()
{
    rotateY = requestAnimationFrame(rotate_y);
    rotation(new THREE.Vector3(0, 1, 0));

    render(scene, camera);
}

function rotate_z()
{
    rotateZ = requestAnimationFrame(rotate_z);
    rotation(new THREE.Vector3(0, 0, 1));

    render(scene, camera);
}

rotate_x();
rotate_y();
rotate_z();

但是我不确定它是否在所有三个轴上都正确旋转。这是它的样子:rotation on the cubes x, y, z axis

这是在立方体的三轴上旋转的样子吗?如果不是,如何正确地进行旋转? 另外,考虑到我希望它在其本地轴上旋转,我认为没有万向节锁定问题是否正确?

0 个答案:

没有答案