Mercurial > games > semicongine
annotate old_tests/test_collision.nim @ 1354:8ad6e4cfcb2d
merge
author | sam <sam@basx.dev> |
---|---|
date | Fri, 27 Sep 2024 23:45:13 +0700 |
parents | 6360c8d17ce0 |
children |
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 |
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 | 12 scene.meshes[1].transform = Scale(0.8, 0.8) |
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 | 15 |
16 const | |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
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 | |
1138 | 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 | 33 engine.InitRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration}) |
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(): |
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 | 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) |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
53 echo Intersects(hitbox, hitsphere) |
1138 | 54 engine.RenderScene(scene) |
55 engine.Destroy() | |
277 | 56 |
57 | |
58 when isMainModule: | |
59 main() |