0
点赞
收藏
分享

微信扫一扫

轻量级 IDE & 文本编辑器 Geany 发布 2.0

三次方 2023-11-01 阅读 30

Three.js设置相机lookAt无效

源代码片段:

//创建相机
const camera = new THREE.PerspectiveCamera(
    80, //视角
    widthofelement / heightofelement, //宽高比
    0.1, //近距离
    1000 //远距离
)

//相机位置,z轴为朝向自己的方向,y轴为垂直方向
camera.position.set(-7, 13, -7)
// 设置相机朝向的位置
camera.lookAt(100, 0, 100) // <----!!!此处无效!!!
const controls = new OrbitControls(camera, renderer.domElement);

//渲染函数
function animate() {
    controls.update()
    //调用animate
    requestAnimationFrame(animate) //异步函数
    //渲染
    renderer.render(scene, camera)
}

animate()

解决方法:
camera.lookAt(100, 0, 100)改为:

controls.target = new THREE.Vector3(100, 0, 100)
举报

相关推荐

0 条评论