2018-09-05 16:53:09 +03:00
|
|
|
package main
|
|
|
|
|
2018-09-17 22:11:04 +03:00
|
|
|
import (
|
|
|
|
"github.com/gopherjs/gopherjs/js"
|
|
|
|
)
|
2018-09-05 16:53:09 +03:00
|
|
|
|
2018-09-17 22:11:04 +03:00
|
|
|
func (w *WebGLScene) animate() {
|
|
|
|
if w.renderer == nil {
|
2018-09-05 16:53:09 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-09-17 22:11:04 +03:00
|
|
|
w.controls.Update()
|
2018-09-05 16:53:09 +03:00
|
|
|
|
2018-09-17 22:11:04 +03:00
|
|
|
js.Global.Call("requestAnimationFrame", w.animate)
|
2018-09-05 16:53:09 +03:00
|
|
|
|
2018-09-17 22:11:04 +03:00
|
|
|
if w.autoRotate {
|
|
|
|
pos := w.graph.Object.Get("rotation")
|
|
|
|
pos.Set("y", pos.Get("y").Float()+float64(0.001))
|
2018-09-05 16:53:09 +03:00
|
|
|
}
|
|
|
|
|
2018-09-17 22:11:04 +03:00
|
|
|
w.renderer.Render(w.scene, w.camera)
|
2018-09-05 16:53:09 +03:00
|
|
|
}
|
|
|
|
|
2018-09-17 22:11:04 +03:00
|
|
|
// ToggleAutoRotation switches auto rotation option.
|
|
|
|
func (w *WebGLScene) ToggleAutoRotation() {
|
|
|
|
w.autoRotate = !w.autoRotate
|
2018-09-05 16:53:09 +03:00
|
|
|
}
|