diff options
author | sanine-a <sanine.not@pm.me> | 2020-10-27 20:58:46 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2020-10-27 20:58:46 -0500 |
commit | c3698446644365283fcd3d3f47f3eea67cad8331 (patch) | |
tree | 4ad91fc176600f21a0bc298012635178a75d92d9 /demo/Vector.lua | |
parent | 7dcdcc6824a515417d0e663277acf0a6b2cd1747 (diff) |
fix bug with working directory and add Vector and Matrix wrappers
Diffstat (limited to 'demo/Vector.lua')
-rw-r--r-- | demo/Vector.lua | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/demo/Vector.lua b/demo/Vector.lua new file mode 100644 index 0000000..752c927 --- /dev/null +++ b/demo/Vector.lua @@ -0,0 +1,60 @@ +local Vec3 = {} + +Vec3.tostring = function(vec3) + local str = '['.. + tostring(honey.cglm.get_value(vec4, 0))..','.. + tostring(honey.cglm.get_value(vec4, 1))..','.. + tostring(honey.cglm.get_value(vec4, 2))..']' + return str +end + +Vec3.new = function(tbl) + if tbl == nil then + return honey.cglm.new_array_zero(3) + end + + if #tbl ~= 3 then + error('3-vectors require exactly three elements!') + end + + local vec3 = honey.cglm.new_array_zero(3) + for i = 0,2 do + honey.cglm.set_value(data, i, tbl[i+1]) + end + + return vec3 +end + +-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +local Vec4 = {} + +Vec4.tostring = function(vec4) + local str = '['.. + tostring(honey.cglm.get_value(vec4, 0))..','.. + tostring(honey.cglm.get_value(vec4, 1))..','.. + tostring(honey.cglm.get_value(vec4, 2))..','.. + tostring(honey.cglm.get_value(vec4, 3))..']' + return str +end + +Vec4.new = function(tbl) + if tbl == nil then + return honey.cglm.new_array_zero(4) + end + + if #tbl ~= 4 then + error('4-vectors require exactly four elements!') + end + + local vec4 = honey.cglm.new_array_zero(4) + for i = 0,3 do + honey.cglm.set_value(vec4, i, tbl[i+1]) + end + + return vec4 +end + + +return function() return Vec3, Vec4 end + |