WebGL基础(5)应用requestAnimationFrame

    // 渲染函数
    render (time) {
      // 物体会沿着x轴一直循环运动
      // this.cube.position.x += 0.01
      // this.cube.rotation.x += 0.1
       
      let t = (time / 1000) % 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:15  yulingjia  阅读(81)  评论(0编辑  收藏  举报