diff --git a/Source/Engine/Core/Math/Float2.cs b/Source/Engine/Core/Math/Float2.cs index 276c0c713..15f412d6e 100644 --- a/Source/Engine/Core/Math/Float2.cs +++ b/Source/Engine/Core/Math/Float2.cs @@ -267,6 +267,19 @@ namespace FlaxEngine /// This method may be preferred to when only a relative length is needed and speed is of the essence. public float LengthSquared => X * X + Y * Y; + /// + /// Gets the normalized vector. Returned vector has length equal 1. + /// + public Float2 Normalized + { + get + { + Float2 result = this; + result.Normalize(); + return result; + } + } + /// /// Converts the vector into a unit vector. /// diff --git a/Source/Engine/Core/Math/Vector2.cs b/Source/Engine/Core/Math/Vector2.cs index 25c25ca21..cd1849383 100644 --- a/Source/Engine/Core/Math/Vector2.cs +++ b/Source/Engine/Core/Math/Vector2.cs @@ -301,6 +301,19 @@ namespace FlaxEngine } } + /// + /// Gets the normalized vector. Returned vector has length equal 1. + /// + public Vector2 Normalized + { + get + { + Vector2 result = this; + result.Normalize(); + return result; + } + } + /// /// Creates an array containing the elements of the vector. /// diff --git a/Source/Engine/Core/Math/Vector2.h b/Source/Engine/Core/Math/Vector2.h index 2b8c80293..2f7a143c4 100644 --- a/Source/Engine/Core/Math/Vector2.h +++ b/Source/Engine/Core/Math/Vector2.h @@ -223,6 +223,15 @@ public: return Vector2Base(-X, -Y); } + /// + /// Calculates a normalized vector that has length equal to 1. + /// + Vector2Base GetNormalized() const + { + const T rcp = 1.0f / Length(); + return Vector2Base(X * rcp, Y * rcp); + } + public: /// /// Performs vector normalization (scales vector up to unit length). diff --git a/Source/Engine/Input/Gamepad.cpp b/Source/Engine/Input/Gamepad.cpp index 7835e7724..278dc5961 100644 --- a/Source/Engine/Input/Gamepad.cpp +++ b/Source/Engine/Input/Gamepad.cpp @@ -31,6 +31,15 @@ void Gamepad::ResetState() _mappedPrevState.Clear(); } +bool Gamepad::IsAnyButtonDown() const +{ + // TODO: optimize with SIMD + bool result = false; + for (auto e : _state.Buttons) + result |= e; + return result; +} + bool Gamepad::Update(EventQueue& queue) { // Copy state diff --git a/Source/Engine/Input/Gamepad.h b/Source/Engine/Input/Gamepad.h index 63decde7c..27a53a716 100644 --- a/Source/Engine/Input/Gamepad.h +++ b/Source/Engine/Input/Gamepad.h @@ -164,6 +164,11 @@ public: return _mappedState.Buttons[static_cast(button)] && !_mappedPrevState.Buttons[static_cast(button)]; } + /// + /// Checks if any gamepad button is currently pressed. + /// + API_PROPERTY() bool IsAnyButtonDown() const; + /// /// Gets the gamepad button up state (true if was released during the current frame). /// diff --git a/Source/Engine/Input/Input.cpp b/Source/Engine/Input/Input.cpp index b7c202512..7a4547c62 100644 --- a/Source/Engine/Input/Input.cpp +++ b/Source/Engine/Input/Input.cpp @@ -183,6 +183,15 @@ void Mouse::OnMouseDown(const Float2& position, const MouseButton button, Window e.MouseData.Position = position; } +bool Mouse::IsAnyButtonDown() const +{ + // TODO: optimize with SIMD + bool result = false; + for (auto e : Mouse::_state.MouseButtons) + result |= e; + return result; +} + void Mouse::OnMouseUp(const Float2& position, const MouseButton button, Window* target) { Event& e = _queue.AddOne(); diff --git a/Source/Engine/Input/Mouse.h b/Source/Engine/Input/Mouse.h index ebf25ebb1..7fc2be75a 100644 --- a/Source/Engine/Input/Mouse.h +++ b/Source/Engine/Input/Mouse.h @@ -64,6 +64,11 @@ public: return _state.MousePosition; } + /// + /// Checks if any mouse button is currently pressed. + /// + API_PROPERTY() bool IsAnyButtonDown() const; + /// /// Gets the delta position of the mouse in the screen-space coordinates. ///