diff options
author | sanine <sanine.not@pm.me> | 2023-03-19 01:17:48 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-03-19 01:17:48 -0500 |
commit | 05009088588e6171dd26c3002208e338e2c5a65a (patch) | |
tree | d3bb7afa0a7388b8a0ac2219c06e32fbd8f6e47e /main.lua | |
parent | d94d9fb122e42264eca20bb037fe8a82290bd3e2 (diff) |
add shader:configure()
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 75 |
1 files changed, 41 insertions, 34 deletions
@@ -13,7 +13,7 @@ local camera = { view=Mat4.Identity(), projection=Mat4(), } -camera.view:translate(Vec3{0, 0, -3}) +camera.view:translate(Vec3{0, 0, -60}) camera.projection:perspective(math.rad(45), 640/480, 0.1, 100) @@ -57,9 +57,13 @@ world:addSystem{ filter=ecs.Filter.AND{"mesh", "shader", "transform"}, update=function(entity, dt) entity.shader:use() - entity.shader:setMatrix('model', entity._transform) - entity.shader:setMatrix('view', camera.view) - entity.shader:setMatrix('projection', camera.projection) + entity.shader:configure{ + matrix={ + model=entity._transform, + view=camera.view, + projection=camera.projection, + }, + } entity.mesh:drawElements() end, priority=99, @@ -128,35 +132,47 @@ local dodeca = honey.mesh.loadFile("assets/dodecahedron.obj")[1] local icosa = honey.mesh.loadFile("assets/icosahedron.obj")[1] -local tetraEntity = { - parent=false, - transform=Mat4.Identity(), - mesh=tetra, - shader=shader, -} +function growLine(prev, depth) + if depth == 0 then return prev end -local cubeEntity = { - parent=tetraEntity, - transform=Mat4.Identity(), - mesh=cube, - shader=shader, -} -cubeEntity.transform:translate(Vec3{2, 0, 0}) + local entity = { + transform=Mat4.Identity(), + mesh=octa, + shader=shader, + } + entity.transform:translate(Vec3{2, 0, 0}) + prev.parent = entity + world:addEntity(prev) + return growLine(entity, depth-1) +end -local octaEntity = { - parent=cubeEntity, + +local leaf = { transform=Mat4.Identity(), - mesh=octa, + mesh=tetra, shader=shader, } -octaEntity.transform:translate(Vec3{2, 0, 0}) +local root = growLine(leaf, 24) +root.parent = false +world:addEntity(root) +function updateTransforms(dt) + local entity = leaf + while entity ~= false do + entity.transform:rotateY(0.3 * math.pi * dt) + entity.transform:rotateX(0.1 * math.pi * dt) + entity = entity.parent + end +end + -world:addEntity(tetraEntity) -world:addEntity(cubeEntity) -world:addEntity(octaEntity) +window:setKeyCallback(function(_, key) + if key == glfw.KEY_ESCAPE then + window:setShouldClose(true) + end +end) @@ -166,16 +182,7 @@ while not window:shouldClose() do local dt = time - prevTime prevTime = time - tetraEntity.transform:identity() - tetraEntity.transform:rotateY(0.5 * math.pi * time) - tetraEntity.transform:rotateX(0.05 * math.pi * time) - --model:scale(0.2 * Vec3{1, 1, 1}) - - cubeEntity.transform:identity() - cubeEntity.transform:translate(Vec3{2, 0, 0}) - cubeEntity.transform:rotateY(0.3 * math.pi * time) - cubeEntity.transform:rotateX(0.08 * math.pi * time) - + updateTransforms(dt) gl.ClearColor(0.2, 0.4, 1.0, 1.0) gl.Clear(gl.COLOR_BUFFER_BIT + gl.DEPTH_BUFFER_BIT) |