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/main.lua | |
parent | 7dcdcc6824a515417d0e663277acf0a6b2cd1747 (diff) |
fix bug with working directory and add Vector and Matrix wrappers
Diffstat (limited to 'demo/main.lua')
-rw-r--r-- | demo/main.lua | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/demo/main.lua b/demo/main.lua index 1be7eaf..1cb63d8 100644 --- a/demo/main.lua +++ b/demo/main.lua @@ -1,27 +1,50 @@ -for k, v in pairs(honey.shader) do - print(k, v) -end +local Vec3, Vec4 = require('Vector')() +local Mat3, Mat4 = require('Matrix')() + +local m = Mat3.new{1, 0, 1, + 0, 1, 0, + 0, 0, 0} +print(Mat3.tostring(m)) honey.input.key.bind(honey.input.key.escape, honey.exit) -local vec4 = function(v) - local vector = honey.cglm.new_array_zero(4) - honey.cglm.set_value(vector, 0, v[1]) - honey.cglm.set_value(vector, 1, v[2]) - honey.cglm.set_value(vector, 2, v[3]) - honey.cglm.set_value(vector, 3, v[4]) - return vector +local basis = function(matrix) + local b = {} + b.x = Vec3.new{1, 0, 0} + b.y = Vec3.new{0, 1, 0} + b.z = Vec3.new{0, 0, 1} + + local mat3 = honey.cglm.new_array_zero(9) + honey.cglm.mat4.pick3(matrix, mat3) + + honey.cglm.mat3.mulv(b.x, mat3, b.x) + honey.cglm.mat3.mulv(b.y, mat3, b.y) + honey.cglm.mat3.mulv(b.z, mat3, b.z) + + return b end local vertex_shader = [[ #version 330 core layout(location = 0) in vec3 position; +layout(location = 1) in vec3 normal; +layout(location = 2) in vec2 tex_coord; + +out vec2 uv_coord; +out vec3 v_normal; +out vec3 v_position; + +uniform mat4 model; +uniform mat4 view; +uniform mat4 projection; void main() { - gl_Position.xyz = position - vec3(1,1,0); - gl_Position.w = 1.0; + gl_Position = projection * view * model * vec4(position.xyz, 1); + uv_coord = tex_coord; + v_normal = mat3(view) * normal; + v_position = vec3(view * model * vec4(position.xyz, 1.0)); } ]] local fragment_shader = [[ #version 330 core @@ -33,8 +56,8 @@ void main() { color = base_color; } ]] local shader = honey.shader.new(vertex_shader, fragment_shader) local plane = honey.primitives.plane(2,2) -local color1 = vec4{1,0,0,1} -local color2 = vec4{0,0,1,1} +local color1 = Vec4.new{1,0,0,1} +local color2 = Vec4.new{0,0,1,1} local color = honey.cglm.new_array_zero(4) local total_time = 0 |