Mercurial > games > semicongine
annotate tests/test_collision.nim @ 1137:a4aa9f374d44
did: more renaming
author | sam <sam@basx.dev> |
---|---|
date | Tue, 04 Jun 2024 20:51:22 +0700 |
parents | 71315636ba82 |
children | 02e1d2658ff5 |
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() |
1136 | 12 scene.meshes[1].transform = Scale(0.8, 0.8) |
13 scene.meshes[2].transform = Scale(0.1, 0.1) | |
329
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 = [ | |
1137 | 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 ], |
1137 | 24 intermediates = [Attr[Vec4f]("colorout")], |
25 uniforms = [Attr[Mat4]("perspective")], | |
26 outputs = [Attr[Vec4f]("fragcolor")], | |
1021 | 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 |
1135
74957cbf589b
fix: update tests according to some API renaming
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
36 while engine.UpdateInputs() and not KeyIsDown(Escape): |
74957cbf589b
fix: update tests according to some API renaming
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
37 if WindowWasResized(): |
74957cbf589b
fix: update tests according to some API renaming
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
38 var winSize = engine.GetWindow().size |
1136 | 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 |
1136 | 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) | |
51 let hitbox = Collider(theType: Box, transform: scene.meshes[0].transform * Translate(-0.5, -0.5)) | |
329
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() |