-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene.go
98 lines (84 loc) · 1.84 KB
/
scene.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
package opengl
import (
"errors"
"fmt"
"time"
uuid "github.com/satori/go.uuid"
)
type scene struct {
worldCameras map[string]WorldCamera
id *uuid.UUID
index uint
hud Hud
nodes []Node
}
func createScene(
worldCameras map[string]WorldCamera,
id *uuid.UUID,
index uint,
hud Hud,
nodes []Node,
) Scene {
return createSceneInternally(worldCameras, id, index, hud, nodes)
}
func createSceneInternally(
worldCameras map[string]WorldCamera,
id *uuid.UUID,
index uint,
hud Hud,
nodes []Node,
) Scene {
out := scene{
worldCameras: worldCameras,
id: id,
index: index,
hud: hud,
nodes: nodes,
}
return &out
}
// ID returns the id
func (obj *scene) ID() *uuid.UUID {
return obj.id
}
// Index returns the index
func (obj *scene) Index() uint {
return obj.index
}
// Hud returns the hud
func (obj *scene) Hud() Hud {
return obj.hud
}
// HasNodes returns true if there is nodes, false otherwise
func (obj *scene) HasNodes() bool {
return obj.nodes != nil
}
// Nodes returns the nodes, if any
func (obj *scene) Nodes() []Node {
return obj.nodes
}
// Render renders a scene
func (obj *scene) Render(
delta time.Duration,
activeCameraID *uuid.UUID,
) error {
// retrieve the active camera:
keyname := activeCameraID.String()
if activeCamera, ok := obj.worldCameras[keyname]; ok {
// render the nodes, if any:
if obj.HasNodes() {
for _, oneNode := range obj.nodes {
err := oneNode.Render(delta, activeCamera, obj)
if err != nil {
return err
}
}
}
// render the heads-up display:
//pos := activeCamera.Position()
//orientation := activeCamera.Orientation()
return obj.hud.Render(delta, obj)
}
str := fmt.Sprintf("the given active Camera (ID: %s) does not exists in the current Scene (ID: %s)", keyname, obj.ID().String())
return errors.New(str)
}