Merge branch 'RuanLucasGD-Inputs'

This commit is contained in:
Wojtek Figat
2023-02-03 15:48:20 +01:00
7 changed files with 63 additions and 0 deletions

View File

@@ -267,6 +267,19 @@ namespace FlaxEngine
/// <remarks>This method may be preferred to <see cref="Float2.Length" /> when only a relative length is needed and speed is of the essence.</remarks>
public float LengthSquared => X * X + Y * Y;
/// <summary>
/// Gets the normalized vector. Returned vector has length equal 1.
/// </summary>
public Float2 Normalized
{
get
{
Float2 result = this;
result.Normalize();
return result;
}
}
/// <summary>
/// Converts the vector into a unit vector.
/// </summary>

View File

@@ -301,6 +301,19 @@ namespace FlaxEngine
}
}
/// <summary>
/// Gets the normalized vector. Returned vector has length equal 1.
/// </summary>
public Vector2 Normalized
{
get
{
Vector2 result = this;
result.Normalize();
return result;
}
}
/// <summary>
/// Creates an array containing the elements of the vector.
/// </summary>

View File

@@ -223,6 +223,15 @@ public:
return Vector2Base(-X, -Y);
}
/// <summary>
/// Calculates a normalized vector that has length equal to 1.
/// </summary>
Vector2Base GetNormalized() const
{
const T rcp = 1.0f / Length();
return Vector2Base(X * rcp, Y * rcp);
}
public:
/// <summary>
/// Performs vector normalization (scales vector up to unit length).

View File

@@ -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

View File

@@ -164,6 +164,11 @@ public:
return _mappedState.Buttons[static_cast<int32>(button)] && !_mappedPrevState.Buttons[static_cast<int32>(button)];
}
/// <summary>
/// Checks if any gamepad button is currently pressed.
/// </summary>
API_PROPERTY() bool IsAnyButtonDown() const;
/// <summary>
/// Gets the gamepad button up state (true if was released during the current frame).
/// </summary>

View File

@@ -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();

View File

@@ -64,6 +64,11 @@ public:
return _state.MousePosition;
}
/// <summary>
/// Checks if any mouse button is currently pressed.
/// </summary>
API_PROPERTY() bool IsAnyButtonDown() const;
/// <summary>
/// Gets the delta position of the mouse in the screen-space coordinates.
/// </summary>