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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
local Enum = require('Enum')
local Vector = {}
Vector.type = Enum{'Vec3', 'Vec4'}
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- Vec3
--
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Vector.Vec3 = {}
Vector.Vec3.prototype = {}
Vector.Vec3.prototype.type = Vector.type.Vec3
Vector.Vec3.prototype.at = function(self, index)
return honey.cglm.get_value(self.array, index)
end
Vector.Vec3.prototype.setAt = function(self, index, value)
honey.cglm.set_value(self.array, index, value)
end
Vector.Vec3.prototype.dot = function(self, v, dest)
local result
if dest == nil then
result = Vector.Vec3.new()
else
result = dest
end
honey.cglm.vec3.dot(self.array, v.array, result.array)
return result
end
Vector.Vec3.prototype.norm2 = function(self)
return honey.cglm.vec3.norm2(self.array)
end
Vector.Vec3.prototype.norm = function(self)
return honey.cglm.vec3.norm(self.array)
end
Vector.Vec3.prototype.add = function(self, v, dest)
local result
if dest == nil then
result = Vector.Vec3.new()
else
result = dest
end
honey.cglm.vec3.add(self.array, v.array, result.array)
return result
end
Vector.Vec3.prototype.adds = function(self, s, dest)
local result
if dest == nil then
result = Vector.Vec3.new()
else
result = dest
end
honey.cglm.vec3.adds(s, self.array, result.array)
return result
end
Vector.Vec3.prototype.sub = function(self, v, dest)
local result
if dest == nil then
result = Vector.Vec3.new()
else
result = dest
end
honey.cglm.vec3.sub(self.array, v.array, result.array)
return result
end
Vector.Vec3.prototype.mul = function(self, v, dest)
local result
if dest == nil then
result = Vector.Vec3.new()
else
result = dest
end
honey.cglm.vec3.mul(self.array, v.array, result.array)
return result
end
Vector.Vec3.prototype.muls = function(self, s, dest)
local result
if dest == nil then
result = Vector.Vec3.new()
else
result = dest
end
honey.cglm.vec3.muls(s, self.array, result.array)
return result
end
Vector.Vec3.prototype.normalize = function(self)
honey.cglm.vec3.normalize(self.array)
end
Vector.Vec3.prototype.distanceTo = function(self, v)
return honey.cglm.vec3.distance(self.array, v.array)
end
Vector.Vec3.prototype.lerp = function(self, v, s, dest)
local result
if dest == nil then
result = Vector.Vec3.new()
else
result = dest
end
honey.cglm.vec3.lerp(self.array, v.array, s, result.array)
return result
end
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Vector.Vec3.mt = {}
Vector.Vec3.mt.__index = Vector.Vec3.prototype
Vector.Vec3.mt.__tostring = function(vec3)
local str = 'vec3('..
tostring(vec3:at(0))..', '..
tostring(vec3:at(1))..', '..
tostring(vec3:at(2))..')'
return str
end
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Vector.Vec3.new = function(tbl)
local vec3 = {}
vec3.array = honey.cglm.new_array_zero(3)
setmetatable(vec3, Vector.Vec3.mt)
if tbl == nil then return vec3 end
for i=0,2 do
vec3:setAt(i, tbl[i+1])
end
return vec3
end
Vector.Vec3.ZERO = Vector.Vec3.new()
Vector.Vec3.X_UNIT = Vector.Vec3.new{1, 0, 0}
Vector.Vec3.Y_UNIT = Vector.Vec3.new{0, 1, 0}
Vector.Vec3.Z_UNIT = Vector.Vec3.new{0, 0, 1}
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
-- Vec4
--
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Vector.Vec4 = {}
Vector.Vec4.prototype = {}
Vector.Vec4.prototype.type = Vector.type.Vec4
Vector.Vec4.prototype.at = function(self, index)
return honey.cglm.get_value(self.array, index)
end
Vector.Vec4.prototype.setAt = function(self, index, value)
honey.cglm.set_value(self.array, index, value)
end
Vector.Vec4.prototype.dot = function(self, v, dest)
local result
if dest == nil then
result = Vector.Vec4.new()
else
result = dest
end
honey.cglm.vec4.dot(self.array, v.array, result.array)
return result
end
Vector.Vec4.prototype.norm2 = function(self)
return honey.cglm.vec4.norm2(self.array)
end
Vector.Vec4.prototype.norm = function(self)
return honey.cglm.vec4.norm(self.array)
end
Vector.Vec4.prototype.add = function(self, v, dest)
local result
if dest == nil then
result = Vector.Vec4.new()
else
result = dest
end
honey.cglm.vec4.add(self.array, v.array, result.array)
return result
end
Vector.Vec4.prototype.adds = function(self, s, dest)
local result
if dest == nil then
result = Vector.Vec4.new()
else
result = dest
end
honey.cglm.vec4.adds(s, self.array, result.array)
return result
end
Vector.Vec4.prototype.sub = function(self, v, dest)
local result
if dest == nil then
result = Vector.Vec4.new()
else
result = dest
end
honey.cglm.vec4.sub(self.array, v.array, result.array)
return result
end
Vector.Vec4.prototype.mul = function(self, v, dest)
local result
if dest == nil then
result = Vector.Vec4.new()
else
result = dest
end
honey.cglm.vec4.mul(self.array, v.array, result.array)
return result
end
Vector.Vec4.prototype.muls = function(self, s, dest)
local result
if dest == nil then
result = Vector.Vec4.new()
else
result = dest
end
honey.cglm.vec4.muls(s, self.array, result.array)
return result
end
Vector.Vec4.prototype.normalize = function(self)
honey.cglm.vec4.normalize(self.array)
end
Vector.Vec4.prototype.distanceTo = function(self, v)
return honey.cglm.vec4.distance(self.array, v.array)
end
Vector.Vec4.prototype.lerp = function(self, v, s, dest)
local result
if dest == nil then
result = Vector.Vec4.new()
else
result = dest
end
honey.cglm.vec4.lerp(self.array, v.array, s, result.array)
return result
end
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Vector.Vec4.mt = {}
Vector.Vec4.mt.__index = Vector.Vec4.prototype
Vector.Vec4.mt.__tostring = function(vec4)
local str = 'vec4('..
tostring(vec4:at(0))..', '..
tostring(vec4:at(1))..', '..
tostring(vec4:at(2))..', '..
tostring(vec4:at(3))..')'
return str
end
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Vector.Vec4.new = function(tbl)
local vec4 = {}
vec4.array = honey.cglm.new_array_zero(4)
setmetatable(vec4, Vector.Vec4.mt)
if tbl == nil then return vec4 end
for i=0,3 do
vec4:setAt(i, tbl[i+1])
end
return vec4
end
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
return Vector
|