Mercurial > games > semicongine
annotate tests/test_collision.nim @ 973:7fb8f62a9ea5
add: api to interact with steam
author | sam <sam@basx.dev> |
---|---|
date | Thu, 04 Apr 2024 17:21:56 +0700 |
parents | f054b8bacab8 |
children | 73b572f82a1f |
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 |
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
|
6 scene.add rect(color="f00f") |
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() |
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
|
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( |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
18 inputs=[ |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
19 attr[Mat4]("transform", memoryPerformanceHint=PreferFastRead, perInstance=true), |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
20 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
21 attr[Vec4f]("color", memoryPerformanceHint=PreferFastRead), |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
22 ], |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
23 intermediates=[attr[Vec4f]("colorout")], |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
24 uniforms=[attr[Mat4]("perspective")], |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
25 outputs=[attr[Vec4f]("fragcolor")], |
277 | 26 vertexCode="""gl_Position = vec4(position, 1.0) * (transform * Uniforms.perspective); colorout = color;""", |
27 fragmentCode="""fragcolor = colorout;""", | |
28 ) | |
29 | |
30 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
|
31 |
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
352
diff
changeset
|
32 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
|
33 engine.loadScene(scene) |
277 | 34 |
35 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): | |
36 if engine.windowWasResized(): | |
37 var winSize = engine.getWindow().size | |
38 scene.setShaderGlobal("perspective", orthoWindowAspect(winSize[1] / winSize[0])) | |
329
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
39 if engine.keyIsDown(A): scene.meshes[0].transform = scene.meshes[0].transform * translate(-0.001, 0, 0) |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
40 if engine.keyIsDown(D): scene.meshes[0].transform = scene.meshes[0].transform * translate( 0.001, 0, 0) |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
41 if engine.keyIsDown(W): scene.meshes[0].transform = scene.meshes[0].transform * translate( 0, -0.001, 0) |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
42 if engine.keyIsDown(S): scene.meshes[0].transform = scene.meshes[0].transform * translate( 0, 0.001, 0) |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
43 if engine.keyIsDown(Q): scene.meshes[0].transform = scene.meshes[0].transform * rotate(-0.001, Z) |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
44 if engine.keyIsDown(Key.E): scene.meshes[0].transform = scene.meshes[0].transform * rotate( 0.001, Z) |
277 | 45 |
329
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
46 if engine.keyIsDown(Key.Z): scene.meshes[1].transform = scene.meshes[1].transform * rotate(-0.001, Z) |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
47 if engine.keyIsDown(Key.X): scene.meshes[1].transform = scene.meshes[1].transform * rotate( 0.001, Z) |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
48 if engine.keyIsDown(Key.C): scene.meshes[1].transform = scene.meshes[1].transform * translate(0, -0.001, 0) |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
49 if engine.keyIsDown(Key.V): scene.meshes[1].transform = scene.meshes[1].transform * translate(0, 0.001, 0) |
69e18f69713b
add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents:
320
diff
changeset
|
50 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
|
51 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
|
52 echo intersects(hitbox, hitsphere) |
277 | 53 engine.renderScene(scene) |
54 engine.destroy() | |
55 | |
56 | |
57 when isMainModule: | |
58 main() |