/
model.go
52 lines (43 loc) · 1.67 KB
/
model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// This is a simple model for your tests
package tests
import (
"github.com/g3n/engine/graphic"
"github.com/g3n/engine/math32"
"github.com/g3n/g3nd/app"
"github.com/g3n/g3nd/demos"
)
// Sets the category and name of your test in the demos.Map
// The category name choosen here starts with a "|" so it shows as the
// last category in list. Change "model" to the name of your test.
func init() {
demos.Map["|tests|.model"] = &testsModel{}
}
// This is your test object. You can store state here.
// By convention and to avoid conflict with other demo/tests name it
// using your test category and name.
type testsModel struct {
grid *graphic.GridHelper // Pointer to a GridHelper created in 'Initialize'
}
// This method will be called once when the test is selected from the G3ND list.
// 'a' is a pointer to the G3ND application.
// It allows access to several methods such as a.Scene(), which returns the current scene,
// a.GuiPanel(), a.Camera(), a.Window() among others.
// You can build your scene adding your objects to the a.Scene()
func (t *testsModel) Initialize(a *app.App) {
// Show axis helper
ah := graphic.NewAxisHelper(1.0)
a.Scene().Add(ah)
// Creates a grid helper and saves its pointer in the test state
t.grid = graphic.NewGridHelper(50, 1, &math32.Color{0.4, 0.4, 0.4})
a.Scene().Add(t.grid)
// Changes the camera position
a.Camera().GetCamera().SetPosition(0, 4, 10)
a.Camera().GetCamera().LookAt(&math32.Vector3{0,0,0})
}
// This method will be called at every frame
// You can animate your objects here.
func (t *testsModel) Render(a *app.App) {
// Rotate the grid, just for show.
rps := a.FrameDeltaSeconds() * 2 * math32.Pi
t.grid.RotateY(rps * 0.05)
}