-
Notifications
You must be signed in to change notification settings - Fork 5
/
format.go
72 lines (59 loc) · 1.37 KB
/
format.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
package vertex
import (
"encoding/gob"
"github.com/johanhenriksson/goworld/math/vec2"
"github.com/johanhenriksson/goworld/math/vec3"
"github.com/johanhenriksson/goworld/math/vec4"
"github.com/johanhenriksson/goworld/render/color"
)
func init() {
gob.Register(P{})
gob.Register(C{})
gob.Register(T{})
gob.Register(UI{})
}
// P - Position only vertex
type P struct {
vec3.T `vtx:"position,float,3"`
}
func (v P) Position() vec3.T { return v.T }
// C - Colored Vertex
type C struct {
P vec3.T `vtx:"position,float,3"`
N vec3.T `vtx:"normal,float,3"`
C vec4.T `vtx:"color_0,float,4"`
}
func (v C) Position() vec3.T { return v.P }
// T - Textured Vertex
type T struct {
P vec3.T `vtx:"position,float,3"`
N vec3.T `vtx:"normal,float,3"`
T vec2.T `vtx:"texcoord_0,float,2"`
}
func (v T) Position() vec3.T { return v.P }
type UI struct {
P vec3.T `vtx:"position,float,3"`
C color.T `vtx:"color_0,float,4"`
T vec2.T `vtx:"texcoord_0,float,2"`
}
func (v UI) Position() vec3.T { return v.P }
func Min[V Vertex](vertices []V) vec3.T {
if len(vertices) == 0 {
return vec3.Zero
}
min := vec3.InfPos
for _, v := range vertices {
min = vec3.Min(min, v.Position())
}
return min
}
func Max[V Vertex](vertices []V) vec3.T {
if len(vertices) == 0 {
return vec3.Zero
}
max := vec3.InfNeg
for _, v := range vertices {
max = vec3.Max(max, v.Position())
}
return max
}