whispervis/animate.go
2018-09-17 22:11:04 +03:00

28 lines
491 B
Go

package main
import (
"github.com/gopherjs/gopherjs/js"
)
func (w *WebGLScene) animate() {
if w.renderer == nil {
return
}
w.controls.Update()
js.Global.Call("requestAnimationFrame", w.animate)
if w.autoRotate {
pos := w.graph.Object.Get("rotation")
pos.Set("y", pos.Get("y").Float()+float64(0.001))
}
w.renderer.Render(w.scene, w.camera)
}
// ToggleAutoRotation switches auto rotation option.
func (w *WebGLScene) ToggleAutoRotation() {
w.autoRotate = !w.autoRotate
}