test48.nim 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # --- Test 48. Use Camera3D node. --- #
  2. import nodesnim
  3. Window("camera 3d test", 1024, 640)
  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. addKeyAction("forward", "w")
  31. addKeyAction("back", "s")
  32. addKeyAction("left", "a")
  33. addKeyAction("right", "d")
  34. root@on_input(self, event):
  35. if event.isInputEventMouseMotion() and event.pressed:
  36. camera.rotate(-event.xrel*0.1, event.yrel*0.1)
  37. if isActionPressed("left"):
  38. root.translate(camera.right * -0.1)
  39. if isActionPressed("right"):
  40. root.translate(camera.right * 0.1)
  41. if isActionPressed("forward"):
  42. root.translate(camera.front*0.1)
  43. if isActionPressed("back"):
  44. root.translate(camera.front*(-0.1))
  45. addMainScene(main)
  46. windowLaunch()