Merge pull request #95790 from aaronfranke/rect-aabb-support
Simplify Rect2/AABB `get_support` function
This commit is contained in:
@ -314,13 +314,20 @@ namespace Godot
|
||||
/// <returns>A vector representing the support.</returns>
|
||||
public readonly Vector3 GetSupport(Vector3 dir)
|
||||
{
|
||||
Vector3 halfExtents = _size * 0.5f;
|
||||
Vector3 ofs = _position + halfExtents;
|
||||
|
||||
return ofs + new Vector3(
|
||||
dir.X > 0f ? halfExtents.X : -halfExtents.X,
|
||||
dir.Y > 0f ? halfExtents.Y : -halfExtents.Y,
|
||||
dir.Z > 0f ? halfExtents.Z : -halfExtents.Z);
|
||||
Vector3 support = _position;
|
||||
if (dir.X > 0.0f)
|
||||
{
|
||||
support.X += _size.X;
|
||||
}
|
||||
if (dir.Y > 0.0f)
|
||||
{
|
||||
support.Y += _size.Y;
|
||||
}
|
||||
if (dir.Z > 0.0f)
|
||||
{
|
||||
support.Z += _size.Z;
|
||||
}
|
||||
return support;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -171,6 +171,26 @@ namespace Godot
|
||||
return _position + (_size * 0.5f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the support point in a given direction.
|
||||
/// This is useful for collision detection algorithms.
|
||||
/// </summary>
|
||||
/// <param name="direction">The direction to find support for.</param>
|
||||
/// <returns>A vector representing the support.</returns>
|
||||
public readonly Vector2 GetSupport(Vector2 direction)
|
||||
{
|
||||
Vector2 support = _position;
|
||||
if (direction.X > 0.0f)
|
||||
{
|
||||
support.X += _size.X;
|
||||
}
|
||||
if (direction.Y > 0.0f)
|
||||
{
|
||||
support.Y += _size.Y;
|
||||
}
|
||||
return support;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the <see cref="Rect2"/> grown by the specified amount
|
||||
/// on all sides.
|
||||
|
||||
Reference in New Issue
Block a user