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
|
local Mat3 = {}
Mat3.tostring = function(mat)
local str = '[ ['..
tostring(honey.cglm.get_value(mat, 0))..', '..
tostring(honey.cglm.get_value(mat, 1))..', '..
tostring(honey.cglm.get_value(mat, 2))..']\n ['..
tostring(honey.cglm.get_value(mat, 3))..', '..
tostring(honey.cglm.get_value(mat, 4))..', '..
tostring(honey.cglm.get_value(mat, 5))..']\n ['..
tostring(honey.cglm.get_value(mat, 6))..', '..
tostring(honey.cglm.get_value(mat, 7))..', '..
tostring(honey.cglm.get_value(mat, 8))..'] ]'
return str
end
Mat3.new = function(tbl)
if tbl == nil then
return honey.cglm.new_array_zero(9)
end
if #tbl ~= 9 then
error('3x3 matrices require exactly nine elements!')
end
local mat3 = honey.cglm.new_array_zero(9)
for i = 0,8 do
honey.cglm.set_value(mat3, i, tbl[i+1])
end
return mat3
end
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local Mat4 = {}
Mat4.tostring = function(mat)
local str = '[ ['..
tostring(honey.cglm.get_value(mat, 0))..', '..
tostring(honey.cglm.get_value(mat, 1))..', '..
tostring(honey.cglm.get_value(mat, 2))..', '..
tostring(honey.cglm.get_value(mat, 3))..']\n ['..
tostring(honey.cglm.get_value(mat, 4))..', '..
tostring(honey.cglm.get_value(mat, 5))..', '..
tostring(honey.cglm.get_value(mat, 6))..', '..
tostring(honey.cglm.get_value(mat, 7))..']\n ['..
tostring(honey.cglm.get_value(mat, 8))..', '..
tostring(honey.cglm.get_value(mat, 9))..', '..
tostring(honey.cglm.get_value(mat, 10))..', '..
tostring(honey.cglm.get_value(mat, 11))..']\n ['..
tostring(honey.cglm.get_value(mat, 12))..', '..
tostring(honey.cglm.get_value(mat, 13))..', '..
tostring(honey.cglm.get_value(mat, 14))..', '..
tostring(honey.cglm.get_value(mat, 15))..'] ]'
return str
end
Mat4.new = function(tbl)
if tbl == nil then
return honey.cglm.new_array_zero(16)
end
if #tbl ~= 16 then
error('4x4 matrices require exactly 16 elements!')
end
local mat4 = honey.cglm.new_array_zero(16)
for i = 0,15 do
honey.cglm.set_value(mat4, i, tbl[i+1])
end
return mat4
end
return function() return Mat3, Mat4 end
|