test7.nim 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # --- Test 7. Work with 3D nodes. --- #
  2. import
  3. nodesnim,
  4. unittest
  5. suite "Work with 3D nodes.":
  6. test "Setup window":
  7. Window("3D nodes test", 1024, 640)
  8. test "Setup scene":
  9. build:
  10. - Scene main
  11. addMainScene(main)
  12. test "Register events":
  13. addKeyAction("forward", "w")
  14. addKeyAction("back", "s")
  15. addKeyAction("left", "a")
  16. addKeyAction("right", "d")
  17. test "GeometryInstance test":
  18. build:
  19. - GeometryInstance cube:
  20. translation: Vector3(-1, 0, 2)
  21. color: Color(122, 133, 144, 0.8)
  22. - GeometryInstance cube1:
  23. translation: Vector3(2, 0, -2)
  24. color: Color(144, 144, 122, 0.8)
  25. - GeometryInstance cube2:
  26. translation: Vector3(1, 2.5, 1)
  27. color: Color(144, 111, 144, 0.8)
  28. - GeometryInstance sphere:
  29. translation: Vector3(-1, -1, 1)
  30. color: Color(144, 77, 144, 1.0)
  31. geometry: GEOMETRY_SPHERE
  32. - GeometryInstance cylinder:
  33. translation: Vector3(2, -1, 1)
  34. color: Color(144, 77, 144, 1.0)
  35. geometry: GEOMETRY_CYLINDER
  36. getSceneByName("main").addChildren(cube, cube1, cube2, sphere, cylinder)
  37. test "Camera3D test":
  38. build:
  39. - Node3D root:
  40. call translate(2, 2, -5)
  41. - Camera3D camera:
  42. call setCurrent()
  43. call changeTarget(root)
  44. root@onInput(self, event):
  45. if event.isInputEventMouseMotion() and event.pressed:
  46. camera.rotate(-event.xrel*0.25, event.yrel*0.25)
  47. root@onProcess(self):
  48. if isActionPressed("left"):
  49. root.translate(camera.right * -0.1)
  50. if isActionPressed("right"):
  51. root.translate(camera.right * 0.1)
  52. if isActionPressed("forward"):
  53. root.translate(camera.front*0.1)
  54. if isActionPressed("back"):
  55. root.translate(camera.front*(-0.1))
  56. getSceneByName("main").addChild(root)
  57. test "Sprite3D test":
  58. build:
  59. - Sprite3D sprite:
  60. call loadTexture("assets/anim/2.jpg", GL_RGB)
  61. call translate(-3, -2, 2)
  62. sprite@onProcess(self):
  63. sprite.rotateY(0.5)
  64. getSceneByName("main").addChild(sprite)
  65. test "Launch window":
  66. windowLaunch()