summaryrefslogtreecommitdiff
path: root/demo/Vector.lua
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-10-27 20:58:46 -0500
committersanine-a <sanine.not@pm.me>2020-10-27 20:58:46 -0500
commitc3698446644365283fcd3d3f47f3eea67cad8331 (patch)
tree4ad91fc176600f21a0bc298012635178a75d92d9 /demo/Vector.lua
parent7dcdcc6824a515417d0e663277acf0a6b2cd1747 (diff)
fix bug with working directory and add Vector and Matrix wrappers
Diffstat (limited to 'demo/Vector.lua')
-rw-r--r--demo/Vector.lua60
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
+