diff options
author | sanine <sanine.not@pm.me> | 2022-08-23 22:16:24 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-08-23 22:16:24 -0500 |
commit | 709e1b6e1ce86f8da4fc136747fcefbc6c6057bd (patch) | |
tree | 8f4da8c27526fb056a340a9d2948fdace8341ece /demo | |
parent | 3afbf2a13b2dada445fb667bf25600407fea480a (diff) |
add basic 3d perspective
Diffstat (limited to 'demo')
-rw-r--r-- | demo/.honey.lua.swo | bin | 0 -> 20480 bytes | |||
-rw-r--r-- | demo/honey.lua | 42 |
2 files changed, 35 insertions, 7 deletions
diff --git a/demo/.honey.lua.swo b/demo/.honey.lua.swo Binary files differnew file mode 100644 index 0000000..73c5d1d --- /dev/null +++ b/demo/.honey.lua.swo diff --git a/demo/honey.lua b/demo/honey.lua index 822877f..9d007e5 100644 --- a/demo/honey.lua +++ b/demo/honey.lua @@ -30,14 +30,17 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aColor; layout (location = 2) in vec2 aTexCoord; -uniform mat4 transform; +uniform mat4 model; +uniform mat4 view; +uniform mat4 projection; + out vec3 ourColor; out vec2 TexCoord; void main() { - gl_Position = transform * vec4(aPos, 1.0); + gl_Position = projection * view * model * vec4(aPos, 1.0); ourColor = aColor; TexCoord = aTexCoord; } @@ -144,6 +147,28 @@ gl.UseProgram(shader) gl.Uniform1i(gl.GetUniformLocation(shader, 'ourTexture'), 0) +--====== matrices ======-- + +local model = honey.glm.mat4() +honey.glm.mat4_identity(model) +local axis = honey.glm.vec3() +honey.glm.vec3_set(axis, 0, 1.0) +honey.glm.vec3_set(axis, 1, 0.0) +honey.glm.vec3_set(axis, 2, 0.0) +honey.glm.rotate(model, math.rad(-55), axis) + +local view = honey.glm.mat4() +honey.glm.mat4_identity(view) +local translation = honey.glm.vec3() +honey.glm.vec3_set(translation, 0, 0.0) +honey.glm.vec3_set(translation, 1, 0.0) +honey.glm.vec3_set(translation, 2, -3.0) +honey.glm.translate(view, translation) + +local projection = honey.glm.mat4() +honey.glm.perspective(math.rad(45), 800/600, 0.1, 100, projection) + + --====== main loop ======-- local transform = honey.glm.mat4() @@ -156,11 +181,14 @@ while not window.shouldClose(w) do gl.BindTexture(gl.TEXTURE_2D, texture) gl.UseProgram(shader) - honey.glm.mat4_identity(transform) - local time = window.getTime() - honey.glm.rotate_z(transform, time, transform) - local transformLocation = gl.GetUniformLocation(shader, 'transform') - gl.UniformMatrix4fv(transformLocation, false, transform) + + local modelL = gl.GetUniformLocation(shader, 'model') + local viewL = gl.GetUniformLocation(shader, 'view') + local projectionL = gl.GetUniformLocation(shader, 'projection') + + gl.UniformMatrix4fv(modelL, false, model) + gl.UniformMatrix4fv(viewL, false, view) + gl.UniformMatrix4fv(projectionL, false, projection) gl.BindVertexArray(vertexArray) gl.DrawElements(gl.TRIANGLES, 6, gl.UNSIGNED_INT, 0) |