Mercurial > games > semicongine
annotate 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 |
| rev | line source |
|---|---|
| 277 | 1 import semicongine |
| 2 | |
| 3 proc main() = | |
|
329
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
4 var scene = Scene(name: "main") |
| 277 | 5 |
| 1021 | 6 scene.add rect(color = "f00f") |
|
331
05fb85ba97dd
did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents:
329
diff
changeset
|
7 scene.add rect() |
| 1021 | 8 scene.add circle(color = "0f0f") |
|
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
352
diff
changeset
|
9 scene.meshes[0].material = VERTEX_COLORED_MATERIAL.initMaterialData() |
|
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
352
diff
changeset
|
10 scene.meshes[1].material = VERTEX_COLORED_MATERIAL.initMaterialData() |
|
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
352
diff
changeset
|
11 scene.meshes[2].material = VERTEX_COLORED_MATERIAL.initMaterialData() |
|
329
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
12 scene.meshes[1].transform = scale(0.8, 0.8) |
|
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
13 scene.meshes[2].transform = scale(0.1, 0.1) |
|
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
14 scene.addShaderGlobal("perspective", Unit4F32) |
| 277 | 15 |
| 16 const | |
|
329
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
17 shaderConfiguration = createShaderConfiguration( |
| 1021 | 18 name = "default shader", |
| 19 inputs = [ | |
| 20 attr[Mat4]("transform", memoryPerformanceHint = PreferFastRead, perInstance = true), | |
| 21 attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), | |
| 22 attr[Vec4f]("color", memoryPerformanceHint = PreferFastRead), | |
|
329
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
23 ], |
| 1021 | 24 intermediates = [attr[Vec4f]("colorout")], |
| 25 uniforms = [attr[Mat4]("perspective")], | |
| 26 outputs = [attr[Vec4f]("fragcolor")], | |
| 27 vertexCode = """gl_Position = vec4(position, 1.0) * (transform * Uniforms.perspective); colorout = color;""", | |
| 28 fragmentCode = """fragcolor = colorout;""", | |
| 277 | 29 ) |
| 30 | |
| 31 var engine = initEngine("Test collisions") | |
|
329
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
32 |
|
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
352
diff
changeset
|
33 engine.initRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration}) |
|
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
352
diff
changeset
|
34 engine.loadScene(scene) |
| 277 | 35 |
| 1021 | 36 while engine.updateInputs() and not keyIsDown(Escape): |
| 37 if windowWasResized(): | |
| 277 | 38 var winSize = engine.getWindow().size |
| 1021 | 39 scene.setShaderGlobal("perspective", orthoWindowAspect(winSize[0] / winSize[1])) |
| 40 if keyIsDown(A): scene.meshes[0].transform = scene.meshes[0].transform * translate(-0.001, 0, 0) | |
| 41 if keyIsDown(D): scene.meshes[0].transform = scene.meshes[0].transform * translate(0.001, 0, 0) | |
| 42 if keyIsDown(W): scene.meshes[0].transform = scene.meshes[0].transform * translate(0, -0.001, 0) | |
| 43 if keyIsDown(S): scene.meshes[0].transform = scene.meshes[0].transform * translate(0, 0.001, 0) | |
| 44 if keyIsDown(Q): scene.meshes[0].transform = scene.meshes[0].transform * rotate(-0.001, Z) | |
| 45 if keyIsDown(Key.E): scene.meshes[0].transform = scene.meshes[0].transform * rotate(0.001, Z) | |
| 277 | 46 |
| 1021 | 47 if keyIsDown(Key.Z): scene.meshes[1].transform = scene.meshes[1].transform * rotate(-0.001, Z) |
| 48 if keyIsDown(Key.X): scene.meshes[1].transform = scene.meshes[1].transform * rotate(0.001, Z) | |
| 49 if keyIsDown(Key.C): scene.meshes[1].transform = scene.meshes[1].transform * translate(0, -0.001, 0) | |
| 50 if keyIsDown(Key.V): scene.meshes[1].transform = scene.meshes[1].transform * translate(0, 0.001, 0) | |
|
329
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
51 let hitbox = Collider(theType: Box, transform: scene.meshes[0].transform * translate(-0.5, -0.5)) |
|
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
52 let hitsphere = Collider(theType: Sphere, transform: scene.meshes[2].transform, radius: 0.5) |
|
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
53 echo intersects(hitbox, hitsphere) |
| 277 | 54 engine.renderScene(scene) |
| 55 engine.destroy() | |
| 56 | |
| 57 | |
| 58 when isMainModule: | |
| 59 main() |
