【发布时间】:2022-01-18 22:33:11
【问题描述】:
我正在使用 Three.js,但我遇到了问题, 我关注了这个视频 fhttps://www.youtube.com/watch?v=pUgWfqWZWmM,我的问题从 48 分钟开始。 我在 x、y 和 z 轴上移动的 mousemove 事件不起作用。I found this error message 对不起我的英语不好。希望你们能帮帮我
document.addEventListener('mousmeove', onDocumentMouseMove)
let mouseX = 0;
let mouseY = 0;
let targetX = 0;
let targetY = 0;
const windowX = window.innerWidth / 2;
const windowY = window.innerHeight / 2;
function onDocumentMouseMove(event) {
mouseX = (event.clientX - windowX)
mouseY = (event.clientY - windowY)
}
const updateSphere = (event) => {
sphere.position.y = window.scrollY * .001
}
window.addEventListener('scroll', updateSphere)
const clock = new THREE.Clock()
const tick = () =>
{
targetX = mouseX * .001
targetY = mouseY * .001
const elapsedTime = clock.getElapsedTime()
// Update objects
sphere.rotation.y = .5 * elapsedTime
sphere.rotation.y += .5 * (targetX - sphere.rotation.y)
sphere.rotation.x += .5 * (targetY - sphere.rotation.x)
sphere.position.z += .5 * (targetY - sphere.rotation.x)
// Update Orbital Controls
// controls.update()
// Render
renderer.render(scene, camera)
// Call tick again on the next frame
window.requestAnimationFrame(tick)
}
tick()
【问题讨论】:
标签: javascript three.js 3d