-
Notifications
You must be signed in to change notification settings - Fork 0
/
Geometry.t
87 lines (81 loc) · 2.8 KB
/
Geometry.t
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
local std = require "util/std"
require "lib/gl"
local math = require "util/math"
local glm = require "util/glm"
local Vertex = require "Vertex"
local struct Geometry(std.Object) {
uuid: math.UUID
verts: std.Vector(Vertex)
indices: std.Vector(uint)
}
terra Geometry.methods.create()
var self = Geometry {
uuid = math.generateUUID();
}
self.verts:init()
self.indices:init()
return self
end
terra Geometry:transform(matrix: glm.mat3)
var i = self.verts:start()
while i ~= self.verts:stop() do
i:get().position = matrix * i:get().position
i:inc()
end
end
terra Geometry:transform(matrix: glm.mat4)
var i = self.verts:start()
while i ~= self.verts:stop() do
i:get().position = matrix * i:get().position
i:inc()
end
end
terra Geometry.methods.squareGeom()
var self = Geometry.create()
self.verts:assign(
array(
Vertex {
position=arrayof(float, 0.0, 0.0, 0.0);
texCoords=arrayof(float, 0.0, 0.0);
},
Vertex {
position=arrayof(float, 1.0, 0.0, 0.0);
texCoords=arrayof(float, 1.0, 0.0);
},
Vertex {
position=arrayof(float, 1.0, 1.0, 0.0);
texCoords=arrayof(float, 1.0, 1.0);
},
Vertex {
position=arrayof(float, 0.0, 1.0, 0.0);
texCoords=arrayof(float, 0.0, 1.0);
}
)
)
self.indices:assign(arrayof(uint, 0, 1, 3, 1, 2, 3))
return self
end
terra Geometry.methods.cubeGeom()
var self = Geometry.create()
self.verts:assign(arrayof(Vertex,
Vertex {arrayof(float, 0.0, 0.0, 0.0)},
Vertex {arrayof(float, 0.0, 0.0, 1.0)},
Vertex {arrayof(float, 0.0, 1.0, 0.0)},
Vertex {arrayof(float, 0.0, 1.0, 1.0)},
Vertex {arrayof(float, 1.0, 0.0, 0.0)},
Vertex {arrayof(float, 1.0, 0.0, 1.0)},
Vertex {arrayof(float, 1.0, 1.0, 0.0)},
Vertex {arrayof(float, 1.0, 1.0, 1.0)}
))
self.indices:assign(arrayof(uint,
0, 4, 2, 4, 6, 2,
0, 1, 2, 1, 2, 3,
0, 1, 4, 1, 4, 5
))
-- self.indices:assign(arrayof(uint, 0, 4, 2, 4, 6, 2))
-- self.indices:assign(arrayof(uint,
-- 0,3,1,0,2,3
-- ))
return self
end
return Geometry