comparison 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
comparison
equal deleted inserted replaced
1202:a8864fe6fe6e 1203:6360c8d17ce0
1 import semicongine
2
3 proc main() =
4 var scene = Scene(name: "main")
5
6 scene.Add Rect(color = "f00f")
7 scene.Add Rect()
8 scene.Add Circle(color = "0f0f")
9 scene.meshes[0].material = VERTEX_COLORED_MATERIAL.InitMaterialData()
10 scene.meshes[1].material = VERTEX_COLORED_MATERIAL.InitMaterialData()
11 scene.meshes[2].material = VERTEX_COLORED_MATERIAL.InitMaterialData()
12 scene.meshes[1].transform = Scale(0.8, 0.8)
13 scene.meshes[2].transform = Scale(0.1, 0.1)
14 scene.AddShaderGlobal("perspective", Unit4F32)
15
16 const
17 shaderConfiguration = CreateShaderConfiguration(
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),
23 ],
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;""",
29 )
30
31 var engine = InitEngine("Test collisions")
32
33 engine.InitRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration})
34 engine.LoadScene(scene)
35
36 while engine.UpdateInputs() and not KeyIsDown(Escape):
37 if WindowWasResized():
38 var winSize = engine.GetWindow().Size
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)
46
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))
52 let hitsphere = Collider(theType: Sphere, transform: scene.meshes[2].transform, radius: 0.5)
53 echo Intersects(hitbox, hitsphere)
54 engine.RenderScene(scene)
55 engine.Destroy()
56
57
58 when isMainModule:
59 main()