-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.go
112 lines (78 loc) · 2.06 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
_ "embed"
"github.com/solarlune/tetra3d"
"github.com/solarlune/tetra3d/colors"
"github.com/solarlune/tetra3d/examples"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
type Game struct {
Scene *tetra3d.Scene
Library *tetra3d.Library
Camera examples.BasicFreeCam
System examples.BasicSystemHandler
}
//go:embed worlds.gltf
var sceneData []byte
func NewGame() *Game {
game := &Game{}
game.Init()
return game
}
func (g *Game) Init() {
library, err := tetra3d.LoadGLTFData(sceneData, nil)
if err != nil {
panic(err)
}
g.Library = library
g.Scene = library.ExportedScene.Clone()
g.Camera = examples.NewBasicFreeCam(g.Scene)
g.Camera.SetFar(30)
g.Camera.SetLocalPosition(0, 5, 5)
g.System = examples.NewBasicSystemHandler(g)
}
func (g *Game) Update() error {
if inpututil.IsKeyJustPressed(ebiten.Key1) {
g.Scene.World = g.Library.Worlds["Dark"]
}
if inpututil.IsKeyJustPressed(ebiten.Key2) {
g.Scene.World = g.Library.Worlds["Bright"]
}
if inpututil.IsKeyJustPressed(ebiten.Key3) {
g.Scene.World = g.Library.Worlds["Blue"]
}
if inpututil.IsKeyJustPressed(ebiten.Key4) {
g.Scene.World = g.Library.Worlds["Red"]
}
g.Camera.Update()
return g.System.Update()
}
func (g *Game) Draw(screen *ebiten.Image) {
// Clear, but with a color
screen.Fill(g.Scene.World.ClearColor.ToRGBA64())
// Clear the Camera
g.Camera.Clear()
// Render the scene first
g.Camera.RenderScene(g.Scene)
// Draw the result
screen.DrawImage(g.Camera.ColorTexture(), nil)
g.System.Draw(screen, g.Camera.Camera)
if g.System.DrawDebugText {
txt := `1-4 Keys: Cycle Worlds
Each World can have its own clear color,
fog color and range, and ambient color.`
g.Camera.DebugDrawText(screen, txt, 0, 200, 1, colors.White())
}
}
func (g *Game) Layout(w, h int) (int, int) {
return g.Camera.Size()
}
func main() {
ebiten.SetWindowTitle("Tetra3d - Worlds Test")
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
game := NewGame()
if err := ebiten.RunGame(game); err != nil {
panic(err)
}
}