无法在three.js中旋转网格

时间:2017-12-18 01:22:39

标签: javascript three.js

如果输入增量值,我可以在three.js中旋转网格,但是如果我使用的是我没有在动画函数中设置的变量,那么它就不起作用了。任何需要的变量在输入之前进行数学运算会导致旋转变为NaN。我试图将鼠标位置用作旋转变量,它可以用来改变对象的位置,但不能用于旋转。



function animate() {
    requestAnimationFrame( animate );	
    var inX = (mouseInX - (document.body.clientWidth / 2)) / 5000;
    var inY = (mouseInY - (document.body.clientHeight / 2)) / 5000;
    camera.position.x = inX;
    camera.position.y = -inY;
    
    //console.log(inX);
    
    
    mesh.rotateOnAxis(new THREE.Vector3 (0.0, 1.0, 0.0), inX); //This causes the mesh to vanish. If I log the roatation on the y axis it say NaN.
    mesh.rotateOnAxis(new THREE.Vector3 (0.0, 0.0, 1.0), 0.001); // This works if both of them have a number typed in like so.
    
    console.log(mesh.rotation.y + ", " + mesh.position.x);
	renderer.render( scene, camera );  
    lastMouseX = mouseInX;
}

function getCurrentMousePos(evt) {
    mouseInX = Number(evt.clientX);
    mouseInY = Number(evt.clientY);
}




0 个答案:

没有答案