Refactor engine to support double-precision vectors

This commit is contained in:
Wojtek Figat
2022-06-13 00:40:32 +02:00
parent f82e370392
commit a881c90b2e
744 changed files with 19062 additions and 12467 deletions

View File

@@ -153,84 +153,84 @@ public:
String ToString() const;
public:
// Gets the up Vector3 of the matrix; that is M21, M22, and M23.
Vector3 GetUp() const
// Gets the up Float3 of the matrix; that is M21, M22, and M23.
Float3 GetUp() const
{
return Vector3(M21, M22, M23);
return Float3(M21, M22, M23);
}
// Sets Vector3 of the matrix; that is M21, M22, and M23.
void SetUp(const Vector3& value)
// Sets Float3 of the matrix; that is M21, M22, and M23.
void SetUp(const Float3& value)
{
M21 = value.X;
M22 = value.Y;
M23 = value.Z;
}
// Gets the down Vector3 of the matrix; that is -M21, -M22, and -M23.
Vector3 GetDown() const
// Gets the down Float3 of the matrix; that is -M21, -M22, and -M23.
Float3 GetDown() const
{
return -Vector3(M21, M22, M23);
return -Float3(M21, M22, M23);
}
// Sets the down Vector3 of the matrix; that is -M21, -M22, and -M23.
void SetDown(const Vector3& value)
// Sets the down Float3 of the matrix; that is -M21, -M22, and -M23.
void SetDown(const Float3& value)
{
M21 = -value.X;
M22 = -value.Y;
M23 = -value.Z;
}
// Gets the right Vector3 of the matrix; that is M11, M12, and M13.
Vector3 GetRight() const
// Gets the right Float3 of the matrix; that is M11, M12, and M13.
Float3 GetRight() const
{
return Vector3(M11, M12, M13);
return Float3(M11, M12, M13);
}
// Sets the right Vector3 of the matrix; that is M11, M12, and M13.
void SetRight(const Vector3& value)
// Sets the right Float3 of the matrix; that is M11, M12, and M13.
void SetRight(const Float3& value)
{
M11 = value.X;
M12 = value.Y;
M13 = value.Z;
}
// Gets the left Vector3 of the matrix; that is -M11, -M12, and -M13.
Vector3 GetLeft() const
// Gets the left Float3 of the matrix; that is -M11, -M12, and -M13.
Float3 GetLeft() const
{
return -Vector3(M11, M12, M13);
return -Float3(M11, M12, M13);
}
// Sets the left Vector3 of the matrix; that is -M11, -M12, and -M13.
void SetLeft(const Vector3& value)
// Sets the left Float3 of the matrix; that is -M11, -M12, and -M13.
void SetLeft(const Float3& value)
{
M11 = -value.X;
M12 = -value.Y;
M13 = -value.Z;
}
// Gets the forward Vector3 of the matrix; that is -M31, -M32, and -M33.
Vector3 GetForward() const
// Gets the forward Float3 of the matrix; that is -M31, -M32, and -M33.
Float3 GetForward() const
{
return -Vector3(M31, M32, M33);
return -Float3(M31, M32, M33);
}
// Sets the forward Vector3 of the matrix; that is -M31, -M32, and -M33.
void SetForward(const Vector3& value)
// Sets the forward Float3 of the matrix; that is -M31, -M32, and -M33.
void SetForward(const Float3& value)
{
M31 = -value.X;
M32 = -value.Y;
M33 = -value.Z;
}
// Gets the backward Vector3 of the matrix; that is M31, M32, and M33.
Vector3 GetBackward() const
// Gets the backward Float3 of the matrix; that is M31, M32, and M33.
Float3 GetBackward() const
{
return Vector3(M31, M32, M33);
return Float3(M31, M32, M33);
}
// Sets the backward Vector3 of the matrix; that is M31, M32, and M33.
void SetBackward(const Vector3& value)
// Sets the backward Float3 of the matrix; that is M31, M32, and M33.
void SetBackward(const Float3& value)
{
M31 = value.X;
M32 = value.Y;
@@ -238,13 +238,13 @@ public:
}
// Gets the first row in the matrix; that is M11, M12, M13, and M14.
Vector4 GetRow1() const
Float4 GetRow1() const
{
return Vector4(M11, M12, M13, M14);
return Float4(M11, M12, M13, M14);
}
// Sets the first row in the matrix; that is M11, M12, M13, and M14.
void SetRow1(const Vector4& value)
void SetRow1(const Float4& value)
{
M11 = value.X;
M12 = value.Y;
@@ -253,13 +253,13 @@ public:
}
// Gets the second row in the matrix; that is M21, M22, M23, and M24.
Vector4 GetRow2() const
Float4 GetRow2() const
{
return Vector4(M21, M22, M23, M24);
return Float4(M21, M22, M23, M24);
}
// Sets the second row in the matrix; that is M21, M22, M23, and M24.
void SetRow2(const Vector4& value)
void SetRow2(const Float4& value)
{
M21 = value.X;
M22 = value.Y;
@@ -268,13 +268,13 @@ public:
}
// Gets the third row in the matrix; that is M31, M32, M33, and M34.
Vector4 GetRow3() const
Float4 GetRow3() const
{
return Vector4(M31, M32, M33, M34);
return Float4(M31, M32, M33, M34);
}
// Sets the third row in the matrix; that is M31, M32, M33, and M34.
void SetRow3(const Vector4& value)
void SetRow3(const Float4& value)
{
M31 = value.X;
M32 = value.Y;
@@ -283,13 +283,13 @@ public:
}
// Gets the fourth row in the matrix; that is M41, M42, M43, and M44.
Vector4 GetRow4() const
Float4 GetRow4() const
{
return Vector4(M41, M42, M43, M44);
return Float4(M41, M42, M43, M44);
}
// Sets the fourth row in the matrix; that is M41, M42, M43, and M44.
void SetRow4(const Vector4& value)
void SetRow4(const Float4& value)
{
M41 = value.X;
M42 = value.Y;
@@ -298,13 +298,13 @@ public:
}
// Gets the first column in the matrix; that is M11, M21, M31, and M41.
Vector4 GetColumn1() const
Float4 GetColumn1() const
{
return Vector4(M11, M21, M31, M41);
return Float4(M11, M21, M31, M41);
}
// Sets the first column in the matrix; that is M11, M21, M31, and M41.
void SetColumn1(const Vector4& value)
void SetColumn1(const Float4& value)
{
M11 = value.X;
M21 = value.Y;
@@ -313,13 +313,13 @@ public:
}
// Gets the second column in the matrix; that is M12, M22, M32, and M42.
Vector4 GetColumn2() const
Float4 GetColumn2() const
{
return Vector4(M12, M22, M32, M42);
return Float4(M12, M22, M32, M42);
}
// Sets the second column in the matrix; that is M12, M22, M32, and M42.
void SetColumn2(const Vector4& value)
void SetColumn2(const Float4& value)
{
M12 = value.X;
M22 = value.Y;
@@ -328,13 +328,13 @@ public:
}
// Gets the third column in the matrix; that is M13, M23, M33, and M43.
Vector4 GetColumn3() const
Float4 GetColumn3() const
{
return Vector4(M13, M23, M33, M43);
return Float4(M13, M23, M33, M43);
}
// Sets the third column in the matrix; that is M13, M23, M33, and M43.
void SetColumn3(const Vector4& value)
void SetColumn3(const Float4& value)
{
M13 = value.X;
M23 = value.Y;
@@ -343,13 +343,13 @@ public:
}
// Gets the fourth column in the matrix; that is M14, M24, M34, and M44.
Vector4 GetColumn4() const
Float4 GetColumn4() const
{
return Vector4(M14, M24, M34, M44);
return Float4(M14, M24, M34, M44);
}
// Sets the fourth column in the matrix; that is M14, M24, M34, and M44.
void SetColumn4(const Vector4& value)
void SetColumn4(const Float4& value)
{
M14 = value.X;
M24 = value.Y;
@@ -358,7 +358,7 @@ public:
}
// Sets part of the first row in the matrix; that is M11, M12, M13.
void SetX(const Vector3& value)
void SetX(const Float3& value)
{
M11 = value.X;
M12 = value.Y;
@@ -366,7 +366,7 @@ public:
}
// Sets part of the second row in the matrix; that is M21, M22, M23.
void SetY(const Vector3& value)
void SetY(const Float3& value)
{
M21 = value.X;
M22 = value.Y;
@@ -374,7 +374,7 @@ public:
}
// Sets part of the third row in the matrix; that is M31, M32, M33.
void SetZ(const Vector3& value)
void SetZ(const Float3& value)
{
M31 = value.X;
M32 = value.Y;
@@ -382,13 +382,13 @@ public:
}
// Gets the translation of the matrix; that is M41, M42, and M43.
Vector3 GetTranslation() const
Float3 GetTranslation() const
{
return Vector3(M41, M42, M43);
return Float3(M41, M42, M43);
}
// Sets the translation of the matrix; that is M41, M42, and M43.
void SetTranslation(const Vector3& value)
void SetTranslation(const Float3& value)
{
M41 = value.X;
M42 = value.Y;
@@ -396,13 +396,13 @@ public:
}
// Gets the scale of the matrix; that is M11, M22, and M33.
Vector3 GetScaleVector() const
Float3 GetScaleVector() const
{
return Vector3(M11, M22, M33);
return Float3(M11, M22, M33);
}
// Sets the scale of the matrix; that is M11, M22, and M33.
void SetScaleVector(const Vector3& value)
void SetScaleVector(const Float3& value)
{
M11 = value.X;
M22 = value.Y;
@@ -457,7 +457,7 @@ public:
/// <param name="scale">When the method completes, contains the scaling component of the decomposed matrix.</param>
/// <param name="translation">When the method completes, contains the translation component of the decomposed matrix.</param>
/// <remarks>This method is designed to decompose an SRT transformation matrix only.</remarks>
void Decompose(Vector3& scale, Vector3& translation) const;
void Decompose(Float3& scale, Float3& translation) const;
/// <summary>
/// Decomposes a matrix into a scale, rotation, and translation.
@@ -473,7 +473,7 @@ public:
/// <param name="rotation">When the method completes, contains the rotation component of the decomposed matrix.</param>
/// <param name="translation">When the method completes, contains the translation component of the decomposed matrix.</param>
/// <remarks>This method is designed to decompose an SRT transformation matrix only.</remarks>
void Decompose(Vector3& scale, Quaternion& rotation, Vector3& translation) const;
void Decompose(Float3& scale, Quaternion& rotation, Float3& translation) const;
/// <summary>
/// Decomposes a matrix into a scale, rotation, and translation.
@@ -482,7 +482,7 @@ public:
/// <param name="rotation">When the method completes, contains the rotation component of the decomposed matrix.</param>
/// <param name="translation">When the method completes, contains the translation component of the decomposed matrix.</param>
/// <remarks>This method is designed to decompose an SRT transformation matrix only.</remarks>
void Decompose(Vector3& scale, Matrix& rotation, Vector3& translation) const;
void Decompose(Float3& scale, Matrix& rotation, Float3& translation) const;
public:
Matrix operator*(const float scale) const
@@ -794,17 +794,17 @@ public:
// Creates a left-handed spherical billboard that rotates around a specified object position.
// @param objectPosition The position of the object around which the billboard will rotate.
// @param cameraPosition The position of the camera.
// @param cameraUpVector The up vector of the camera.
// @param cameraForwardVector The forward vector of the camera.
// @param cameraUpFloat The up vector of the camera.
// @param cameraForwardFloat The forward vector of the camera.
// @param result When the method completes, contains the created billboard matrix.
static void Billboard(const Vector3& objectPosition, const Vector3& cameraPosition, const Vector3& cameraUpVector, const Vector3& cameraForwardVector, Matrix& result);
static void Billboard(const Float3& objectPosition, const Float3& cameraPosition, const Float3& cameraUpFloat, const Float3& cameraForwardFloat, Matrix& result);
// Creates a left-handed, look-at matrix.
// @param eye The position of the viewer's eye.
// @param target The camera look-at target.
// @param up The camera's up vector.
// @param result When the method completes, contains the created look-at matrix.
static void LookAt(const Vector3& eye, const Vector3& target, const Vector3& up, Matrix& result);
static void LookAt(const Float3& eye, const Float3& target, const Float3& up, Matrix& result);
// Creates a left-handed, orthographic projection matrix.
// @param width Width of the viewing volume.
@@ -863,7 +863,7 @@ public:
// Creates a matrix that scales along the x-axis, y-axis, and y-axis.
// @param scale Scaling factor for all three axes.
// @param result The created scaling matrix.
static Matrix Scaling(const Vector3& scale)
static Matrix Scaling(const Float3& scale)
{
return Scaling(scale.X, scale.Y, scale.Z);
}
@@ -871,7 +871,7 @@ public:
// Creates a matrix that scales along the x-axis, y-axis, and y-axis.
// @param scale Scaling factor for all three axes.
// @param result When the method completes, contains the created scaling matrix.
static void Scaling(const Vector3& scale, Matrix& result)
static void Scaling(const Float3& scale, Matrix& result)
{
Scaling(scale.X, scale.Y, scale.Z, result);
}
@@ -971,7 +971,7 @@ public:
// @param axis The axis around which to rotate. This parameter is assumed to be normalized.
// @param angle Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin.
// @returns The created rotation matrix
static Matrix RotationAxis(const Vector3& axis, float angle)
static Matrix RotationAxis(const Float3& axis, float angle)
{
Matrix result;
RotationAxis(axis, angle, result);
@@ -982,7 +982,7 @@ public:
// @param axis The axis around which to rotate. This parameter is assumed to be normalized.
// @param angle Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin.
// @param result When the method completes, contains the created rotation matrix.
static void RotationAxis(const Vector3& axis, float angle, Matrix& result);
static void RotationAxis(const Float3& axis, float angle, Matrix& result);
/// <summary>
/// Creates a rotation matrix from a quaternion
@@ -1025,12 +1025,12 @@ public:
// Creates a translation matrix using the specified offsets.
// @param value The offset for all three coordinate planes.
// @returns The created translation matrix.
static Matrix Translation(const Vector3& value);
static Matrix Translation(const Float3& value);
// Creates a translation matrix using the specified offsets.
// @param value The offset for all three coordinate planes.
// @param result When the method completes, contains the created translation matrix.
static void Translation(const Vector3& value, Matrix& result);
static void Translation(const Float3& value, Matrix& result);
// Creates a translation matrix using the specified offsets.
// @param x X-coordinate offset.
@@ -1044,7 +1044,7 @@ public:
// @param rotationVec The rotation vector.
// @param transVec The translation vector.
// @param matrix Contains the created skew/shear matrix.
static void Skew(float angle, const Vector3& rotationVec, const Vector3& transVec, Matrix& matrix);
static void Skew(float angle, const Float3& rotationVec, const Float3& transVec, Matrix& matrix);
/// <summary>
/// Creates a matrix that contains both the X, Y and Z rotation, as well as scaling and translation.
@@ -1053,14 +1053,14 @@ public:
/// <param name="rotation">Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin.</param>
/// <param name="scaling">The scaling.</param>
/// <param name="result">When the method completes, contains the created rotation matrix.</param>
static void Transformation(const Vector3& scaling, const Quaternion& rotation, const Vector3& translation, Matrix& result);
static void Transformation(const Float3& scaling, const Quaternion& rotation, const Float3& translation, Matrix& result);
// Creates a 3D affine transformation matrix.
// @param scaling Scaling factor.
// @param rotation The rotation of the transformation.
// @param translation The translation factor of the transformation.
// @param result When the method completes, contains the created affine transformation matrix.
static void AffineTransformation(float scaling, const Quaternion& rotation, const Vector3& translation, Matrix& result);
static void AffineTransformation(float scaling, const Quaternion& rotation, const Float3& translation, Matrix& result);
// Creates a 3D affine transformation matrix.
// @param scaling Scaling factor.
@@ -1068,14 +1068,14 @@ public:
// @param rotation The rotation of the transformation.
// @param translation The translation factor of the transformation.
// @param result When the method completes, contains the created affine transformation matrix.
static void AffineTransformation(float scaling, const Vector3& rotationCenter, const Quaternion& rotation, const Vector3& translation, Matrix& result);
static void AffineTransformation(float scaling, const Float3& rotationCenter, const Quaternion& rotation, const Float3& translation, Matrix& result);
// Creates a 2D affine transformation matrix.
// @param scaling Scaling factor.
// @param rotation The rotation of the transformation.
// @param translation The translation factor of the transformation.
// @param result When the method completes, contains the created affine transformation matrix.
static void AffineTransformation2D(float scaling, float rotation, const Vector2& translation, Matrix& result);
static void AffineTransformation2D(float scaling, float rotation, const Float2& translation, Matrix& result);
// Creates a 2D affine transformation matrix.
// @param scaling Scaling factor.
@@ -1083,7 +1083,7 @@ public:
// @param rotation The rotation of the transformation.
// @param translation The translation factor of the transformation.
// @param result When the method completes, contains the created affine transformation matrix.
static void AffineTransformation2D(float scaling, const Vector2& rotationCenter, float rotation, const Vector2& translation, Matrix& result);
static void AffineTransformation2D(float scaling, const Float2& rotationCenter, float rotation, const Float2& translation, Matrix& result);
// Creates a transformation matrix.
// @param scalingCenter Center point of the scaling operation.
@@ -1093,7 +1093,7 @@ public:
// @param rotation The rotation of the transformation.
// @param translation The translation factor of the transformation.
// @param result When the method completes, contains the created transformation matrix.
static void Transformation(const Vector3& scalingCenter, const Quaternion& scalingRotation, const Vector3& scaling, const Vector3& rotationCenter, const Quaternion& rotation, const Vector3& translation, Matrix& result);
static void Transformation(const Float3& scalingCenter, const Quaternion& scalingRotation, const Float3& scaling, const Float3& rotationCenter, const Quaternion& rotation, const Float3& translation, Matrix& result);
// Creates a 2D transformation matrix.
// @param scalingCenter Center point of the scaling operation.
@@ -1103,37 +1103,37 @@ public:
// @param rotation The rotation of the transformation.
// @param translation The translation factor of the transformation.
// @param result When the method completes, contains the created transformation matrix.
static void Transformation2D(Vector2& scalingCenter, float scalingRotation, const Vector2& scaling, const Vector2& rotationCenter, float rotation, const Vector2& translation, Matrix& result);
static void Transformation2D(Float2& scalingCenter, float scalingRotation, const Float2& scaling, const Float2& rotationCenter, float rotation, const Float2& translation, Matrix& result);
// Creates a world matrix with the specified parameters.
// @param position Position of the object. This value is used in translation operations.
// @param forward Forward direction of the object.
// @param up Upward direction of the object; usually [0, 1, 0].
// @returns Created world matrix of given transformation world.
static Matrix CreateWorld(const Vector3& position, const Vector3& forward, const Vector3& up);
static Matrix CreateWorld(const Float3& position, const Float3& forward, const Float3& up);
// Creates a world matrix with the specified parameters.
// @param position Position of the object. This value is used in translation operations.
// @param forward Forward direction of the object.
// @param up Upward direction of the object; usually [0, 1, 0].
// @param result Created world matrix of given transformation world.
static void CreateWorld(const Vector3& position, const Vector3& forward, const Vector3& up, Matrix& result);
static void CreateWorld(const Float3& position, const Float3& forward, const Float3& up, Matrix& result);
// Creates a new Matrix that rotates around an arbitrary vector.
// @param axis The axis to rotate around.
// @param angle The angle to rotate around the vector.
// @returns Result matrix.
static Matrix CreateFromAxisAngle(const Vector3& axis, float angle);
static Matrix CreateFromAxisAngle(const Float3& axis, float angle);
// Creates a new Matrix that rotates around an arbitrary vector.
// @param axis The axis to rotate around.
// @param angle The angle to rotate around the vector.
// @param result Result matrix.
static void CreateFromAxisAngle(const Vector3& axis, float angle, Matrix& result);
static void CreateFromAxisAngle(const Float3& axis, float angle, Matrix& result);
public:
static Vector4 TransformPosition(const Matrix& m, const Vector3& v);
static Vector4 TransformPosition(const Matrix& m, const Vector4& v);
static Float4 TransformPosition(const Matrix& m, const Float3& v);
static Float4 TransformPosition(const Matrix& m, const Float4& v);
};
template<>