WebGL基础(6)通过Clock跟踪时间处理动画

    // init方法最后面 
   // 设置时钟 this.clock = new THREE.Clock() this.render() // 渲染函数 render () { // 物体会沿着x轴一直循环运动 // this.cube.position.x += 0.01 // this.cube.rotation.x += 0.1 let time = this.clock.getElapsedTime() // let delaTime = this.clock.getDelta() // 两次获取时间的间隔时间 let t = time % 5 this.cube.position.x = t * 1 this.cube.rotation.x = t * 1 if (this.cube.position.x > 5) { this.cube.position.x = 0 } this.renderer.render( this.scene, this.camera ) // 渲染下一帧的时候就会调用render函数 requestAnimationFrame( this.render ) }

  

posted @ 2022-08-01 16:26  yulingjia  阅读(121)  评论(0编辑  收藏  举报