comparison tests/test_collision.nim @ 1139:114f395b9144

did: finish refactoring and updated all tests accordingly
author sam <sam@basx.dev>
date Sat, 08 Jun 2024 14:58:25 +0700
parents 02e1d2658ff5
children
comparison
equal deleted inserted replaced
1138:02e1d2658ff5 1139:114f395b9144
1 import semicongine 1 import semicongine
2 2
3 proc main() = 3 proc main() =
4 var scene = Scene(name: "main") 4 var scene = Scene(name: "main")
5 5
6 scene.add rect(color = "f00f") 6 scene.Add Rect(color = "f00f")
7 scene.add rect() 7 scene.Add Rect()
8 scene.add circle(color = "0f0f") 8 scene.Add Circle(color = "0f0f")
9 scene.meshes[0].material = VERTEX_COLORED_MATERIAL.initMaterialData() 9 scene.meshes[0].material = VERTEX_COLORED_MATERIAL.InitMaterialData()
10 scene.meshes[1].material = VERTEX_COLORED_MATERIAL.initMaterialData() 10 scene.meshes[1].material = VERTEX_COLORED_MATERIAL.InitMaterialData()
11 scene.meshes[2].material = VERTEX_COLORED_MATERIAL.initMaterialData() 11 scene.meshes[2].material = VERTEX_COLORED_MATERIAL.InitMaterialData()
12 scene.meshes[1].transform = Scale(0.8, 0.8) 12 scene.meshes[1].transform = Scale(0.8, 0.8)
13 scene.meshes[2].transform = Scale(0.1, 0.1) 13 scene.meshes[2].transform = Scale(0.1, 0.1)
14 scene.addShaderGlobal("perspective", Unit4F32) 14 scene.AddShaderGlobal("perspective", Unit4F32)
15 15
16 const 16 const
17 shaderConfiguration = createShaderConfiguration( 17 shaderConfiguration = CreateShaderConfiguration(
18 name = "default shader", 18 name = "default shader",
19 inputs = [ 19 inputs = [
20 Attr[Mat4]("transform", memoryPerformanceHint = PreferFastRead, perInstance = true), 20 Attr[Mat4]("transform", memoryPerformanceHint = PreferFastRead, perInstance = true),
21 Attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), 21 Attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead),
22 Attr[Vec4f]("color", memoryPerformanceHint = PreferFastRead), 22 Attr[Vec4f]("color", memoryPerformanceHint = PreferFastRead),
33 engine.InitRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration}) 33 engine.InitRenderer({VERTEX_COLORED_MATERIAL: shaderConfiguration})
34 engine.LoadScene(scene) 34 engine.LoadScene(scene)
35 35
36 while engine.UpdateInputs() and not KeyIsDown(Escape): 36 while engine.UpdateInputs() and not KeyIsDown(Escape):
37 if WindowWasResized(): 37 if WindowWasResized():
38 var winSize = engine.GetWindow().size 38 var winSize = engine.GetWindow().Size
39 scene.setShaderGlobal("perspective", OrthoWindowAspect(winSize[0] / winSize[1])) 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) 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) 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) 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) 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) 44 if KeyIsDown(Q): scene.meshes[0].transform = scene.meshes[0].transform * Rotate(-0.001, Z)
48 if KeyIsDown(Key.X): 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) 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) 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)) 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) 52 let hitsphere = Collider(theType: Sphere, transform: scene.meshes[2].transform, radius: 0.5)
53 echo intersects(hitbox, hitsphere) 53 echo Intersects(hitbox, hitsphere)
54 engine.RenderScene(scene) 54 engine.RenderScene(scene)
55 engine.Destroy() 55 engine.Destroy()
56 56
57 57
58 when isMainModule: 58 when isMainModule: