annotate old_tests/test_collision.nim @ 1203:6360c8d17ce0 compiletime-tests

did: preprations to add rendering tests
author sam <sam@basx.dev>
date Mon, 15 Jul 2024 20:06:42 +0700
parents tests/test_collision.nim@114f395b9144
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
277
1fbef3a2d769 add: collision tests
Sam <sam@basx.dev>
parents:
diff changeset
1 import semicongine
1fbef3a2d769 add: collision tests
Sam <sam@basx.dev>
parents:
diff changeset
2
1fbef3a2d769 add: collision tests
Sam <sam@basx.dev>
parents:
diff changeset
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
1fbef3a2d769 add: collision tests
Sam <sam@basx.dev>
parents:
diff changeset
5
1139
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
6 scene.Add Rect(color = "f00f")
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
7 scene.Add Rect()
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
8 scene.Add Circle(color = "0f0f")
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
9 scene.meshes[0].material = VERTEX_COLORED_MATERIAL.InitMaterialData()
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
10 scene.meshes[1].material = VERTEX_COLORED_MATERIAL.InitMaterialData()
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
11 scene.meshes[2].material = VERTEX_COLORED_MATERIAL.InitMaterialData()
1136
71315636ba82 did: refactor naming in tons of places
sam <sam@basx.dev>
parents: 1135
diff changeset
12 scene.meshes[1].transform = Scale(0.8, 0.8)
71315636ba82 did: refactor naming in tons of places
sam <sam@basx.dev>
parents: 1135
diff changeset
13 scene.meshes[2].transform = Scale(0.1, 0.1)
1139
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
14 scene.AddShaderGlobal("perspective", Unit4F32)
277
1fbef3a2d769 add: collision tests
Sam <sam@basx.dev>
parents:
diff changeset
15
1fbef3a2d769 add: collision tests
Sam <sam@basx.dev>
parents:
diff changeset
16 const
1139
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
17 shaderConfiguration = CreateShaderConfiguration(
1021
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents: 371
diff changeset
18 name = "default shader",
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents: 371
diff changeset
19 inputs = [
1137
a4aa9f374d44 did: more renaming
sam <sam@basx.dev>
parents: 1136
diff changeset
20 Attr[Mat4]("transform", memoryPerformanceHint = PreferFastRead, perInstance = true),
a4aa9f374d44 did: more renaming
sam <sam@basx.dev>
parents: 1136
diff changeset
21 Attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead),
a4aa9f374d44 did: more renaming
sam <sam@basx.dev>
parents: 1136
diff changeset
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
a4aa9f374d44 did: more renaming
sam <sam@basx.dev>
parents: 1136
diff changeset
24 intermediates = [Attr[Vec4f]("colorout")],
a4aa9f374d44 did: more renaming
sam <sam@basx.dev>
parents: 1136
diff changeset
25 uniforms = [Attr[Mat4]("perspective")],
a4aa9f374d44 did: more renaming
sam <sam@basx.dev>
parents: 1136
diff changeset
26 outputs = [Attr[Vec4f]("fragcolor")],
1021
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents: 371
diff changeset
27 vertexCode = """gl_Position = vec4(position, 1.0) * (transform * Uniforms.perspective); colorout = color;""",
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents: 371
diff changeset
28 fragmentCode = """fragcolor = colorout;""",
277
1fbef3a2d769 add: collision tests
Sam <sam@basx.dev>
parents:
diff changeset
29 )
1fbef3a2d769 add: collision tests
Sam <sam@basx.dev>
parents:
diff changeset
30
1138
02e1d2658ff5 did: more renaming
sam <sam@basx.dev>
parents: 1137
diff changeset
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
1138
02e1d2658ff5 did: more renaming
sam <sam@basx.dev>
parents: 1137
diff changeset
33 engine.InitRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration})
02e1d2658ff5 did: more renaming
sam <sam@basx.dev>
parents: 1137
diff changeset
34 engine.LoadScene(scene)
277
1fbef3a2d769 add: collision tests
Sam <sam@basx.dev>
parents:
diff changeset
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():
1139
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
38 var winSize = engine.GetWindow().Size
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
39 scene.SetShaderGlobal("perspective", OrthoWindowAspect(winSize[0] / winSize[1]))
1136
71315636ba82 did: refactor naming in tons of places
sam <sam@basx.dev>
parents: 1135
diff changeset
40 if KeyIsDown(A): scene.meshes[0].transform = scene.meshes[0].transform * Translate(-0.001, 0, 0)
71315636ba82 did: refactor naming in tons of places
sam <sam@basx.dev>
parents: 1135
diff changeset
41 if KeyIsDown(D): scene.meshes[0].transform = scene.meshes[0].transform * Translate(0.001, 0, 0)
71315636ba82 did: refactor naming in tons of places
sam <sam@basx.dev>
parents: 1135
diff changeset
42 if KeyIsDown(W): scene.meshes[0].transform = scene.meshes[0].transform * Translate(0, -0.001, 0)
71315636ba82 did: refactor naming in tons of places
sam <sam@basx.dev>
parents: 1135
diff changeset
43 if KeyIsDown(S): scene.meshes[0].transform = scene.meshes[0].transform * Translate(0, 0.001, 0)
71315636ba82 did: refactor naming in tons of places
sam <sam@basx.dev>
parents: 1135
diff changeset
44 if KeyIsDown(Q): scene.meshes[0].transform = scene.meshes[0].transform * Rotate(-0.001, Z)
71315636ba82 did: refactor naming in tons of places
sam <sam@basx.dev>
parents: 1135
diff changeset
45 if KeyIsDown(Key.E): scene.meshes[0].transform = scene.meshes[0].transform * Rotate(0.001, Z)
277
1fbef3a2d769 add: collision tests
Sam <sam@basx.dev>
parents:
diff changeset
46
1136
71315636ba82 did: refactor naming in tons of places
sam <sam@basx.dev>
parents: 1135
diff changeset
47 if KeyIsDown(Key.Z): scene.meshes[1].transform = scene.meshes[1].transform * Rotate(-0.001, Z)
71315636ba82 did: refactor naming in tons of places
sam <sam@basx.dev>
parents: 1135
diff changeset
48 if KeyIsDown(Key.X): scene.meshes[1].transform = scene.meshes[1].transform * Rotate(0.001, Z)
71315636ba82 did: refactor naming in tons of places
sam <sam@basx.dev>
parents: 1135
diff changeset
49 if KeyIsDown(Key.C): scene.meshes[1].transform = scene.meshes[1].transform * Translate(0, -0.001, 0)
71315636ba82 did: refactor naming in tons of places
sam <sam@basx.dev>
parents: 1135
diff changeset
50 if KeyIsDown(Key.V): scene.meshes[1].transform = scene.meshes[1].transform * Translate(0, 0.001, 0)
71315636ba82 did: refactor naming in tons of places
sam <sam@basx.dev>
parents: 1135
diff changeset
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)
1139
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
53 echo Intersects(hitbox, hitsphere)
1138
02e1d2658ff5 did: more renaming
sam <sam@basx.dev>
parents: 1137
diff changeset
54 engine.RenderScene(scene)
02e1d2658ff5 did: more renaming
sam <sam@basx.dev>
parents: 1137
diff changeset
55 engine.Destroy()
277
1fbef3a2d769 add: collision tests
Sam <sam@basx.dev>
parents:
diff changeset
56
1fbef3a2d769 add: collision tests
Sam <sam@basx.dev>
parents:
diff changeset
57
1fbef3a2d769 add: collision tests
Sam <sam@basx.dev>
parents:
diff changeset
58 when isMainModule:
1fbef3a2d769 add: collision tests
Sam <sam@basx.dev>
parents:
diff changeset
59 main()