diff --git a/Source/Engine/Engine/Engine.cpp b/Source/Engine/Engine/Engine.cpp index 709997eac..979a2547b 100644 --- a/Source/Engine/Engine/Engine.cpp +++ b/Source/Engine/Engine/Engine.cpp @@ -413,24 +413,6 @@ bool Engine::HasGameViewportFocus() #endif } -Vector2 Engine::ScreenToGameViewport(const Vector2& screenPos) -{ -#if USE_EDITOR - return Editor::Managed->ScreenToGameViewport(screenPos); -#else - return MainWindow ? MainWindow->ScreenToClient(screenPos) : Vector2::Minimum; -#endif -} - -Vector2 Engine::GameViewportToScreen(const Vector2& viewportPos) -{ -#if USE_EDITOR - return Editor::Managed->GameViewportToScreen(viewportPos); -#else - return MainWindow ? MainWindow->ClientToScreen(viewportPos) : Vector2::Minimum; -#endif -} - void Engine::OnPause() { LOG(Info, "App paused"); diff --git a/Source/Engine/Engine/Engine.h b/Source/Engine/Engine/Engine.h index 22aeac9f0..13f3e1fe8 100644 --- a/Source/Engine/Engine/Engine.h +++ b/Source/Engine/Engine/Engine.h @@ -153,20 +153,6 @@ public: /// True if game viewport is focused, otherwise false. static bool HasGameViewportFocus(); - /// - /// Converts the screen-space position to the game viewport position. - /// - /// The screen-space position. - /// The game viewport position. - static Vector2 ScreenToGameViewport(const Vector2& screenPos); - - /// - /// Converts the game viewport position to the screen-space position. - /// - /// The game viewport position. - /// The screen-space position. - static Vector2 GameViewportToScreen(const Vector2& viewportPos); - private: static void OnPause(); diff --git a/Source/Engine/Engine/Screen.cpp b/Source/Engine/Engine/Screen.cpp index 999dc28cb..11db5dd42 100644 --- a/Source/Engine/Engine/Screen.cpp +++ b/Source/Engine/Engine/Screen.cpp @@ -66,6 +66,26 @@ void Screen::SetSize(const Vector2& value) Size = value; } +Vector2 Screen::ScreenToGameViewport(const Vector2& screenPos) +{ +#if USE_EDITOR + return Editor::Managed->ScreenToGameViewport(screenPos); +#else + auto win = Engine::MainWindow; + return win ? win->ScreenToClient(screenPos) : Vector2::Minimum; +#endif +} + +Vector2 Screen::GameViewportToScreen(const Vector2& viewportPos) +{ +#if USE_EDITOR + return Editor::Managed->GameViewportToScreen(viewportPos); +#else + auto win = Engine::MainWindow; + return win ? win->ClientToScreen(viewportPos) : Vector2::Minimum; +#endif +} + bool Screen::GetCursorVisible() { #if USE_EDITOR diff --git a/Source/Engine/Engine/Screen.h b/Source/Engine/Engine/Screen.h index 88a44da43..4fa39a324 100644 --- a/Source/Engine/Engine/Screen.h +++ b/Source/Engine/Engine/Screen.h @@ -33,6 +33,20 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(Screen); /// The value API_PROPERTY() static Vector2 GetSize(); + /// + /// Converts the screen-space position to the game viewport position. + /// + /// The screen-space position. + /// The game viewport position. + API_FUNCTION() static Vector2 ScreenToGameViewport(const Vector2& screenPos); + + /// + /// Converts the game viewport position to the screen-space position. + /// + /// The game viewport position. + /// The screen-space position. + API_FUNCTION() static Vector2 GameViewportToScreen(const Vector2& viewportPos); + /// /// Sets the window size. /// diff --git a/Source/Engine/Input/Input.cpp b/Source/Engine/Input/Input.cpp index 485d5a891..d7796691b 100644 --- a/Source/Engine/Input/Input.cpp +++ b/Source/Engine/Input/Input.cpp @@ -339,14 +339,14 @@ bool Input::GetKeyUp(const KeyboardKeys key) Vector2 Input::GetMousePosition() { - return Mouse ? Engine::ScreenToGameViewport(Mouse->GetPosition()) : Vector2::Minimum; + return Mouse ? Screen::ScreenToGameViewport(Mouse->GetPosition()) : Vector2::Minimum; } void Input::SetMousePosition(const Vector2& position) { if (Mouse && Engine::HasGameViewportFocus()) { - const auto pos = Engine::GameViewportToScreen(position); + const auto pos = Screen::GameViewportToScreen(position); if (pos > Vector2::Minimum) Mouse->SetMousePosition(pos); } diff --git a/Source/Engine/Level/Actors/Camera.cpp b/Source/Engine/Level/Actors/Camera.cpp index 95eebefc1..1f9de6d41 100644 --- a/Source/Engine/Level/Actors/Camera.cpp +++ b/Source/Engine/Level/Actors/Camera.cpp @@ -101,12 +101,12 @@ void Camera::SetOrthographicScale(float value) } } -void Camera::ProjectPoint(const Vector3& worldSpaceLocation, Vector2& screenSpaceLocation) const +void Camera::ProjectPoint(const Vector3& worldSpaceLocation, Vector2& gameWindowSpaceLocation) const { - ProjectPoint(worldSpaceLocation, screenSpaceLocation, GetViewport()); + ProjectPoint(worldSpaceLocation, gameWindowSpaceLocation, GetViewport()); } -void Camera::ProjectPoint(const Vector3& worldSpaceLocation, Vector2& screenSpaceLocation, const Viewport& viewport) const +void Camera::ProjectPoint(const Vector3& worldSpaceLocation, Vector2& cameraViewportSpaceLocation, const Viewport& viewport) const { Matrix v, p, vp; GetMatrices(v, p, viewport); @@ -114,7 +114,7 @@ void Camera::ProjectPoint(const Vector3& worldSpaceLocation, Vector2& screenSpac Vector3 clipSpaceLocation; Vector3::Transform(worldSpaceLocation, vp, clipSpaceLocation); viewport.Project(worldSpaceLocation, vp, clipSpaceLocation); - screenSpaceLocation = Vector2(clipSpaceLocation); + cameraViewportSpaceLocation = Vector2(clipSpaceLocation); } Ray Camera::ConvertMouseToRay(const Vector2& mousePosition) const diff --git a/Source/Engine/Level/Actors/Camera.h b/Source/Engine/Level/Actors/Camera.h index 7f40617dd..4bf277279 100644 --- a/Source/Engine/Level/Actors/Camera.h +++ b/Source/Engine/Level/Actors/Camera.h @@ -174,19 +174,19 @@ public: public: /// - /// Projects the point from 3D world-space to the camera screen-space (in screen pixels for default viewport calculated from ). + /// Projects the point from 3D world-space to game window coordinates (in screen pixels for default viewport calculated from ). /// /// The input world-space location (XYZ in world). - /// The output screen-space location (XY in screen pixels). - API_FUNCTION() void ProjectPoint(const Vector3& worldSpaceLocation, API_PARAM(Out) Vector2& screenSpaceLocation) const; + /// The output game window coordinates (XY in screen pixels). + API_FUNCTION() void ProjectPoint(const Vector3& worldSpaceLocation, API_PARAM(Out) Vector2& gameWindowSpaceLocation) const; /// - /// Projects the point from 3D world-space to the camera screen-space (in screen pixels for given viewport). + /// Projects the point from 3D world-space to the camera viewport-space (in screen pixels for given viewport). /// /// The input world-space location (XYZ in world). - /// The output screen-space location (XY in screen pixels). + /// The output camera viewport-space location (XY in screen pixels). /// The viewport. - API_FUNCTION() void ProjectPoint(const Vector3& worldSpaceLocation, API_PARAM(Out) Vector2& screenSpaceLocation, API_PARAM(Ref) const Viewport& viewport) const; + API_FUNCTION() void ProjectPoint(const Vector3& worldSpaceLocation, API_PARAM(Out) Vector2& cameraViewportSpaceLocation, API_PARAM(Ref) const Viewport& viewport) const; /// /// Converts the mouse position to 3D ray.