test48.nim 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # --- Test 48. Use Camera3D node. --- #
  2. import nodesnim
  3. Window("camera 3d test")
  4. build:
  5. - Scene main:
  6. - Node3D root:
  7. call translate(2, 2, -5)
  8. - Camera3D camera:
  9. call setCurrent()
  10. call changeTarget(root)
  11. - GeometryInstance cube:
  12. translation: Vector3(-1, 0, 2)
  13. color: Color(122, 133, 144, 0.8)
  14. - GeometryInstance cube1:
  15. translation: Vector3(2, 0, -2)
  16. color: Color(144, 144, 122, 0.8)
  17. - GeometryInstance cube2:
  18. translation: Vector3(1, 2.5, 1)
  19. color: Color(144, 111, 144, 0.8)
  20. - GeometryInstance sphere:
  21. translation: Vector3(-1, -1, 1)
  22. color: Color(144, 77, 144, 1.0)
  23. geometry: GEOMETRY_SPHERE
  24. - ProgressBar health:
  25. call resize(256, 48)
  26. call setAnchor(0, 1, 0, 1)
  27. call setProgress(50)
  28. call setProgressColor(Color("#a77"))
  29. call setBackgroundColor(Color(222, 222, 222, 0.5))
  30. Input.addKeyAction("forward", "w")
  31. Input.addKeyAction("back", "s")
  32. Input.addKeyAction("left", "a")
  33. Input.addKeyAction("right", "d")
  34. root@on_input(self, event):
  35. if event.isInputEventMouseMotion() and event.pressed:
  36. camera.pitch += event.yrel*0.1 # Y
  37. camera.yaw -= event.xrel*0.1 # X
  38. if Input.isActionPressed("left"):
  39. root.translate(camera.front.cross(camera.up).normalized() * -0.1)
  40. if Input.isActionPressed("right"):
  41. root.translate(camera.front.cross(camera.up).normalized() * 0.1)
  42. if Input.isActionPressed("forward"):
  43. root.translate(camera.front*0.1)
  44. if Input.isActionPressed("back"):
  45. root.translate(camera.front*(-0.1))
  46. addMainScene(main)
  47. windowLaunch()