Merge remote-tracking branch 'origin/1.1' into linux-editor
# Conflicts: # Source/Engine/Core/Math/BoundingSphere.cs # Source/Engine/Debug/DebugDraw.cpp # Source/Engine/Platform/Win32/Win32Platform.cpp # Source/Engine/Platform/Win32/Win32Platform.h
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "BoundingSphere.h"
|
||||
#include "BoundingBox.h"
|
||||
#include "Matrix.h"
|
||||
#include "Ray.h"
|
||||
#include "../Types/String.h"
|
||||
|
||||
@@ -194,3 +195,9 @@ void BoundingSphere::Merge(const BoundingSphere& value1, const Vector3& value2,
|
||||
result.Center = value1.Center + vector * (max + min);
|
||||
result.Radius = max;
|
||||
}
|
||||
|
||||
void BoundingSphere::Transform(const BoundingSphere& sphere, const Matrix& matrix, BoundingSphere& result)
|
||||
{
|
||||
Vector3::Transform(sphere.Center, matrix, result.Center);
|
||||
result.Radius = sphere.Radius * matrix.GetScaleVector().GetAbsolute().MaxValue();
|
||||
}
|
||||
|
||||
@@ -88,10 +88,7 @@ namespace FlaxEngine
|
||||
/// Determines if there is an intersection between the current object and a <see cref="Ray" />.
|
||||
/// </summary>
|
||||
/// <param name="ray">The ray to test.</param>
|
||||
/// <param name="distance">
|
||||
/// When the method completes, contains the distance of the intersection,
|
||||
/// or 0 if there was no intersection.
|
||||
/// </param>
|
||||
/// <param name="distance">When the method completes, contains the distance of the intersection, or 0 if there was no intersection.</param>
|
||||
/// <returns>Whether the two objects intersected.</returns>
|
||||
public bool Intersects(ref Ray ray, out float distance)
|
||||
{
|
||||
@@ -102,10 +99,7 @@ namespace FlaxEngine
|
||||
/// Determines if there is an intersection between the current object and a <see cref="Ray" />.
|
||||
/// </summary>
|
||||
/// <param name="ray">The ray to test.</param>
|
||||
/// <param name="point">
|
||||
/// When the method completes, contains the point of intersection,
|
||||
/// or <see cref="Vector3.Zero" /> if there was no intersection.
|
||||
/// </param>
|
||||
/// <param name="point">When the method completes, contains the point of intersection, or <see cref="Vector3.Zero" /> if there was no intersection.</param>
|
||||
/// <returns>Whether the two objects intersected.</returns>
|
||||
public bool Intersects(ref Ray ray, out Vector3 point)
|
||||
{
|
||||
@@ -224,11 +218,7 @@ namespace FlaxEngine
|
||||
/// <param name="count">The count of points to process to compute the bounding sphere.</param>
|
||||
/// <param name="result">When the method completes, contains the newly constructed bounding sphere.</param>
|
||||
/// <exception cref="System.ArgumentNullException">points</exception>
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">
|
||||
/// start
|
||||
/// or
|
||||
/// count
|
||||
/// </exception>
|
||||
/// <exception cref="System.ArgumentOutOfRangeException">start or count</exception>
|
||||
public static void FromPoints(Vector3[] points, int start, int count, out BoundingSphere result)
|
||||
{
|
||||
if (points == null)
|
||||
@@ -244,30 +234,30 @@ namespace FlaxEngine
|
||||
|
||||
int upperEnd = start + count;
|
||||
|
||||
//Find the center of all points.
|
||||
// Find the center of all points
|
||||
Vector3 center = Vector3.Zero;
|
||||
for (int i = start; i < upperEnd; ++i)
|
||||
Vector3.Add(ref points[i], ref center, out center);
|
||||
|
||||
//This is the center of our sphere.
|
||||
// This is the center of our sphere
|
||||
center /= (float)count;
|
||||
|
||||
//Find the radius of the sphere
|
||||
var radius = 0f;
|
||||
for (int i = start; i < upperEnd; ++i)
|
||||
{
|
||||
//We are doing a relative distance comparison to find the maximum distance
|
||||
//from the center of our sphere.
|
||||
// We are doing a relative distance comparison to find the maximum distance from the center of our sphere
|
||||
float distance;
|
||||
Vector3.DistanceSquared(ref center, ref points[i], out float distance);
|
||||
|
||||
if (distance > radius)
|
||||
radius = distance;
|
||||
}
|
||||
|
||||
//Find the real distance from the DistanceSquared.
|
||||
// Find the real distance from the DistanceSquared
|
||||
radius = (float)Math.Sqrt(radius);
|
||||
|
||||
//Construct the sphere.
|
||||
// Construct the sphere
|
||||
result.Center = center;
|
||||
result.Radius = radius;
|
||||
}
|
||||
@@ -281,7 +271,6 @@ namespace FlaxEngine
|
||||
{
|
||||
if (points == null)
|
||||
throw new ArgumentNullException(nameof(points));
|
||||
|
||||
FromPoints(points, 0, points.Length, out result);
|
||||
}
|
||||
|
||||
@@ -292,7 +281,7 @@ namespace FlaxEngine
|
||||
/// <returns>The newly constructed bounding sphere.</returns>
|
||||
public static BoundingSphere FromPoints(Vector3[] points)
|
||||
{
|
||||
FromPoints(points, out BoundingSphere result);
|
||||
FromPoints(points, out var result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -320,7 +309,7 @@ namespace FlaxEngine
|
||||
/// <returns>The newly constructed bounding sphere.</returns>
|
||||
public static BoundingSphere FromBox(BoundingBox box)
|
||||
{
|
||||
FromBox(ref box, out BoundingSphere result);
|
||||
FromBox(ref box, out var result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -383,19 +372,40 @@ namespace FlaxEngine
|
||||
/// <returns>The newly constructed bounding sphere.</returns>
|
||||
public static BoundingSphere Merge(BoundingSphere value1, BoundingSphere value2)
|
||||
{
|
||||
Merge(ref value1, ref value2, out BoundingSphere result);
|
||||
Merge(ref value1, ref value2, out var result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms the bounding sphere using the specified matrix.
|
||||
/// </summary>
|
||||
/// <param name="sphere">The sphere.</param>
|
||||
/// <param name="matrix">The matrix.</param>
|
||||
/// <remarks>The result transformed sphere.</remarks>
|
||||
public static BoundingSphere Transform(BoundingSphere sphere, Matrix matrix)
|
||||
{
|
||||
Transform(ref sphere, ref matrix, out var result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms the bounding sphere using the specified matrix.
|
||||
/// </summary>
|
||||
/// <param name="sphere">The sphere.</param>
|
||||
/// <param name="matrix">The matrix.</param>
|
||||
/// <param name="result">The result transformed sphere.</param>
|
||||
public static void Transform(ref BoundingSphere sphere, ref Matrix matrix, out BoundingSphere result)
|
||||
{
|
||||
Vector3.Transform(ref sphere.Center, ref matrix, out result.Center);
|
||||
result.Radius = sphere.Radius * matrix.ScaleVector.Absolute.MaxValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests for equality between two objects.
|
||||
/// </summary>
|
||||
/// <param name="left">The first value to compare.</param>
|
||||
/// <param name="right">The second value to compare.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if <paramref name="left" /> has the same value as <paramref name="right" />; otherwise,
|
||||
/// <c>false</c>.
|
||||
/// </returns>
|
||||
/// <returns><c>true</c> if <paramref name="left" /> has the same value as <paramref name="right" />; otherwise, <c>false</c>.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(BoundingSphere left, BoundingSphere right)
|
||||
{
|
||||
@@ -407,10 +417,7 @@ namespace FlaxEngine
|
||||
/// </summary>
|
||||
/// <param name="left">The first value to compare.</param>
|
||||
/// <param name="right">The second value to compare.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if <paramref name="left" /> has a different value than <paramref name="right" />; otherwise,
|
||||
/// <c>false</c>.
|
||||
/// </returns>
|
||||
/// <returns><c>true</c> if <paramref name="left" /> has a different value than <paramref name="right" />; otherwise, <c>false</c>.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(BoundingSphere left, BoundingSphere right)
|
||||
{
|
||||
@@ -420,9 +427,7 @@ namespace FlaxEngine
|
||||
/// <summary>
|
||||
/// Returns a <see cref="System.String" /> that represents this instance.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A <see cref="System.String" /> that represents this instance.
|
||||
/// </returns>
|
||||
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture,
|
||||
@@ -435,9 +440,7 @@ namespace FlaxEngine
|
||||
/// Returns a <see cref="System.String" /> that represents this instance.
|
||||
/// </summary>
|
||||
/// <param name="format">The format.</param>
|
||||
/// <returns>
|
||||
/// A <see cref="System.String" /> that represents this instance.
|
||||
/// </returns>
|
||||
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
|
||||
public string ToString(string format)
|
||||
{
|
||||
if (format == null)
|
||||
@@ -453,9 +456,7 @@ namespace FlaxEngine
|
||||
/// Returns a <see cref="System.String" /> that represents this instance.
|
||||
/// </summary>
|
||||
/// <param name="formatProvider">The format provider.</param>
|
||||
/// <returns>
|
||||
/// A <see cref="System.String" /> that represents this instance.
|
||||
/// </returns>
|
||||
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
|
||||
public string ToString(IFormatProvider formatProvider)
|
||||
{
|
||||
return string.Format(formatProvider,
|
||||
@@ -469,9 +470,7 @@ namespace FlaxEngine
|
||||
/// </summary>
|
||||
/// <param name="format">The format.</param>
|
||||
/// <param name="formatProvider">The format provider.</param>
|
||||
/// <returns>
|
||||
/// A <see cref="System.String" /> that represents this instance.
|
||||
/// </returns>
|
||||
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
|
||||
public string ToString(string format, IFormatProvider formatProvider)
|
||||
{
|
||||
if (format == null)
|
||||
@@ -486,9 +485,7 @@ namespace FlaxEngine
|
||||
/// <summary>
|
||||
/// Returns a hash code for this instance.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
|
||||
/// </returns>
|
||||
/// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
@@ -501,9 +498,7 @@ namespace FlaxEngine
|
||||
/// Determines whether the specified <see cref="Vector4" /> is equal to this instance.
|
||||
/// </summary>
|
||||
/// <param name="value">The <see cref="Vector4" /> to compare with this instance.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the specified <see cref="Vector4" /> is equal to this instance; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
/// <returns><c>true</c> if the specified <see cref="Vector4" /> is equal to this instance; otherwise, <c>false</c>.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(ref BoundingSphere value)
|
||||
{
|
||||
@@ -514,9 +509,7 @@ namespace FlaxEngine
|
||||
/// Determines whether the specified <see cref="Vector4" /> is equal to this instance.
|
||||
/// </summary>
|
||||
/// <param name="value">The <see cref="Vector4" /> to compare with this instance.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the specified <see cref="Vector4" /> is equal to this instance; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
/// <returns><c>true</c> if the specified <see cref="Vector4" /> is equal to this instance; otherwise, <c>false</c>.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(BoundingSphere value)
|
||||
{
|
||||
@@ -527,14 +520,11 @@ namespace FlaxEngine
|
||||
/// Determines whether the specified <see cref="System.Object" /> is equal to this instance.
|
||||
/// </summary>
|
||||
/// <param name="value">The <see cref="System.Object" /> to compare with this instance.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
/// <returns><c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.</returns>
|
||||
public override bool Equals(object value)
|
||||
{
|
||||
if (!(value is BoundingSphere))
|
||||
return false;
|
||||
|
||||
var strongValue = (BoundingSphere)value;
|
||||
return Equals(ref strongValue);
|
||||
}
|
||||
|
||||
@@ -218,6 +218,14 @@ public:
|
||||
/// <param name="value2">The point to merge.</param>
|
||||
/// <param name="result">When the method completes, contains the newly constructed bounding sphere.</param>
|
||||
static void Merge(const BoundingSphere& value1, const Vector3& value2, BoundingSphere& result);
|
||||
|
||||
/// <summary>
|
||||
/// Transforms the bounding sphere using the specified matrix.
|
||||
/// </summary>
|
||||
/// <param name="sphere">The sphere.</param>
|
||||
/// <param name="matrix">The matrix.</param>
|
||||
/// <param name="result">The result transformed sphere.</param>
|
||||
static void Transform(const BoundingSphere& sphere, const Matrix& matrix, BoundingSphere& result);
|
||||
};
|
||||
|
||||
template<>
|
||||
|
||||
@@ -53,9 +53,7 @@ namespace FlaxEngine
|
||||
/// Creates an <see cref="OrientedBoundingBox" /> from a BoundingBox.
|
||||
/// </summary>
|
||||
/// <param name="bb">The BoundingBox to create from.</param>
|
||||
/// <remarks>
|
||||
/// Initially, the OBB is axis-aligned box, but it can be rotated and transformed later.
|
||||
/// </remarks>
|
||||
/// <remarks>Initially, the OBB is axis-aligned box, but it can be rotated and transformed later.</remarks>
|
||||
public OrientedBoundingBox(BoundingBox bb)
|
||||
{
|
||||
Vector3 center = bb.Minimum + (bb.Maximum - bb.Minimum) / 2f;
|
||||
@@ -79,9 +77,7 @@ namespace FlaxEngine
|
||||
/// </summary>
|
||||
/// <param name="minimum">The minimum vertex of the bounding box.</param>
|
||||
/// <param name="maximum">The maximum vertex of the bounding box.</param>
|
||||
/// <remarks>
|
||||
/// Initially, the OrientedBoundingBox is axis-aligned box, but it can be rotated and transformed later.
|
||||
/// </remarks>
|
||||
/// <remarks>Initially, the OrientedBoundingBox is axis-aligned box, but it can be rotated and transformed later.</remarks>
|
||||
public OrientedBoundingBox(Vector3 minimum, Vector3 maximum)
|
||||
{
|
||||
Vector3 center = minimum + (maximum - minimum) / 2f;
|
||||
@@ -93,10 +89,7 @@ namespace FlaxEngine
|
||||
/// Creates an <see cref="OrientedBoundingBox" /> that fully contains the given points.
|
||||
/// </summary>
|
||||
/// <param name="points">The points that will be contained by the box.</param>
|
||||
/// <remarks>
|
||||
/// This method is not for computing the best tight-fitting OrientedBoundingBox.
|
||||
/// And initially, the OrientedBoundingBox is axis-aligned box, but it can be rotated and transformed later.
|
||||
/// </remarks>
|
||||
/// <remarks>This method is not for computing the best tight-fitting OrientedBoundingBox. And initially, the OrientedBoundingBox is axis-aligned box, but it can be rotated and transformed later.</remarks>
|
||||
public OrientedBoundingBox(Vector3[] points)
|
||||
{
|
||||
if ((points == null) || (points.Length == 0))
|
||||
@@ -231,8 +224,7 @@ namespace FlaxEngine
|
||||
/// <param name="mat">The transformation matrix.</param>
|
||||
/// <remarks>
|
||||
/// While any kind of transformation can be applied, it is recommended to apply scaling using scale method instead, which
|
||||
/// scales the Extents and keeps the Transformation matrix for rotation only, and that preserves collision detection
|
||||
/// accuracy.
|
||||
/// scales the Extents and keeps the Transformation matrix for rotation only, and that preserves collision detection accuracy.
|
||||
/// </remarks>
|
||||
public void Transform(ref Matrix mat)
|
||||
{
|
||||
@@ -245,8 +237,7 @@ namespace FlaxEngine
|
||||
/// <param name="mat">The transformation matrix.</param>
|
||||
/// <remarks>
|
||||
/// While any kind of transformation can be applied, it is recommended to apply scaling using scale method instead, which
|
||||
/// scales the Extents and keeps the Transformation matrix for rotation only, and that preserves collision detection
|
||||
/// accuracy.
|
||||
/// scales the Extents and keeps the Transformation matrix for rotation only, and that preserves collision detection accuracy.
|
||||
/// </remarks>
|
||||
public void Transform(Matrix mat)
|
||||
{
|
||||
@@ -304,21 +295,15 @@ namespace FlaxEngine
|
||||
/// <summary>
|
||||
/// The size of the <see cref="OrientedBoundingBox" /> if no scaling is applied to the transformation matrix.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The property will return the actual size even if the scaling is applied using Scale method,
|
||||
/// but if the scaling is applied to transformation matrix, use GetSize Function instead.
|
||||
/// <remarks>The property will return the actual size even if the scaling is applied using Scale method, but if the scaling is applied to transformation matrix, use GetSize Function instead.
|
||||
/// </remarks>
|
||||
public Vector3 Size => Extents * 2;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the size of the <see cref="OrientedBoundingBox" /> taking into consideration the scaling applied to the
|
||||
/// transformation matrix.
|
||||
/// Returns the size of the <see cref="OrientedBoundingBox" /> taking into consideration the scaling applied to the transformation matrix.
|
||||
/// </summary>
|
||||
/// <returns>The size of the consideration</returns>
|
||||
/// <remarks>
|
||||
/// This method is computationally expensive, so if no scale is applied to the transformation matrix
|
||||
/// use <see cref="OrientedBoundingBox.Size" /> property instead.
|
||||
/// </remarks>
|
||||
/// <remarks>This method is computationally expensive, so if no scale is applied to the transformation matrix use <see cref="OrientedBoundingBox.Size" /> property instead.</remarks>
|
||||
public Vector3 GetSize()
|
||||
{
|
||||
var xv = new Vector3(Extents.X * 2, 0, 0);
|
||||
@@ -332,8 +317,7 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the square size of the <see cref="OrientedBoundingBox" /> taking into consideration the scaling applied to
|
||||
/// the transformation matrix.
|
||||
/// Returns the square size of the <see cref="OrientedBoundingBox" /> taking into consideration the scaling applied to the transformation matrix.
|
||||
/// </summary>
|
||||
/// <returns>The size of the consideration</returns>
|
||||
public Vector3 GetSizeSquared()
|
||||
@@ -432,16 +416,9 @@ namespace FlaxEngine
|
||||
/// Determines whether a <see cref="OrientedBoundingBox" /> contains a <see cref="BoundingSphere" />.
|
||||
/// </summary>
|
||||
/// <param name="sphere">The sphere to test.</param>
|
||||
/// <param name="ignoreScale">
|
||||
/// Optimize the check operation by assuming that <see cref="OrientedBoundingBox" /> has no
|
||||
/// scaling applied
|
||||
/// </param>
|
||||
/// <param name="ignoreScale">Optimize the check operation by assuming that <see cref="OrientedBoundingBox" /> has no scaling applied.</param>
|
||||
/// <returns>The type of containment the two objects have.</returns>
|
||||
/// <remarks>
|
||||
/// This method is not designed for <see cref="OrientedBoundingBox" /> which has a non-uniform scaling applied to its
|
||||
/// transformation matrix.
|
||||
/// But any type of scaling applied using Scale method will keep this method accurate.
|
||||
/// </remarks>
|
||||
/// <remarks>This method is not designed for <see cref="OrientedBoundingBox" /> which has a non-uniform scaling applied to its transformation matrix. But any type of scaling applied using Scale method will keep this method accurate.</remarks>
|
||||
public ContainmentType Contains(BoundingSphere sphere, bool ignoreScale = false)
|
||||
{
|
||||
Matrix.Invert(ref Transformation, out Matrix invTrans);
|
||||
@@ -489,11 +466,7 @@ namespace FlaxEngine
|
||||
/// </summary>
|
||||
/// <param name="obb">The OrientedBoundingBox to test.</param>
|
||||
/// <returns>The type of containment the two objects have.</returns>
|
||||
/// <remarks>
|
||||
/// For accuracy, The transformation matrix for both <see cref="OrientedBoundingBox" /> must not have any scaling applied
|
||||
/// to it.
|
||||
/// Anyway, scaling using Scale method will keep this method accurate.
|
||||
/// </remarks>
|
||||
/// <remarks>For accuracy, The transformation matrix for both <see cref="OrientedBoundingBox" /> must not have any scaling applied to it. Anyway, scaling using Scale method will keep this method accurate.</remarks>
|
||||
public ContainmentType Contains(ref OrientedBoundingBox obb)
|
||||
{
|
||||
ContainmentType cornersCheck = Contains(obb.GetCorners());
|
||||
@@ -570,11 +543,7 @@ namespace FlaxEngine
|
||||
/// <param name="L1">The first point in the line.</param>
|
||||
/// <param name="L2">The second point in the line.</param>
|
||||
/// <returns>The type of containment the two objects have.</returns>
|
||||
/// <remarks>
|
||||
/// For accuracy, The transformation matrix for the <see cref="OrientedBoundingBox" /> must not have any scaling applied
|
||||
/// to it.
|
||||
/// Anyway, scaling using Scale method will keep this method accurate.
|
||||
/// </remarks>
|
||||
/// <remarks>For accuracy, The transformation matrix for the <see cref="OrientedBoundingBox" /> must not have any scaling applied to it. Anyway, scaling using Scale method will keep this method accurate.</remarks>
|
||||
public ContainmentType ContainsLine(ref Vector3 L1, ref Vector3 L2)
|
||||
{
|
||||
ContainmentType cornersCheck = Contains(new[]
|
||||
@@ -627,11 +596,7 @@ namespace FlaxEngine
|
||||
/// </summary>
|
||||
/// <param name="box">The BoundingBox to test.</param>
|
||||
/// <returns>The type of containment the two objects have.</returns>
|
||||
/// <remarks>
|
||||
/// For accuracy, The transformation matrix for the <see cref="OrientedBoundingBox" /> must not have any scaling applied
|
||||
/// to it.
|
||||
/// Anyway, scaling using Scale method will keep this method accurate.
|
||||
/// </remarks>
|
||||
/// <remarks>For accuracy, The transformation matrix for the <see cref="OrientedBoundingBox" /> must not have any scaling applied to it. Anyway, scaling using Scale method will keep this method accurate.</remarks>
|
||||
public ContainmentType Contains(ref BoundingBox box)
|
||||
{
|
||||
ContainmentType cornersCheck = Contains(box.GetCorners());
|
||||
@@ -704,10 +669,7 @@ namespace FlaxEngine
|
||||
/// Determines whether there is an intersection between a <see cref="Ray" /> and a <see cref="OrientedBoundingBox" />.
|
||||
/// </summary>
|
||||
/// <param name="ray">The ray to test.</param>
|
||||
/// <param name="point">
|
||||
/// When the method completes, contains the point of intersection,
|
||||
/// or <see cref="Vector3.Zero" /> if there was no intersection.
|
||||
/// </param>
|
||||
/// <param name="point">When the method completes, contains the point of intersection, or <see cref="Vector3.Zero" /> if there was no intersection.</param>
|
||||
/// <returns>Whether the two objects intersected.</returns>
|
||||
public bool Intersects(ref Ray ray, out Vector3 point)
|
||||
{
|
||||
@@ -718,11 +680,11 @@ namespace FlaxEngine
|
||||
Vector3.TransformNormal(ref ray.Direction, ref invTrans, out bRay.Direction);
|
||||
Vector3.TransformCoordinate(ref ray.Position, ref invTrans, out bRay.Position);
|
||||
|
||||
//Perform a regular ray to BoundingBox check
|
||||
// Perform a regular ray to BoundingBox check
|
||||
var bb = new BoundingBox(-Extents, Extents);
|
||||
bool intersects = CollisionsHelper.RayIntersectsBox(ref bRay, ref bb, out point);
|
||||
|
||||
//Put the result intersection back to world
|
||||
// Put the result intersection back to world
|
||||
if (intersects)
|
||||
Vector3.TransformCoordinate(ref point, ref Transformation, out point);
|
||||
|
||||
@@ -733,10 +695,7 @@ namespace FlaxEngine
|
||||
/// Determines whether there is an intersection between a <see cref="Ray" /> and a <see cref="OrientedBoundingBox" />.
|
||||
/// </summary>
|
||||
/// <param name="ray">The ray to test.</param>
|
||||
/// <param name="distance">
|
||||
/// When the method completes, contains the distance of intersection from the ray start,
|
||||
/// or 0 if there was no intersection.
|
||||
/// </param>
|
||||
/// <param name="distance">When the method completes, contains the distance of intersection from the ray start, or 0 if there was no intersection.</param>
|
||||
/// <returns>Whether the two objects intersected.</returns>
|
||||
public bool Intersects(ref Ray ray, out float distance)
|
||||
{
|
||||
@@ -788,16 +747,12 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the matrix required to transfer any point from one <see cref="OrientedBoundingBox" /> local coordinates to
|
||||
/// another.
|
||||
/// Calculates the matrix required to transfer any point from one <see cref="OrientedBoundingBox" /> local coordinates to another.
|
||||
/// </summary>
|
||||
/// <param name="A">The source OrientedBoundingBox.</param>
|
||||
/// <param name="B">The target OrientedBoundingBox.</param>
|
||||
/// <param name="NoMatrixScaleApplied">
|
||||
/// If true, the method will use a fast algorithm which is inapplicable if a scale is applied to the transformation
|
||||
/// matrix of the OrientedBoundingBox.
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
/// <param name="NoMatrixScaleApplied">If true, the method will use a fast algorithm which is inapplicable if a scale is applied to the transformation matrix of the OrientedBoundingBox.</param>
|
||||
/// <returns>The matrix.</returns>
|
||||
public static Matrix GetBoxToBoxMatrix(ref OrientedBoundingBox A, ref OrientedBoundingBox B, bool NoMatrixScaleApplied = false)
|
||||
{
|
||||
Matrix AtoB_Matrix;
|
||||
@@ -828,19 +783,12 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merge an OrientedBoundingBox B into another OrientedBoundingBox A, by expanding A to contain B and keeping A
|
||||
/// orientation.
|
||||
/// Merge an OrientedBoundingBox B into another OrientedBoundingBox A, by expanding A to contain B and keeping A orientation.
|
||||
/// </summary>
|
||||
/// <param name="A">The <see cref="OrientedBoundingBox" /> to merge into it.</param>
|
||||
/// <param name="B">The <see cref="OrientedBoundingBox" /> to be merged</param>
|
||||
/// <param name="NoMatrixScaleApplied">
|
||||
/// If true, the method will use a fast algorithm which is inapplicable if a scale is applied to the transformation
|
||||
/// matrix of the OrientedBoundingBox.
|
||||
/// </param>
|
||||
/// <remarks>
|
||||
/// Unlike merging axis aligned boxes, The operation is not interchangeable, because it keeps A orientation and merge B
|
||||
/// into it.
|
||||
/// </remarks>
|
||||
/// <param name="NoMatrixScaleApplied">If true, the method will use a fast algorithm which is inapplicable if a scale is applied to the transformation matrix of the OrientedBoundingBox.</param>
|
||||
/// <remarks>Unlike merging axis aligned boxes, The operation is not interchangeable, because it keeps A orientation and merge B into it.</remarks>
|
||||
public static void Merge(ref OrientedBoundingBox A, ref OrientedBoundingBox B, bool NoMatrixScaleApplied = false)
|
||||
{
|
||||
Matrix AtoB_Matrix = GetBoxToBoxMatrix(ref A, ref B, NoMatrixScaleApplied);
|
||||
@@ -869,10 +817,7 @@ namespace FlaxEngine
|
||||
/// Merge this OrientedBoundingBox into another OrientedBoundingBox, keeping the other OrientedBoundingBox orientation.
|
||||
/// </summary>
|
||||
/// <param name="OBB">The other <see cref="OrientedBoundingBox" /> to merge into.</param>
|
||||
/// <param name="NoMatrixScaleApplied">
|
||||
/// If true, the method will use a fast algorithm which is inapplicable if a scale is applied to the transformation
|
||||
/// matrix of the OrientedBoundingBox.
|
||||
/// </param>
|
||||
/// <param name="NoMatrixScaleApplied">If true, the method will use a fast algorithm which is inapplicable if a scale is applied to the transformation matrix of the OrientedBoundingBox.</param>
|
||||
public void MergeInto(ref OrientedBoundingBox OBB, bool NoMatrixScaleApplied = false)
|
||||
{
|
||||
Merge(ref OBB, ref this, NoMatrixScaleApplied);
|
||||
@@ -882,10 +827,7 @@ namespace FlaxEngine
|
||||
/// Merge another OrientedBoundingBox into this OrientedBoundingBox.
|
||||
/// </summary>
|
||||
/// <param name="OBB">The other <see cref="OrientedBoundingBox" /> to merge into this OrientedBoundingBox.</param>
|
||||
/// <param name="NoMatrixScaleApplied">
|
||||
/// If true, the method will use a fast algorithm which is inapplicable if a scale is applied to the transformation
|
||||
/// matrix of the OrientedBoundingBox.
|
||||
/// </param>
|
||||
/// <param name="NoMatrixScaleApplied">If true, the method will use a fast algorithm which is inapplicable if a scale is applied to the transformation matrix of the OrientedBoundingBox.</param>
|
||||
public void Add(ref OrientedBoundingBox OBB, bool NoMatrixScaleApplied = false)
|
||||
{
|
||||
Merge(ref this, ref OBB, NoMatrixScaleApplied);
|
||||
@@ -895,9 +837,7 @@ namespace FlaxEngine
|
||||
/// Determines whether the specified <see cref="Vector4" /> is equal to this instance.
|
||||
/// </summary>
|
||||
/// <param name="value">The <see cref="Vector4" /> to compare with this instance.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the specified <see cref="Vector4" /> is equal to this instance; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
/// <returns><c>true</c> if the specified <see cref="Vector4" /> is equal to this instance; otherwise, <c>false</c>.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(ref OrientedBoundingBox value)
|
||||
{
|
||||
@@ -908,9 +848,7 @@ namespace FlaxEngine
|
||||
/// Determines whether the specified <see cref="Vector4" /> is equal to this instance.
|
||||
/// </summary>
|
||||
/// <param name="value">The <see cref="Vector4" /> to compare with this instance.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the specified <see cref="Vector4" /> is equal to this instance; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
/// <returns><c>true</c> if the specified <see cref="Vector4" /> is equal to this instance; otherwise, <c>false</c>.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(OrientedBoundingBox value)
|
||||
{
|
||||
@@ -921,9 +859,7 @@ namespace FlaxEngine
|
||||
/// Determines whether the specified <see cref="System.Object" /> is equal to this instance.
|
||||
/// </summary>
|
||||
/// <param name="value">The <see cref="System.Object" /> to compare with this instance.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
/// <returns><c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.</returns>
|
||||
public override bool Equals(object value)
|
||||
{
|
||||
if (!(value is OrientedBoundingBox))
|
||||
@@ -952,10 +888,7 @@ namespace FlaxEngine
|
||||
/// </summary>
|
||||
/// <param name="left">The first value to compare.</param>
|
||||
/// <param name="right">The second value to compare.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if <paramref name="left" /> has the same value as <paramref name="right" />; otherwise,
|
||||
/// <c>false</c>.
|
||||
/// </returns>
|
||||
/// <returns><c>true</c> if <paramref name="left" /> has the same value as <paramref name="right" />; otherwise, <c>false</c>.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(OrientedBoundingBox left, OrientedBoundingBox right)
|
||||
{
|
||||
@@ -967,10 +900,7 @@ namespace FlaxEngine
|
||||
/// </summary>
|
||||
/// <param name="left">The first value to compare.</param>
|
||||
/// <param name="right">The second value to compare.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if <paramref name="left" /> has a different value than <paramref name="right" />; otherwise,
|
||||
/// <c>false</c>.
|
||||
/// </returns>
|
||||
/// <returns><c>true</c> if <paramref name="left" /> has a different value than <paramref name="right" />; otherwise, <c>false</c>.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(OrientedBoundingBox left, OrientedBoundingBox right)
|
||||
{
|
||||
@@ -980,9 +910,7 @@ namespace FlaxEngine
|
||||
/// <summary>
|
||||
/// Returns a hash code for this instance.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
|
||||
/// </returns>
|
||||
/// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Extents.GetHashCode() + Transformation.GetHashCode();
|
||||
@@ -991,9 +919,7 @@ namespace FlaxEngine
|
||||
/// <summary>
|
||||
/// Returns a <see cref="System.String" /> that represents this instance.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A <see cref="System.String" /> that represents this instance.
|
||||
/// </returns>
|
||||
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, "Center: {0}, Extents: {1}", Center, Extents);
|
||||
@@ -1003,9 +929,7 @@ namespace FlaxEngine
|
||||
/// Returns a <see cref="System.String" /> that represents this instance.
|
||||
/// </summary>
|
||||
/// <param name="format">The format.</param>
|
||||
/// <returns>
|
||||
/// A <see cref="System.String" /> that represents this instance.
|
||||
/// </returns>
|
||||
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
|
||||
public string ToString(string format)
|
||||
{
|
||||
if (format == null)
|
||||
@@ -1019,9 +943,7 @@ namespace FlaxEngine
|
||||
/// Returns a <see cref="System.String" /> that represents this instance.
|
||||
/// </summary>
|
||||
/// <param name="formatProvider">The format provider.</param>
|
||||
/// <returns>
|
||||
/// A <see cref="System.String" /> that represents this instance.
|
||||
/// </returns>
|
||||
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
|
||||
public string ToString(IFormatProvider formatProvider)
|
||||
{
|
||||
return string.Format(formatProvider, "Center: {0}, Extents: {1}", Center.ToString(), Extents.ToString());
|
||||
@@ -1032,9 +954,7 @@ namespace FlaxEngine
|
||||
/// </summary>
|
||||
/// <param name="format">The format.</param>
|
||||
/// <param name="formatProvider">The format provider.</param>
|
||||
/// <returns>
|
||||
/// A <see cref="System.String" /> that represents this instance.
|
||||
/// </returns>
|
||||
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
|
||||
public string ToString(string format, IFormatProvider formatProvider)
|
||||
{
|
||||
if (format == null)
|
||||
|
||||
@@ -250,6 +250,16 @@ namespace FlaxEngine
|
||||
/// </summary>
|
||||
public float ValuesSum => X + Y + Z;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a vector with values being absolute values of that vector.
|
||||
/// </summary>
|
||||
public Vector3 Absolute => new Vector3(Mathf.Abs(X), Mathf.Abs(Y), Mathf.Abs(Z));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a vector with values being opposite to values of that vector.
|
||||
/// </summary>
|
||||
public Vector3 Negative => new Vector3(-X, -Y, -Z);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the component at the specified index.
|
||||
/// </summary>
|
||||
@@ -294,8 +304,7 @@ namespace FlaxEngine
|
||||
/// </summary>
|
||||
/// <returns>The length of the vector.</returns>
|
||||
/// <remarks>
|
||||
/// <see cref="Vector3.LengthSquared" /> may be preferred when only the relative length is needed
|
||||
/// and speed is of the essence.
|
||||
/// <see cref="Vector3.LengthSquared" /> may be preferred when only the relative length is needed and speed is of the essence.
|
||||
/// </remarks>
|
||||
public float Length => (float)Math.Sqrt(X * X + Y * Y + Z * Z);
|
||||
|
||||
@@ -304,8 +313,7 @@ namespace FlaxEngine
|
||||
/// </summary>
|
||||
/// <returns>The squared length of the vector.</returns>
|
||||
/// <remarks>
|
||||
/// This method may be preferred to <see cref="Vector3.Length" /> when only a relative length is needed
|
||||
/// and speed is of the essence.
|
||||
/// This method may be preferred to <see cref="Vector3.Length" /> when only a relative length is needed and speed is of the essence.
|
||||
/// </remarks>
|
||||
public float LengthSquared => X * X + Y * Y + Z * Z;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user