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 )
}
浙公网安备 33010602011771号