diff --git a/Source/Engine/Core/Math/Double2.h b/Source/Engine/Core/Math/Double2.h
index fe30f032b..5703db105 100644
--- a/Source/Engine/Core/Math/Double2.h
+++ b/Source/Engine/Core/Math/Double2.h
@@ -19,7 +19,7 @@ struct Color;
struct Matrix;
///
-/// Represents a two dimensional mathematical vector.
+/// Represents a two dimensional mathematical vector with 64-bit precision (per-component).
///
API_STRUCT() struct FLAXENGINE_API Double2
{
@@ -115,7 +115,7 @@ public:
// Init
// @param v Vector2 to use X and Y components
- explicit Double2(const Vector2& xy);
+ Double2(const Vector2& xy);
// Init
// @param v Vector3 to use X and Y components
diff --git a/Source/Engine/Core/Math/Double3.h b/Source/Engine/Core/Math/Double3.h
index a27056066..908a0b74c 100644
--- a/Source/Engine/Core/Math/Double3.h
+++ b/Source/Engine/Core/Math/Double3.h
@@ -19,7 +19,7 @@ struct Color;
struct Matrix;
///
-/// Represents a two dimensional mathematical vector.
+/// Represents a two dimensional mathematical vector with 64-bit precision (per-component).
///
API_STRUCT() struct FLAXENGINE_API Double3
{
@@ -146,7 +146,7 @@ public:
// Init
// @param xyz Vector3 value
- explicit Double3(const Vector3& xyz);
+ Double3(const Vector3& xyz);
// Init
// @param xyz Vector4 value
diff --git a/Source/Engine/Core/Math/Double4.h b/Source/Engine/Core/Math/Double4.h
index 7572c8184..461a5cc1a 100644
--- a/Source/Engine/Core/Math/Double4.h
+++ b/Source/Engine/Core/Math/Double4.h
@@ -2,11 +2,10 @@
#pragma once
-#include "Engine/Platform/Platform.h"
-#include "Engine/Core/Formatting.h"
-#include "Engine/Core/Templates.h"
#include "Math.h"
#include "Mathd.h"
+#include "Engine/Core/Formatting.h"
+#include "Engine/Core/Templates.h"
struct Double2;
struct Double3;
@@ -22,7 +21,7 @@ struct Int3;
struct Int4;
///
-/// Represents a four dimensional mathematical vector.
+/// Represents a four dimensional mathematical vector with 64-bit precision (per-component).
///
API_STRUCT() struct FLAXENGINE_API Double4
{
@@ -140,7 +139,7 @@ public:
// Init
// @param xyzw Vector4 value
- explicit Double4(const Vector4& xyzw);
+ Double4(const Vector4& xyzw);
// Init
// @param xy X and Y values in the vector
diff --git a/Source/Engine/Core/Math/Mathd.cs b/Source/Engine/Core/Math/Mathd.cs
index a20c633de..447eb4a9d 100644
--- a/Source/Engine/Core/Math/Mathd.cs
+++ b/Source/Engine/Core/Math/Mathd.cs
@@ -1,4 +1,4 @@
-// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
+// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
using System;
using System.ComponentModel;
@@ -49,7 +49,7 @@ namespace FlaxEngine
{
return Math.Abs(f);
}
-
+
///
/// Returns the arc-cosine of f - the angle in radians whose cosine is f.
///
@@ -388,7 +388,7 @@ namespace FlaxEngine
{
return (long)Math.Round(f);
}
-
+
///
/// Returns the sign of f.
///
@@ -444,8 +444,7 @@ namespace FlaxEngine
/// The maximum speed.
/// The delta time (in seconds) since last update.
/// The smoothed value.
- public static double SmoothDamp(double current, double target, ref double currentVelocity, double smoothTime, [DefaultValue("double.PositiveInfinity")]
- double maxSpeed, [DefaultValue("Time.DeltaTime")] double deltaTime)
+ public static double SmoothDamp(double current, double target, ref double currentVelocity, double smoothTime, [DefaultValue("double.PositiveInfinity")] double maxSpeed, [DefaultValue("Time.DeltaTime")] double deltaTime)
{
smoothTime = Max(0.0001d, smoothTime);
double a = 2d / smoothTime;
@@ -504,8 +503,7 @@ namespace FlaxEngine
/// The maximum speed.
/// The delta time (in seconds) since last update.
/// The smoothed value.
- public static double SmoothDampAngle(double current, double target, ref double currentVelocity, double smoothTime, [DefaultValue("double.PositiveInfinity")]
- double maxSpeed, [DefaultValue("Time.DeltaTime")] double deltaTime)
+ public static double SmoothDampAngle(double current, double target, ref double currentVelocity, double smoothTime, [DefaultValue("double.PositiveInfinity")] double maxSpeed, [DefaultValue("Time.DeltaTime")] double deltaTime)
{
target = current + DeltaAngle(current, target);
return SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime);
diff --git a/Source/Engine/Core/Math/Mathd.h b/Source/Engine/Core/Math/Mathd.h
index 254e67f30..128e0a3d9 100644
--- a/Source/Engine/Core/Math/Mathd.h
+++ b/Source/Engine/Core/Math/Mathd.h
@@ -2,8 +2,8 @@
#pragma once
-#include
#include "Engine/Core/Types/BaseTypes.h"
+#include
namespace Math
{
diff --git a/Source/Engine/Core/Math/Vector2.cs b/Source/Engine/Core/Math/Vector2.cs
index 0b3de37ac..09839c052 100644
--- a/Source/Engine/Core/Math/Vector2.cs
+++ b/Source/Engine/Core/Math/Vector2.cs
@@ -218,7 +218,6 @@ namespace FlaxEngine
}
throw new ArgumentOutOfRangeException(nameof(index), "Indices for Vector2 run from 0 to 1, inclusive.");
}
-
set
{
switch (index)
@@ -267,11 +266,7 @@ namespace FlaxEngine
///
public float[] ToArray()
{
- return new[]
- {
- X,
- Y
- };
+ return new[] { X, Y };
}
///
@@ -297,7 +292,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise addition
+ /// Performs a component-wise addition.
///
/// The input vector
/// The scalar value to be added to elements
@@ -308,7 +303,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise addition
+ /// Performs a component-wise addition.
///
/// The input vector
/// The scalar value to be added to elements
@@ -341,7 +336,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The input vector
/// The scalar value to be subtracted from elements
@@ -352,7 +347,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The input vector
/// The scalar value to be subtracted from elements
@@ -363,7 +358,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The scalar value to be subtracted from elements
/// The input vector
@@ -374,7 +369,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The scalar value to be subtracted from elements
/// The input vector
@@ -536,11 +531,9 @@ namespace FlaxEngine
float x = value.X;
x = x > max.X ? max.X : x;
x = x < min.X ? min.X : x;
-
float y = value.Y;
y = y > max.Y ? max.Y : y;
y = y < min.Y ? min.Y : y;
-
result = new Vector2(x, y);
}
@@ -626,14 +619,6 @@ namespace FlaxEngine
/// The first vector.
/// The second vector
/// When the method completes, contains the squared distance between the two vectors.
- ///
- /// Distance squared is the value before taking the square root.
- /// Distance squared can often be used in place of distance if relative comparisons are being made.
- /// For example, consider three points A, B, and C. To determine whether B or C is further from A,
- /// compare the distance between A and B to the distance between A and C. Calculating the two distances
- /// involves two square roots, which are computationally expensive. However, using distance squared
- /// provides the same information and avoids calculating two square roots.
- ///
public static void DistanceSquared(ref Vector2 value1, ref Vector2 value2, out float result)
{
float x = value1.X - value2.X;
@@ -647,14 +632,6 @@ namespace FlaxEngine
/// The first vector.
/// The second vector
/// The squared distance between the two vectors.
- ///
- /// Distance squared is the value before taking the square root.
- /// Distance squared can often be used in place of distance if relative comparisons are being made.
- /// For example, consider three points A, B, and C. To determine whether B or C is further from A,
- /// compare the distance between A and B to the distance between A and C. Calculating the two distances
- /// involves two square roots, which are computationally expensive. However, using distance squared
- /// provides the same information and avoids calculating two square roots.
- ///
public static float DistanceSquared(ref Vector2 value1, ref Vector2 value2)
{
float x = value1.X - value2.X;
@@ -668,14 +645,6 @@ namespace FlaxEngine
/// The first vector.
/// The second vector.
/// The squared distance between the two vectors.
- ///
- /// Distance squared is the value before taking the square root.
- /// Distance squared can often be used in place of distance if relative comparisons are being made.
- /// For example, consider three points A, B, and C. To determine whether B or C is further from A,
- /// compare the distance between A and B to the distance between A and C. Calculating the two distances
- /// involves two square roots, which are computationally expensive. However, using distance squared
- /// provides the same information and avoids calculating two square roots.
- ///
public static float DistanceSquared(Vector2 value1, Vector2 value2)
{
float x = value1.X - value2.X;
@@ -813,8 +782,8 @@ namespace FlaxEngine
/// Max Length
public static Vector2 ClampLength(Vector2 vector, float min, float max)
{
- ClampLength(ref vector, min, max, out Vector2 retVect);
- return retVect;
+ ClampLength(vector, min, max, out Vector2 result);
+ return result;
}
///
@@ -823,24 +792,22 @@ namespace FlaxEngine
/// Input Vector.
/// Min Length
/// Max Length
- /// The Return Vector
- public static void ClampLength(ref Vector2 vector, float min, float max, out Vector2 retVect)
+ /// The result value.
+ public static void ClampLength(Vector2 vector, float min, float max, out Vector2 result)
{
- retVect.X = vector.X;
- retVect.Y = vector.Y;
-
- float lenSq = retVect.LengthSquared;
+ result = vector;
+ float lenSq = result.LengthSquared;
if (lenSq > max * max)
{
float scaleFactor = max / (float)Math.Sqrt(lenSq);
- retVect.X = retVect.X * scaleFactor;
- retVect.Y = retVect.Y * scaleFactor;
+ result.X *= scaleFactor;
+ result.Y *= scaleFactor;
}
if (lenSq < min * min)
{
float scaleFactor = min / (float)Math.Sqrt(lenSq);
- retVect.X = retVect.X * scaleFactor;
- retVect.Y = retVect.Y * scaleFactor;
+ result.X *= scaleFactor;
+ result.Y *= scaleFactor;
}
}
@@ -973,7 +940,6 @@ namespace FlaxEngine
float part2 = -2.0f * cubed + 3.0f * squared;
float part3 = cubed - 2.0f * squared + amount;
float part4 = cubed - squared;
-
result.X = value1.X * part1 + value2.X * part2 + tangent1.X * part3 + tangent2.X * part4;
result.Y = value1.Y * part1 + value2.Y * part2 + tangent1.Y * part3 + tangent2.Y * part4;
}
@@ -1026,11 +992,9 @@ namespace FlaxEngine
{
float squared = amount * amount;
float cubed = amount * squared;
-
result.X = 0.5f * (2.0f * value2.X + (-value1.X + value3.X) * amount +
(2.0f * value1.X - 5.0f * value2.X + 4.0f * value3.X - value4.X) * squared +
(-value1.X + 3.0f * value2.X - 3.0f * value3.X + value4.X) * cubed);
-
result.Y = 0.5f * (2.0f * value2.Y + (-value1.Y + value3.Y) * amount +
(2.0f * value1.Y - 5.0f * value2.Y + 4.0f * value3.Y - value4.Y) * squared +
(-value1.Y + 3.0f * value2.Y - 3.0f * value3.Y + value4.Y) * cubed);
@@ -1119,7 +1083,6 @@ namespace FlaxEngine
public static void Reflect(ref Vector2 vector, ref Vector2 normal, out Vector2 result)
{
float dot = vector.X * normal.X + vector.Y * normal.Y;
-
result.X = vector.X - 2.0f * dot * normal.X;
result.Y = vector.Y - 2.0f * dot * normal.Y;
}
@@ -1165,20 +1128,18 @@ namespace FlaxEngine
//q3 = m3 - ((q1 ⋅ m3) / (q1 ⋅ q1)) * q1 - ((q2 ⋅ m3) / (q2 ⋅ q2)) * q2
//q4 = m4 - ((q1 ⋅ m4) / (q1 ⋅ q1)) * q1 - ((q2 ⋅ m4) / (q2 ⋅ q2)) * q2 - ((q3 ⋅ m4) / (q3 ⋅ q3)) * q3
//q5 = ...
-
if (source == null)
throw new ArgumentNullException(nameof(source));
if (destination == null)
throw new ArgumentNullException(nameof(destination));
if (destination.Length < source.Length)
throw new ArgumentOutOfRangeException(nameof(destination), "The destination array must be of same length or larger length than the source array.");
-
for (var i = 0; i < source.Length; ++i)
{
- Vector2 newvector = source[i];
+ Vector2 v = source[i];
for (var r = 0; r < i; ++r)
- newvector -= Dot(destination[r], newvector) / Dot(destination[r], destination[r]) * destination[r];
- destination[i] = newvector;
+ v -= Dot(destination[r], v) / Dot(destination[r], destination[r]) * destination[r];
+ destination[i] = v;
}
}
@@ -1212,21 +1173,19 @@ namespace FlaxEngine
//q3 = (m3 - (q1 ⋅ m3) * q1 - (q2 ⋅ m3) * q2) / |m3 - (q1 ⋅ m3) * q1 - (q2 ⋅ m3) * q2|
//q4 = (m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3) / |m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3|
//q5 = ...
-
if (source == null)
throw new ArgumentNullException(nameof(source));
if (destination == null)
throw new ArgumentNullException(nameof(destination));
if (destination.Length < source.Length)
throw new ArgumentOutOfRangeException(nameof(destination), "The destination array must be of same length or larger length than the source array.");
-
for (var i = 0; i < source.Length; ++i)
{
- Vector2 newvector = source[i];
+ Vector2 v = source[i];
for (var r = 0; r < i; ++r)
- newvector -= Dot(destination[r], newvector) * destination[r];
- newvector.Normalize();
- destination[i] = newvector;
+ v -= Dot(destination[r], v) * destination[r];
+ v.Normalize();
+ destination[i] = v;
}
}
@@ -1277,7 +1236,6 @@ namespace FlaxEngine
throw new ArgumentNullException(nameof(destination));
if (destination.Length < source.Length)
throw new ArgumentOutOfRangeException(nameof(destination), "The destination array must be of same length or larger length than the source array.");
-
float x = rotation.X + rotation.X;
float y = rotation.Y + rotation.Y;
float z = rotation.Z + rotation.Z;
@@ -1286,16 +1244,12 @@ namespace FlaxEngine
float xy = rotation.X * y;
float yy = rotation.Y * y;
float zz = rotation.Z * z;
-
float num1 = 1.0f - yy - zz;
float num2 = xy - wz;
float num3 = xy + wz;
float num4 = 1.0f - xx - zz;
-
for (var i = 0; i < source.Length; ++i)
- destination[i] = new Vector2(
- source[i].X * num1 + source[i].Y * num2,
- source[i].X * num3 + source[i].Y * num4);
+ destination[i] = new Vector2(source[i].X * num1 + source[i].Y * num2, source[i].X * num3 + source[i].Y * num4);
}
///
@@ -1306,11 +1260,10 @@ namespace FlaxEngine
/// When the method completes, contains the transformed .
public static void Transform(ref Vector2 vector, ref Matrix transform, out Vector4 result)
{
- result = new Vector4(
- vector.X * transform.M11 + vector.Y * transform.M21 + transform.M41,
- vector.X * transform.M12 + vector.Y * transform.M22 + transform.M42,
- vector.X * transform.M13 + vector.Y * transform.M23 + transform.M43,
- vector.X * transform.M14 + vector.Y * transform.M24 + transform.M44);
+ result = new Vector4(vector.X * transform.M11 + vector.Y * transform.M21 + transform.M41,
+ vector.X * transform.M12 + vector.Y * transform.M22 + transform.M42,
+ vector.X * transform.M13 + vector.Y * transform.M23 + transform.M43,
+ vector.X * transform.M14 + vector.Y * transform.M24 + transform.M44);
}
///
@@ -1431,9 +1384,8 @@ namespace FlaxEngine
///
public static void TransformNormal(ref Vector2 normal, ref Matrix transform, out Vector2 result)
{
- result = new Vector2(
- normal.X * transform.M11 + normal.Y * transform.M21,
- normal.X * transform.M12 + normal.Y * transform.M22);
+ result = new Vector2(normal.X * transform.M11 + normal.Y * transform.M21,
+ normal.X * transform.M12 + normal.Y * transform.M22);
}
///
@@ -1474,13 +1426,10 @@ namespace FlaxEngine
{
if (source == null)
throw new ArgumentNullException(nameof(source));
-
if (destination == null)
throw new ArgumentNullException(nameof(destination));
-
if (destination.Length < source.Length)
throw new ArgumentOutOfRangeException(nameof(destination), "The destination array must be of same length or larger length than the source array.");
-
for (var i = 0; i < source.Length; ++i)
TransformNormal(ref source[i], ref transform, out destination[i]);
}
@@ -1627,7 +1576,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise addition
+ /// Performs a component-wise addition.
///
/// The input vector.
/// The scalar value to be added on elements
@@ -1638,7 +1587,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise addition
+ /// Performs a component-wise addition.
///
/// The input vector.
/// The scalar value to be added on elements
@@ -1649,7 +1598,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The input vector.
/// The scalar value to be subtracted from elements
@@ -1660,7 +1609,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The input vector.
/// The scalar value to be subtracted from elements
diff --git a/Source/Engine/Core/Math/Vector2.h b/Source/Engine/Core/Math/Vector2.h
index cb81ea164..94837533d 100644
--- a/Source/Engine/Core/Math/Vector2.h
+++ b/Source/Engine/Core/Math/Vector2.h
@@ -18,7 +18,7 @@ struct Color;
struct Matrix;
///
-/// Represents a two dimensional mathematical vector.
+/// Represents a two dimensional mathematical vector with 32-bit precision (per-component).
///
API_STRUCT() struct FLAXENGINE_API Vector2
{
@@ -112,7 +112,7 @@ public:
// Init
// @param xy Double2 to use X and Y components
- explicit Vector2(const Double2& xy);
+ Vector2(const Double2& xy);
// Init
// @param xyz Double3 to use X and Y components
diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs
index 538992ddb..e9ec2b0c1 100644
--- a/Source/Engine/Core/Math/Vector3.cs
+++ b/Source/Engine/Core/Math/Vector3.cs
@@ -279,7 +279,6 @@ namespace FlaxEngine
}
throw new ArgumentOutOfRangeException(nameof(index), "Indices for Vector3 run from 0 to 2, inclusive.");
}
-
set
{
switch (index)
@@ -353,12 +352,7 @@ namespace FlaxEngine
/// A three-element array containing the components of the vector.
public float[] ToArray()
{
- return new[]
- {
- X,
- Y,
- Z
- };
+ return new[] { X, Y, Z };
}
///
@@ -384,7 +378,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise addition
+ /// Performs a component-wise addition.
///
/// The input vector
/// The scalar value to be added to elements
@@ -395,7 +389,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise addition
+ /// Performs a component-wise addition.
///
/// The input vector
/// The scalar value to be added to elements
@@ -428,7 +422,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The input vector
/// The scalar value to be subtracted from elements
@@ -439,7 +433,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The input vector
/// The scalar value to be subtracted from elements
@@ -450,7 +444,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The scalar value to be subtracted from elements
/// The input vector.
@@ -461,7 +455,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The scalar value to be subtracted from elements
/// The input vector.
@@ -602,8 +596,7 @@ namespace FlaxEngine
}
///
- /// Returns a containing the 3D Cartesian coordinates of a point specified in Barycentric
- /// coordinates relative to a 3D triangle.
+ /// Returns a containing the 3D Cartesian coordinates of a point specified in Barycentric coordinates relative to a 3D triangle.
///
/// A containing the 3D Cartesian coordinates of vertex 1 of the triangle.
/// A containing the 3D Cartesian coordinates of vertex 2 of the triangle.
@@ -619,8 +612,7 @@ namespace FlaxEngine
}
///
- /// Returns a containing the 3D Cartesian coordinates of a point specified in Barycentric
- /// coordinates relative to a 3D triangle.
+ /// Returns a containing the 3D Cartesian coordinates of a point specified in Barycentric coordinates relative to a 3D triangle.
///
/// A containing the 3D Cartesian coordinates of vertex 1 of the triangle.
/// A containing the 3D Cartesian coordinates of vertex 2 of the triangle.
@@ -646,15 +638,12 @@ namespace FlaxEngine
float x = value.X;
x = x > max.X ? max.X : x;
x = x < min.X ? min.X : x;
-
float y = value.Y;
y = y > max.Y ? max.Y : y;
y = y < min.Y ? min.Y : y;
-
float z = value.Z;
z = z > max.Z ? max.Z : z;
z = z < min.Z ? min.Z : z;
-
result = new Vector3(x, y, z);
}
@@ -747,14 +736,6 @@ namespace FlaxEngine
/// The first vector.
/// The second vector.
/// When the method completes, contains the squared distance between the two vectors.
- ///
- /// Distance squared is the value before taking the square root.
- /// Distance squared can often be used in place of distance if relative comparisons are being made.
- /// For example, consider three points A, B, and C. To determine whether B or C is further from A,
- /// compare the distance between A and B to the distance between A and C. Calculating the two distances
- /// involves two square roots, which are computationally expensive. However, using distance squared
- /// provides the same information and avoids calculating two square roots.
- ///
public static void DistanceSquared(ref Vector3 value1, ref Vector3 value2, out float result)
{
float x = value1.X - value2.X;
@@ -769,14 +750,6 @@ namespace FlaxEngine
/// The first vector.
/// The second vector.
/// The squared distance between the two vectors.
- ///
- /// Distance squared is the value before taking the square root.
- /// Distance squared can often be used in place of distance if relative comparisons are being made.
- /// For example, consider three points A, B, and C. To determine whether B or C is further from A,
- /// compare the distance between A and B to the distance between A and C. Calculating the two distances
- /// involves two square roots, which are computationally expensive. However, using distance squared
- /// provides the same information and avoids calculating two square roots.
- ///
public static float DistanceSquared(ref Vector3 value1, ref Vector3 value2)
{
float x = value1.X - value2.X;
@@ -791,14 +764,6 @@ namespace FlaxEngine
/// The first vector.
/// The second vector.
/// The squared distance between the two vectors.
- ///
- /// Distance squared is the value before taking the square root.
- /// Distance squared can often be used in place of distance if relative comparisons are being made.
- /// For example, consider three points A, B, and C. To determine whether B or C is further from A,
- /// compare the distance between A and B to the distance between A and C. Calculating the two distances
- /// involves two square roots, which are computationally expensive. However, using distance squared
- /// provides the same information and avoids calculating two square roots.
- ///
public static float DistanceSquared(Vector3 value1, Vector3 value2)
{
float x = value1.X - value2.X;
@@ -982,7 +947,7 @@ namespace FlaxEngine
/// Max Length
public static Vector3 ClampLength(Vector3 vector, float min, float max)
{
- ClampLength(ref vector, min, max, out Vector3 retVect);
+ ClampLength(vector, min, max, out Vector3 retVect);
return retVect;
}
@@ -992,27 +957,26 @@ namespace FlaxEngine
/// Input Vector.
/// Min Length
/// Max Length
- /// The Return Vector
- public static void ClampLength(ref Vector3 vector, float min, float max, out Vector3 retVect)
+ /// The result vector.
+ public static void ClampLength(Vector3 vector, float min, float max, out Vector3 result)
{
- retVect.X = vector.X;
- retVect.Y = vector.Y;
- retVect.Z = vector.Z;
-
- float lenSq = retVect.LengthSquared;
+ result.X = vector.X;
+ result.Y = vector.Y;
+ result.Z = vector.Z;
+ float lenSq = result.LengthSquared;
if (lenSq > max * max)
{
float scaleFactor = max / (float)Math.Sqrt(lenSq);
- retVect.X = retVect.X * scaleFactor;
- retVect.Y = retVect.Y * scaleFactor;
- retVect.Z = retVect.Z * scaleFactor;
+ result.X *= scaleFactor;
+ result.Y *= scaleFactor;
+ result.Z *= scaleFactor;
}
if (lenSq < min * min)
{
float scaleFactor = min / (float)Math.Sqrt(lenSq);
- retVect.X = retVect.X * scaleFactor;
- retVect.Y = retVect.Y * scaleFactor;
- retVect.Z = retVect.Z * scaleFactor;
+ result.X *= scaleFactor;
+ result.Y *= scaleFactor;
+ result.Z *= scaleFactor;
}
}
@@ -1088,7 +1052,6 @@ namespace FlaxEngine
float part2 = -2.0f * cubed + 3.0f * squared;
float part3 = cubed - 2.0f * squared + amount;
float part4 = cubed - squared;
-
result.X = value1.X * part1 + value2.X * part2 + tangent1.X * part3 + tangent2.X * part4;
result.Y = value1.Y * part1 + value2.Y * part2 + tangent1.Y * part3 + tangent2.Y * part4;
result.Z = value1.Z * part1 + value2.Z * part2 + tangent1.Z * part3 + tangent2.Z * part4;
@@ -1122,15 +1085,12 @@ namespace FlaxEngine
{
float squared = amount * amount;
float cubed = amount * squared;
-
result.X = 0.5f * (2.0f * value2.X + (-value1.X + value3.X) * amount +
(2.0f * value1.X - 5.0f * value2.X + 4.0f * value3.X - value4.X) * squared +
(-value1.X + 3.0f * value2.X - 3.0f * value3.X + value4.X) * cubed);
-
result.Y = 0.5f * (2.0f * value2.Y + (-value1.Y + value3.Y) * amount +
(2.0f * value1.Y - 5.0f * value2.Y + 4.0f * value3.Y - value4.Y) * squared +
(-value1.Y + 3.0f * value2.Y - 3.0f * value3.Y + value4.Y) * cubed);
-
result.Z = 0.5f * (2.0f * value2.Z + (-value1.Z + value3.Z) * amount +
(2.0f * value1.Z - 5.0f * value2.Z + 4.0f * value3.Z - value4.Z) * squared +
(-value1.Z + 3.0f * value2.Z - 3.0f * value3.Z + value4.Z) * cubed);
@@ -1265,7 +1225,6 @@ namespace FlaxEngine
public static void Project(ref Vector3 vector, float x, float y, float width, float height, float minZ, float maxZ, ref Matrix worldViewProjection, out Vector3 result)
{
TransformCoordinate(ref vector, ref worldViewProjection, out var v);
-
result = new Vector3((1.0f + v.X) * 0.5f * width + x, (1.0f - v.Y) * 0.5f * height + y, v.Z * (maxZ - minZ) + minZ);
}
@@ -1301,13 +1260,13 @@ namespace FlaxEngine
/// When the method completes, contains the vector in object space.
public static void Unproject(ref Vector3 vector, float x, float y, float width, float height, float minZ, float maxZ, ref Matrix worldViewProjection, out Vector3 result)
{
- var v = new Vector3();
Matrix.Invert(ref worldViewProjection, out var matrix);
-
- v.X = (vector.X - x) / width * 2.0f - 1.0f;
- v.Y = -((vector.Y - y) / height * 2.0f - 1.0f);
- v.Z = (vector.Z - minZ) / (maxZ - minZ);
-
+ var v = new Vector3
+ {
+ X = (vector.X - x) / width * 2.0f - 1.0f,
+ Y = -((vector.Y - y) / height * 2.0f - 1.0f),
+ Z = (vector.Z - minZ) / (maxZ - minZ)
+ };
TransformCoordinate(ref v, ref matrix, out result);
}
@@ -1342,7 +1301,6 @@ namespace FlaxEngine
public static void Reflect(ref Vector3 vector, ref Vector3 normal, out Vector3 result)
{
float dot = vector.X * normal.X + vector.Y * normal.Y + vector.Z * normal.Z;
-
result.X = vector.X - 2.0f * dot * normal.X;
result.Y = vector.Y - 2.0f * dot * normal.Y;
result.Z = vector.Z - 2.0f * dot * normal.Z;
@@ -1389,22 +1347,18 @@ namespace FlaxEngine
//q3 = m3 - ((q1 ⋅ m3) / (q1 ⋅ q1)) * q1 - ((q2 ⋅ m3) / (q2 ⋅ q2)) * q2
//q4 = m4 - ((q1 ⋅ m4) / (q1 ⋅ q1)) * q1 - ((q2 ⋅ m4) / (q2 ⋅ q2)) * q2 - ((q3 ⋅ m4) / (q3 ⋅ q3)) * q3
//q5 = ...
-
if (source == null)
throw new ArgumentNullException(nameof(source));
if (destination == null)
throw new ArgumentNullException(nameof(destination));
if (destination.Length < source.Length)
throw new ArgumentOutOfRangeException(nameof(destination), "The destination array must be of same length or larger length than the source array.");
-
for (var i = 0; i < source.Length; ++i)
{
- Vector3 s = source[i];
-
+ Vector3 v = source[i];
for (var r = 0; r < i; ++r)
- s -= Dot(destination[r], s) / Dot(destination[r], destination[r]) * destination[r];
-
- destination[i] = s;
+ v -= Dot(destination[r], v) / Dot(destination[r], destination[r]) * destination[r];
+ destination[i] = v;
}
}
@@ -1438,23 +1392,19 @@ namespace FlaxEngine
//q3 = (m3 - (q1 ⋅ m3) * q1 - (q2 ⋅ m3) * q2) / |m3 - (q1 ⋅ m3) * q1 - (q2 ⋅ m3) * q2|
//q4 = (m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3) / |m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3|
//q5 = ...
-
if (source == null)
throw new ArgumentNullException(nameof(source));
if (destination == null)
throw new ArgumentNullException(nameof(destination));
if (destination.Length < source.Length)
throw new ArgumentOutOfRangeException(nameof(destination), "The destination array must be of same length or larger length than the source array.");
-
for (var i = 0; i < source.Length; ++i)
{
- Vector3 s = source[i];
-
+ Vector3 v = source[i];
for (var r = 0; r < i; ++r)
- s -= Dot(destination[r], s) * destination[r];
-
- s.Normalize();
- destination[i] = s;
+ v -= Dot(destination[r], v) * destination[r];
+ v.Normalize();
+ destination[i] = v;
}
}
@@ -1478,7 +1428,6 @@ namespace FlaxEngine
float yy = rotation.Y * y;
float yz = rotation.Y * z;
float zz = rotation.Z * z;
-
result = new Vector3(vector.X * (1.0f - yy - zz) + vector.Y * (xy - wz) + vector.Z * (xz + wy),
vector.X * (xy + wz) + vector.Y * (1.0f - xx - zz) + vector.Z * (yz - wx),
vector.X * (xz - wy) + vector.Y * (yz + wx) + vector.Z * (1.0f - xx - yy));
@@ -1512,7 +1461,6 @@ namespace FlaxEngine
throw new ArgumentNullException(nameof(destination));
if (destination.Length < source.Length)
throw new ArgumentOutOfRangeException(nameof(destination), "The destination array must be of same length or larger length than the source array.");
-
float x = rotation.X + rotation.X;
float y = rotation.Y + rotation.Y;
float z = rotation.Z + rotation.Z;
@@ -1525,7 +1473,6 @@ namespace FlaxEngine
float yy = rotation.Y * y;
float yz = rotation.Y * z;
float zz = rotation.Z * z;
-
float num1 = 1.0f - yy - zz;
float num2 = xy - wz;
float num3 = xz + wy;
@@ -1535,7 +1482,6 @@ namespace FlaxEngine
float num7 = xz - wy;
float num8 = yz + wx;
float num9 = 1.0f - xx - yy;
-
for (var i = 0; i < source.Length; i++)
{
destination[i] = new Vector3(source[i].X * num1 + source[i].Y * num2 + source[i].Z * num3,
@@ -1624,7 +1570,6 @@ namespace FlaxEngine
throw new ArgumentNullException(nameof(destination));
if (destination.Length < source.Length)
throw new ArgumentOutOfRangeException(nameof(destination), "The destination array must be of same length or larger length than the source array.");
-
for (var i = 0; i < source.Length; ++i)
Transform(ref source[i], ref transform, out destination[i]);
}
@@ -1651,7 +1596,6 @@ namespace FlaxEngine
Z = coordinate.X * transform.M13 + coordinate.Y * transform.M23 + coordinate.Z * transform.M33 + transform.M43,
W = 1f / (coordinate.X * transform.M14 + coordinate.Y * transform.M24 + coordinate.Z * transform.M34 + transform.M44)
};
-
result = new Vector3(vector.X * vector.W, vector.Y * vector.W, vector.Z * vector.W);
}
@@ -1699,7 +1643,6 @@ namespace FlaxEngine
throw new ArgumentNullException(nameof(destination));
if (destination.Length < source.Length)
throw new ArgumentOutOfRangeException(nameof(destination), "The destination array must be of same length or larger length than the source array.");
-
for (var i = 0; i < source.Length; i++)
TransformCoordinate(ref source[i], ref transform, out destination[i]);
}
@@ -1766,7 +1709,6 @@ namespace FlaxEngine
throw new ArgumentNullException(nameof(destination));
if (destination.Length < source.Length)
throw new ArgumentOutOfRangeException(nameof(destination), "The destination array must be of same length or larger length than the source array.");
-
for (var i = 0; i < source.Length; ++i)
TransformNormal(ref source[i], ref transform, out destination[i]);
}
@@ -1783,8 +1725,7 @@ namespace FlaxEngine
}
///
- /// Multiplies a vector with another by performing component-wise multiplication equivalent to
- /// .
+ /// Multiplies a vector with another by performing component-wise multiplication equivalent to .
///
/// The first vector to multiply.
/// The second vector to multiply.
@@ -1926,7 +1867,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise addition
+ /// Performs a component-wise addition.
///
/// The input vector.
/// The scalar value to be added on elements
@@ -1937,7 +1878,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise addition
+ /// Performs a component-wise addition.
///
/// The input vector.
/// The scalar value to be added on elements
@@ -1948,7 +1889,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The input vector.
/// The scalar value to be subtracted from elements
@@ -1959,7 +1900,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The input vector.
/// The scalar value to be subtracted from elements
diff --git a/Source/Engine/Core/Math/Vector3.h b/Source/Engine/Core/Math/Vector3.h
index b6c1ce7fb..2b8a7e880 100644
--- a/Source/Engine/Core/Math/Vector3.h
+++ b/Source/Engine/Core/Math/Vector3.h
@@ -19,7 +19,7 @@ struct Int3;
struct Int4;
///
-/// Represents a three dimensional mathematical vector.
+/// Represents a three dimensional mathematical vector with 32-bit precision (per-component).
///
API_STRUCT() struct FLAXENGINE_API Vector3
{
@@ -167,11 +167,11 @@ public:
// Init
// @param xyz Double3 value
- explicit Vector3(const Double3& xyz);
+ Vector3(const Double3& xyz);
// Init
// @param xyzw Double4 value
- explicit Vector3(const Double4& xyzw);
+ explicit Vector3(const Double4& xyzw);
// Init
// @param color Color value
diff --git a/Source/Engine/Core/Math/Vector4.cs b/Source/Engine/Core/Math/Vector4.cs
index 5048bd622..237132a20 100644
--- a/Source/Engine/Core/Math/Vector4.cs
+++ b/Source/Engine/Core/Math/Vector4.cs
@@ -263,7 +263,6 @@ namespace FlaxEngine
}
throw new ArgumentOutOfRangeException(nameof(index), "Indices for Vector4 run from 0 to 3, inclusive.");
}
-
set
{
switch (index)
@@ -321,13 +320,7 @@ namespace FlaxEngine
/// A four-element array containing the components of the vector.
public float[] ToArray()
{
- return new[]
- {
- X,
- Y,
- Z,
- W
- };
+ return new[] { X, Y, Z, W };
}
///
@@ -353,7 +346,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise addition
+ /// Performs a component-wise addition.
///
/// The input vector
/// The scalar value to be added to elements
@@ -364,7 +357,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise addition
+ /// Performs a component-wise addition.
///
/// The input vector
/// The scalar value to be added to elements
@@ -397,7 +390,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The input vector
/// The scalar value to be subtracted from elements
@@ -408,7 +401,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The input vector
/// The scalar value to be subtracted from elements
@@ -419,7 +412,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The scalar value to be subtracted from elements
/// The input vector.
@@ -430,7 +423,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The scalar value to be subtracted from elements
/// The input vector.
@@ -592,19 +585,15 @@ namespace FlaxEngine
float x = value.X;
x = x > max.X ? max.X : x;
x = x < min.X ? min.X : x;
-
float y = value.Y;
y = y > max.Y ? max.Y : y;
y = y < min.Y ? min.Y : y;
-
float z = value.Z;
z = z > max.Z ? max.Z : z;
z = z < min.Z ? min.Z : z;
-
float w = value.W;
w = w > max.W ? max.W : w;
w = w < min.W ? min.W : w;
-
result = new Vector4(x, y, z, w);
}
@@ -659,14 +648,6 @@ namespace FlaxEngine
/// The first vector.
/// The second vector.
/// When the method completes, contains the squared distance between the two vectors.
- ///
- /// Distance squared is the value before taking the square root.
- /// Distance squared can often be used in place of distance if relative comparisons are being made.
- /// For example, consider three points A, B, and C. To determine whether B or C is further from A,
- /// compare the distance between A and B to the distance between A and C. Calculating the two distances
- /// involves two square roots, which are computationally expensive. However, using distance squared
- /// provides the same information and avoids calculating two square roots.
- ///
public static void DistanceSquared(ref Vector4 value1, ref Vector4 value2, out float result)
{
float x = value1.X - value2.X;
@@ -682,14 +663,6 @@ namespace FlaxEngine
/// The first vector.
/// The second vector.
/// The squared distance between the two vectors.
- ///
- /// Distance squared is the value before taking the square root.
- /// Distance squared can often be used in place of distance if relative comparisons are being made.
- /// For example, consider three points A, B, and C. To determine whether B or C is further from A,
- /// compare the distance between A and B to the distance between A and C. Calculating the two distances
- /// involves two square roots, which are computationally expensive. However, using distance squared
- /// provides the same information and avoids calculating two square roots.
- ///
public static float DistanceSquared(Vector4 value1, Vector4 value2)
{
float x = value1.X - value2.X;
@@ -720,9 +693,7 @@ namespace FlaxEngine
/// true if left and right are near another, false otherwise
public static bool NearEqual(ref Vector4 left, ref Vector4 right, float epsilon = Mathf.Epsilon)
{
- return Mathf.WithinEpsilon(left.X, right.X, epsilon) &&
- Mathf.WithinEpsilon(left.Y, right.Y, epsilon) &&
- Mathf.WithinEpsilon(left.Z, right.Z, epsilon);
+ return Mathf.WithinEpsilon(left.X, right.X, epsilon) && Mathf.WithinEpsilon(left.Y, right.Y, epsilon) && Mathf.WithinEpsilon(left.Z, right.Z, epsilon) && Mathf.WithinEpsilon(left.W, right.W, epsilon);
}
///
@@ -754,8 +725,7 @@ namespace FlaxEngine
/// When the method completes, contains the normalized vector.
public static void Normalize(ref Vector4 value, out Vector4 result)
{
- Vector4 temp = value;
- result = temp;
+ result = value;
result.Normalize();
}
@@ -788,8 +758,8 @@ namespace FlaxEngine
/// Max Length
public static Vector4 ClampLength(Vector4 vector, float min, float max)
{
- ClampLength(ref vector, min, max, out Vector4 retVect);
- return retVect;
+ ClampLength(vector, min, max, out Vector4 result);
+ return result;
}
///
@@ -798,30 +768,26 @@ namespace FlaxEngine
/// Input Vector.
/// Min Length
/// Max Length
- /// The Return Vector
- public static void ClampLength(ref Vector4 vector, float min, float max, out Vector4 retVect)
+ /// The result vector.
+ public static void ClampLength(Vector4 vector, float min, float max, out Vector4 result)
{
- retVect.X = vector.X;
- retVect.Y = vector.Y;
- retVect.Z = vector.Z;
- retVect.W = vector.W;
-
- float lenSq = retVect.LengthSquared;
+ result = vector;
+ float lenSq = result.LengthSquared;
if (lenSq > max * max)
{
float scaleFactor = max / (float)Math.Sqrt(lenSq);
- retVect.X = retVect.X * scaleFactor;
- retVect.Y = retVect.Y * scaleFactor;
- retVect.Z = retVect.Z * scaleFactor;
- retVect.W = retVect.W * scaleFactor;
+ result.X *= scaleFactor;
+ result.Y *= scaleFactor;
+ result.Z *= scaleFactor;
+ result.W *= scaleFactor;
}
if (lenSq < min * min)
{
float scaleFactor = min / (float)Math.Sqrt(lenSq);
- retVect.X = retVect.X * scaleFactor;
- retVect.Y = retVect.Y * scaleFactor;
- retVect.Z = retVect.Z * scaleFactor;
- retVect.W = retVect.W * scaleFactor;
+ result.X *= scaleFactor;
+ result.Y *= scaleFactor;
+ result.Z *= scaleFactor;
+ result.W *= scaleFactor;
}
}
@@ -898,7 +864,6 @@ namespace FlaxEngine
float part2 = -2.0f * cubed + 3.0f * squared;
float part3 = cubed - 2.0f * squared + amount;
float part4 = cubed - squared;
-
result = new Vector4(value1.X * part1 + value2.X * part2 + tangent1.X * part3 + tangent2.X * part4,
value1.Y * part1 + value2.Y * part2 + tangent1.Y * part3 + tangent2.Y * part4,
value1.Z * part1 + value2.Z * part2 + tangent1.Z * part3 + tangent2.Z * part4,
@@ -933,7 +898,6 @@ namespace FlaxEngine
{
float squared = amount * amount;
float cubed = amount * squared;
-
result.X = 0.5f * (2.0f * value2.X + (-value1.X + value3.X) * amount + (2.0f * value1.X - 5.0f * value2.X + 4.0f * value3.X - value4.X) * squared + (-value1.X + 3.0f * value2.X - 3.0f * value3.X + value4.X) * cubed);
result.Y = 0.5f * (2.0f * value2.Y + (-value1.Y + value3.Y) * amount + (2.0f * value1.Y - 5.0f * value2.Y + 4.0f * value3.Y - value4.Y) * squared + (-value1.Y + 3.0f * value2.Y - 3.0f * value3.Y + value4.Y) * cubed);
result.Z = 0.5f * (2.0f * value2.Z + (-value1.Z + value3.Z) * amount + (2.0f * value1.Z - 5.0f * value2.Z + 4.0f * value3.Z - value4.Z) * squared + (-value1.Z + 3.0f * value2.Z - 3.0f * value3.Z + value4.Z) * cubed);
@@ -1045,22 +1009,18 @@ namespace FlaxEngine
//q3 = m3 - ((q1 ⋅ m3) / (q1 ⋅ q1)) * q1 - ((q2 ⋅ m3) / (q2 ⋅ q2)) * q2
//q4 = m4 - ((q1 ⋅ m4) / (q1 ⋅ q1)) * q1 - ((q2 ⋅ m4) / (q2 ⋅ q2)) * q2 - ((q3 ⋅ m4) / (q3 ⋅ q3)) * q3
//q5 = ...
-
if (source == null)
throw new ArgumentNullException(nameof(source));
if (destination == null)
throw new ArgumentNullException(nameof(destination));
if (destination.Length < source.Length)
throw new ArgumentOutOfRangeException(nameof(destination), "The destination array must be of same length or larger length than the source array.");
-
for (var i = 0; i < source.Length; ++i)
{
- Vector4 newvector = source[i];
-
+ Vector4 v = source[i];
for (var r = 0; r < i; ++r)
- newvector -= Dot(destination[r], newvector) / Dot(destination[r], destination[r]) * destination[r];
-
- destination[i] = newvector;
+ v -= Dot(destination[r], v) / Dot(destination[r], destination[r]) * destination[r];
+ destination[i] = v;
}
}
@@ -1094,23 +1054,19 @@ namespace FlaxEngine
//q3 = (m3 - (q1 ⋅ m3) * q1 - (q2 ⋅ m3) * q2) / |m3 - (q1 ⋅ m3) * q1 - (q2 ⋅ m3) * q2|
//q4 = (m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3) / |m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3|
//q5 = ...
-
if (source == null)
throw new ArgumentNullException(nameof(source));
if (destination == null)
throw new ArgumentNullException(nameof(destination));
if (destination.Length < source.Length)
throw new ArgumentOutOfRangeException(nameof(destination), "The destination array must be of same length or larger length than the source array.");
-
for (var i = 0; i < source.Length; ++i)
{
- Vector4 newvector = source[i];
-
+ Vector4 v = source[i];
for (var r = 0; r < i; ++r)
- newvector -= Dot(destination[r], newvector) * destination[r];
-
- newvector.Normalize();
- destination[i] = newvector;
+ v -= Dot(destination[r], v) * destination[r];
+ v.Normalize();
+ destination[i] = v;
}
}
@@ -1134,12 +1090,10 @@ namespace FlaxEngine
float yy = rotation.Y * y;
float yz = rotation.Y * z;
float zz = rotation.Z * z;
-
- result = new Vector4(
- vector.X * (1.0f - yy - zz) + vector.Y * (xy - wz) + vector.Z * (xz + wy),
- vector.X * (xy + wz) + vector.Y * (1.0f - xx - zz) + vector.Z * (yz - wx),
- vector.X * (xz - wy) + vector.Y * (yz + wx) + vector.Z * (1.0f - xx - yy),
- vector.W);
+ result = new Vector4(vector.X * (1.0f - yy - zz) + vector.Y * (xy - wz) + vector.Z * (xz + wy),
+ vector.X * (xy + wz) + vector.Y * (1.0f - xx - zz) + vector.Z * (yz - wx),
+ vector.X * (xz - wy) + vector.Y * (yz + wx) + vector.Z * (1.0f - xx - yy),
+ vector.W);
}
///
@@ -1170,7 +1124,6 @@ namespace FlaxEngine
throw new ArgumentNullException(nameof(destination));
if (destination.Length < source.Length)
throw new ArgumentOutOfRangeException(nameof(destination), "The destination array must be of same length or larger length than the source array.");
-
float x = rotation.X + rotation.X;
float y = rotation.Y + rotation.Y;
float z = rotation.Z + rotation.Z;
@@ -1183,7 +1136,6 @@ namespace FlaxEngine
float yy = rotation.Y * y;
float yz = rotation.Y * z;
float zz = rotation.Z * z;
-
float num1 = 1.0f - yy - zz;
float num2 = xy - wz;
float num3 = xz + wy;
@@ -1193,13 +1145,11 @@ namespace FlaxEngine
float num7 = xz - wy;
float num8 = yz + wx;
float num9 = 1.0f - xx - yy;
-
for (var i = 0; i < source.Length; ++i)
- destination[i] = new Vector4(
- source[i].X * num1 + source[i].Y * num2 + source[i].Z * num3,
- source[i].X * num4 + source[i].Y * num5 + source[i].Z * num6,
- source[i].X * num7 + source[i].Y * num8 + source[i].Z * num9,
- source[i].W);
+ destination[i] = new Vector4(source[i].X * num1 + source[i].Y * num2 + source[i].Z * num3,
+ source[i].X * num4 + source[i].Y * num5 + source[i].Z * num6,
+ source[i].X * num7 + source[i].Y * num8 + source[i].Z * num9,
+ source[i].W);
}
///
@@ -1210,11 +1160,10 @@ namespace FlaxEngine
/// When the method completes, contains the transformed .
public static void Transform(ref Vector4 vector, ref Matrix transform, out Vector4 result)
{
- result = new Vector4(
- vector.X * transform.M11 + vector.Y * transform.M21 + vector.Z * transform.M31 + vector.W * transform.M41,
- vector.X * transform.M12 + vector.Y * transform.M22 + vector.Z * transform.M32 + vector.W * transform.M42,
- vector.X * transform.M13 + vector.Y * transform.M23 + vector.Z * transform.M33 + vector.W * transform.M43,
- vector.X * transform.M14 + vector.Y * transform.M24 + vector.Z * transform.M34 + vector.W * transform.M44);
+ result = new Vector4(vector.X * transform.M11 + vector.Y * transform.M21 + vector.Z * transform.M31 + vector.W * transform.M41,
+ vector.X * transform.M12 + vector.Y * transform.M22 + vector.Z * transform.M32 + vector.W * transform.M42,
+ vector.X * transform.M13 + vector.Y * transform.M23 + vector.Z * transform.M33 + vector.W * transform.M43,
+ vector.X * transform.M14 + vector.Y * transform.M24 + vector.Z * transform.M34 + vector.W * transform.M44);
}
///
@@ -1245,7 +1194,6 @@ namespace FlaxEngine
throw new ArgumentNullException(nameof(destination));
if (destination.Length < source.Length)
throw new ArgumentOutOfRangeException(nameof(destination), "The destination array must be of same length or larger length than the source array.");
-
for (var i = 0; i < source.Length; ++i)
Transform(ref source[i], ref transform, out destination[i]);
}
@@ -1262,8 +1210,7 @@ namespace FlaxEngine
}
///
- /// Multiplies a vector with another by performing component-wise multiplication equivalent to
- /// .
+ /// Multiplies a vector with another by performing component-wise multiplication equivalent to .
///
/// The first vector to multiply.
/// The second vector to multiply.
@@ -1393,7 +1340,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise addition
+ /// Performs a component-wise addition.
///
/// The input vector.
/// The scalar value to be added on elements
@@ -1404,7 +1351,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise addition
+ /// Performs a component-wise addition.
///
/// The input vector.
/// The scalar value to be added on elements
@@ -1415,7 +1362,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The input vector.
/// The scalar value to be subtracted from elements
@@ -1426,7 +1373,7 @@ namespace FlaxEngine
}
///
- /// Perform a component-wise subtraction
+ /// Performs a component-wise subtraction.
///
/// The input vector.
/// The scalar value to be subtracted from elements
diff --git a/Source/Engine/Core/Math/Vector4.h b/Source/Engine/Core/Math/Vector4.h
index 2b3420f66..4521d7d63 100644
--- a/Source/Engine/Core/Math/Vector4.h
+++ b/Source/Engine/Core/Math/Vector4.h
@@ -2,10 +2,9 @@
#pragma once
-#include "Engine/Platform/Platform.h"
+#include "Math.h"
#include "Engine/Core/Formatting.h"
#include "Engine/Core/Templates.h"
-#include "Math.h"
struct Double2;
struct Double3;
@@ -21,7 +20,7 @@ struct Int3;
struct Int4;
///
-/// Represents a four dimensional mathematical vector.
+/// Represents a four dimensional mathematical vector with 32-bit precision (per-component).
///
API_STRUCT() struct FLAXENGINE_API Vector4
{
@@ -167,7 +166,7 @@ public:
// Init
// @param xyzw Double4 value
- explicit Vector4(const Double4& xyzw);
+ Vector4(const Double4& xyzw);
// Init
// @param color Color value