Mercurial > games > semicongine
diff tests/test_mesh.nim @ 1021:73b572f82a1f
add: bases for a better input-system
author | sam <sam@basx.dev> |
---|---|
date | Thu, 09 May 2024 23:02:35 +0700 |
parents | 6406766a222d |
children | 74957cbf589b |
line wrap: on
line diff
--- a/tests/test_mesh.nim Wed May 08 15:46:47 2024 +0700 +++ b/tests/test_mesh.nim Thu May 09 23:02:35 2024 +0700 @@ -1,14 +1,25 @@ import std/strformat import semicongine +const + MeshMaterial* = MaterialType( + name: "colored single texture material", + vertexAttributes: { + "position": Vec3F32, + "texcoord_0": Vec2F32, + }.toTable, + attributes: {"baseTexture": TextureType, "color": Vec4F32}.toTable + ) + proc main() = var scenes = [ - Scene(name: "Donut", meshes: loadMeshes("donut.glb", COLORED_SINGLE_TEXTURE_MATERIAL)[0].toSeq), + Scene(name: "Donut", meshes: loadMeshes("donut.glb", MeshMaterial)[0].toSeq), ] var engine = initEngine("Test meshes") const shaderConfiguration = createShaderConfiguration( + name = "default shader", inputs = [ attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), attr[uint16](MATERIALINDEX_ATTRIBUTE, memoryPerformanceHint = PreferFastRead, perInstance = true), @@ -28,14 +39,14 @@ ], samplers = [attr[Texture]("baseTexture", arrayCount = 4)], vertexCode = &""" - gl_Position = vec4(position, 1.0) * (transform * Uniforms.view * Uniforms.projection); + gl_Position = vec4(position, 1.0) * (transform * (Uniforms.view * Uniforms.projection)); vertexColor = Uniforms.color[{MATERIALINDEX_ATTRIBUTE}]; colorTexCoord = texcoord_0; materialIndexOut = {MATERIALINDEX_ATTRIBUTE}; """, fragmentCode = "color = texture(baseTexture[materialIndexOut], colorTexCoord) * vertexColor;" ) - engine.initRenderer({COLORED_SINGLE_TEXTURE_MATERIAL: shaderConfiguration}) + engine.initRenderer({MeshMaterial: shaderConfiguration}) for scene in scenes.mitems: scene.addShaderGlobal("projection", Unit4F32) @@ -48,30 +59,30 @@ azimut = 0'f32 currentScene = 0 - while engine.updateInputs() == Running and not engine.keyIsDown(Escape): - if engine.keyWasPressed(`1`): + while engine.updateInputs() and not keyIsDown(Escape): + if keyWasPressed(`1`): currentScene = 0 - elif engine.keyWasPressed(`2`): + elif keyWasPressed(`2`): currentScene = 1 - elif engine.keyWasPressed(`3`): + elif keyWasPressed(`3`): currentScene = 2 - elif engine.keyWasPressed(`4`): + elif keyWasPressed(`4`): currentScene = 3 - elif engine.keyWasPressed(`5`): + elif keyWasPressed(`5`): currentScene = 4 - elif engine.keyWasPressed(`6`): + elif keyWasPressed(`6`): currentScene = 5 - if engine.keyWasPressed(NumberRowExtra3): + if keyWasPressed(NumberRowExtra3): size = 0.3'f32 elevation = 0'f32 azimut = 0'f32 let ratio = engine.getWindow().size[0] / engine.getWindow().size[1] - size *= 1'f32 + engine.mouseWheel() * 0.05 - azimut += engine.mouseMove().x / 180'f32 - elevation -= engine.mouseMove().y / 180'f32 - scenes[currentScene].setShaderGlobal("projection", ortho(-ratio, ratio, -1, 1, -1, 1)) + size *= 1'f32 + mouseWheel() * 0.05 + azimut += mouseMove().x / 180'f32 + elevation -= mouseMove().y / 180'f32 + scenes[currentScene].setShaderGlobal("projection", perspective(PI / 2, ratio, -0.5, 1)) scenes[currentScene].setShaderGlobal( "view", scale(size, size, size) * rotate(elevation, newVec3f(1, 0, 0)) * rotate(azimut, Yf32)