-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel.go
57 lines (48 loc) · 1.16 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
53
54
55
56
57
package wfobj
// Represent a 3D vertex
type Vertex struct {
X, Y, Z float32
}
// Check if two vertexes are the same
func (v *Vertex) Same(other *Vertex) bool {
return v.X == other.X && v.Y == other.Y && v.Z == other.Z
}
// Subtract one for another
func (v *Vertex) Sub(other *Vertex) (ret *Vertex) {
ret = &Vertex{other.X - v.X, other.Y - v.Y, other.Z - v.Z}
return
}
// Add on vector to another
func (v *Vertex) Add(other *Vertex) (ret *Vertex) {
ret = &Vertex{other.X + v.X, other.Y + v.Y, other.Z + v.Z}
return
}
// Represent a vertex list
type VertexList []Vertex
func (v VertexList) Same(other VertexList) bool {
if len(v) != len(other) {
return false
}
for i, _ := range other {
if !v[i].Same(&other[i]) {
return false
}
}
return true
}
// Represent one face of the object
// Vertices must be in the right draw order
type Face struct {
Vertices VertexList
Normals VertexList
}
// Check if two faces are equal
// ie, same vertices in the same order
func (f *Face) Same(other *Face) bool {
return f.Vertices.Same(other.Vertices)
}
// Represent a mesh made by a collection of faces/material
// TODO Implement material
type Mesh struct {
Faces []Face
}