engine_view_helpers.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include "game/systems/picking_service.h"
  3. #include "render/gl/camera.h"
  4. #include <QPointF>
  5. #include <QQuickWindow>
  6. #include <QVector3D>
  7. namespace App::Utils {
  8. inline auto screenToGround(const Game::Systems::PickingService *pickingService,
  9. const Render::GL::Camera *camera,
  10. QQuickWindow *window, int viewportWidth,
  11. int viewportHeight, const QPointF &screenPt,
  12. QVector3D &outWorld) -> bool {
  13. if ((window == nullptr) || (camera == nullptr) ||
  14. (pickingService == nullptr)) {
  15. return false;
  16. }
  17. int const w = (viewportWidth > 0 ? viewportWidth : window->width());
  18. int const h = (viewportHeight > 0 ? viewportHeight : window->height());
  19. return Game::Systems::PickingService::screenToGround(*camera, w, h, screenPt,
  20. outWorld);
  21. }
  22. inline auto worldToScreen(const Game::Systems::PickingService *pickingService,
  23. const Render::GL::Camera *camera,
  24. QQuickWindow *window, int viewportWidth,
  25. int viewportHeight, const QVector3D &world,
  26. QPointF &outScreen) -> bool {
  27. if ((window == nullptr) || (camera == nullptr) ||
  28. (pickingService == nullptr)) {
  29. return false;
  30. }
  31. int const w = (viewportWidth > 0 ? viewportWidth : window->width());
  32. int const h = (viewportHeight > 0 ? viewportHeight : window->height());
  33. return Game::Systems::PickingService::worldToScreen(*camera, w, h, world,
  34. outScreen);
  35. }
  36. } // namespace App::Utils