diff tests/test_collision.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 f054b8bacab8
children 74957cbf589b
line wrap: on
line diff
--- a/tests/test_collision.nim	Wed May 08 15:46:47 2024 +0700
+++ b/tests/test_collision.nim	Thu May 09 23:02:35 2024 +0700
@@ -3,9 +3,9 @@
 proc main() =
   var scene = Scene(name: "main")
 
-  scene.add rect(color="f00f")
+  scene.add rect(color = "f00f")
   scene.add rect()
-  scene.add circle(color="0f0f")
+  scene.add circle(color = "0f0f")
   scene.meshes[0].material = VERTEX_COLORED_MATERIAL.initMaterialData()
   scene.meshes[1].material = VERTEX_COLORED_MATERIAL.initMaterialData()
   scene.meshes[2].material = VERTEX_COLORED_MATERIAL.initMaterialData()
@@ -15,16 +15,17 @@
 
   const
     shaderConfiguration = createShaderConfiguration(
-      inputs=[
-        attr[Mat4]("transform", memoryPerformanceHint=PreferFastRead, perInstance=true),
-        attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead),
-        attr[Vec4f]("color", memoryPerformanceHint=PreferFastRead),
+      name = "default shader",
+      inputs = [
+        attr[Mat4]("transform", memoryPerformanceHint = PreferFastRead, perInstance = true),
+        attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead),
+        attr[Vec4f]("color", memoryPerformanceHint = PreferFastRead),
       ],
-      intermediates=[attr[Vec4f]("colorout")],
-      uniforms=[attr[Mat4]("perspective")],
-      outputs=[attr[Vec4f]("fragcolor")],
-      vertexCode="""gl_Position = vec4(position, 1.0) * (transform * Uniforms.perspective); colorout = color;""",
-      fragmentCode="""fragcolor = colorout;""",
+      intermediates = [attr[Vec4f]("colorout")],
+      uniforms = [attr[Mat4]("perspective")],
+      outputs = [attr[Vec4f]("fragcolor")],
+      vertexCode = """gl_Position = vec4(position, 1.0) * (transform * Uniforms.perspective); colorout = color;""",
+      fragmentCode = """fragcolor = colorout;""",
     )
 
   var engine = initEngine("Test collisions")
@@ -32,21 +33,21 @@
   engine.initRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration})
   engine.loadScene(scene)
 
-  while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
-    if engine.windowWasResized():
+  while engine.updateInputs() and not keyIsDown(Escape):
+    if windowWasResized():
       var winSize = engine.getWindow().size
-      scene.setShaderGlobal("perspective", orthoWindowAspect(winSize[1] / winSize[0]))
-    if engine.keyIsDown(A): scene.meshes[0].transform = scene.meshes[0].transform * translate(-0.001,      0, 0)
-    if engine.keyIsDown(D): scene.meshes[0].transform = scene.meshes[0].transform * translate( 0.001,      0, 0)
-    if engine.keyIsDown(W): scene.meshes[0].transform = scene.meshes[0].transform * translate(     0, -0.001, 0)
-    if engine.keyIsDown(S): scene.meshes[0].transform = scene.meshes[0].transform * translate(     0,  0.001, 0)
-    if engine.keyIsDown(Q): scene.meshes[0].transform = scene.meshes[0].transform * rotate(-0.001, Z)
-    if engine.keyIsDown(Key.E): scene.meshes[0].transform = scene.meshes[0].transform * rotate( 0.001, Z)
+      scene.setShaderGlobal("perspective", orthoWindowAspect(winSize[0] / winSize[1]))
+    if keyIsDown(A): scene.meshes[0].transform = scene.meshes[0].transform * translate(-0.001, 0, 0)
+    if keyIsDown(D): scene.meshes[0].transform = scene.meshes[0].transform * translate(0.001, 0, 0)
+    if keyIsDown(W): scene.meshes[0].transform = scene.meshes[0].transform * translate(0, -0.001, 0)
+    if keyIsDown(S): scene.meshes[0].transform = scene.meshes[0].transform * translate(0, 0.001, 0)
+    if keyIsDown(Q): scene.meshes[0].transform = scene.meshes[0].transform * rotate(-0.001, Z)
+    if keyIsDown(Key.E): scene.meshes[0].transform = scene.meshes[0].transform * rotate(0.001, Z)
 
-    if engine.keyIsDown(Key.Z): scene.meshes[1].transform = scene.meshes[1].transform * rotate(-0.001, Z)
-    if engine.keyIsDown(Key.X): scene.meshes[1].transform = scene.meshes[1].transform * rotate( 0.001, Z)
-    if engine.keyIsDown(Key.C): scene.meshes[1].transform = scene.meshes[1].transform * translate(0, -0.001, 0)
-    if engine.keyIsDown(Key.V): scene.meshes[1].transform = scene.meshes[1].transform * translate(0,  0.001, 0)
+    if keyIsDown(Key.Z): scene.meshes[1].transform = scene.meshes[1].transform * rotate(-0.001, Z)
+    if keyIsDown(Key.X): scene.meshes[1].transform = scene.meshes[1].transform * rotate(0.001, Z)
+    if keyIsDown(Key.C): scene.meshes[1].transform = scene.meshes[1].transform * translate(0, -0.001, 0)
+    if keyIsDown(Key.V): scene.meshes[1].transform = scene.meshes[1].transform * translate(0, 0.001, 0)
     let hitbox = Collider(theType: Box, transform: scene.meshes[0].transform * translate(-0.5, -0.5))
     let hitsphere = Collider(theType: Sphere, transform: scene.meshes[2].transform, radius: 0.5)
     echo intersects(hitbox, hitsphere)