From ee56a3506db800302ea41e75ab0011abd1547577 Mon Sep 17 00:00:00 2001 From: Robert Rouhani Date: Tue, 9 Sep 2014 13:21:11 -0400 Subject: [PATCH] Added Matrix3[d].Add and Matrix4[d].CreateFromRotationMatrix --- Source/OpenTK/Math/Matrix3.cs | 20 +++++++++++++++++++- Source/OpenTK/Math/Matrix3d.cs | 20 +++++++++++++++++++- Source/OpenTK/Math/Matrix4.cs | 31 +++++++++++++++++++++++++++++++ Source/OpenTK/Math/Matrix4d.cs | 31 +++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 2 deletions(-) diff --git a/Source/OpenTK/Math/Matrix3.cs b/Source/OpenTK/Math/Matrix3.cs index cd2f3bc..18b5c6f 100644 --- a/Source/OpenTK/Math/Matrix3.cs +++ b/Source/OpenTK/Math/Matrix3.cs @@ -667,7 +667,25 @@ namespace OpenTK } #endregion - + + #region Add Functions + + public static Matrix3 Add(Matrix3 left, Matrix3 right) + { + Matrix3 result; + Add(ref left, ref right, out result); + return result; + } + + public static void Add(ref Matrix3 left, ref Matrix3 right, out Matrix3 result) + { + Vector3.Add(ref left.Row0, ref right.Row0, out result.Row0); + Vector3.Add(ref left.Row1, ref right.Row1, out result.Row1); + Vector3.Add(ref left.Row2, ref right.Row2, out result.Row2); + } + + #endregion + #region Multiply Functions /// diff --git a/Source/OpenTK/Math/Matrix3d.cs b/Source/OpenTK/Math/Matrix3d.cs index 757c36c..7963353 100644 --- a/Source/OpenTK/Math/Matrix3d.cs +++ b/Source/OpenTK/Math/Matrix3d.cs @@ -664,7 +664,25 @@ namespace OpenTK } #endregion - + + #region Add Functions + + public static Matrix3d Add(Matrix3d left, Matrix3d right) + { + Matrix3d result; + Add(ref left, ref right, out result); + return result; + } + + public static void Add(ref Matrix3d left, ref Matrix3d right, out Matrix3d result) + { + Vector3d.Add(ref left.Row0, ref right.Row0, out result.Row0); + Vector3d.Add(ref left.Row1, ref right.Row1, out result.Row1); + Vector3d.Add(ref left.Row2, ref right.Row2, out result.Row2); + } + + #endregion + #region Multiply Functions /// diff --git a/Source/OpenTK/Math/Matrix4.cs b/Source/OpenTK/Math/Matrix4.cs index 2d311fd..1828298 100644 --- a/Source/OpenTK/Math/Matrix4.cs +++ b/Source/OpenTK/Math/Matrix4.cs @@ -592,6 +592,37 @@ namespace OpenTK #endregion + #region CreateFromRotationMatrix + + public static Matrix4 CreateFromRotationMatrix(Matrix3 rotation) + { + Matrix4 result; + CreateFromRotationMatrix(ref rotation, out result); + return result; + } + + public static void CreateFromRotationMatrix(ref Matrix3 rotation, out Matrix4 result) + { + result.Row0.X = rotation.Row0.X; + result.Row0.Y = rotation.Row0.Y; + result.Row0.Z = rotation.Row0.Z; + result.Row0.W = 0; + result.Row1.X = rotation.Row1.X; + result.Row1.Y = rotation.Row1.Y; + result.Row1.Z = rotation.Row1.Z; + result.Row1.W = 0; + result.Row2.X = rotation.Row2.X; + result.Row2.Y = rotation.Row2.Y; + result.Row2.Z = rotation.Row2.Z; + result.Row2.W = 0; + result.Row3.X = 0; + result.Row3.Y = 0; + result.Row3.Z = 0; + result.Row3.W = 1; + } + + #endregion + #region CreateRotation[XYZ] /// diff --git a/Source/OpenTK/Math/Matrix4d.cs b/Source/OpenTK/Math/Matrix4d.cs index 785a6a1..103b94a 100644 --- a/Source/OpenTK/Math/Matrix4d.cs +++ b/Source/OpenTK/Math/Matrix4d.cs @@ -551,6 +551,37 @@ namespace OpenTK #endregion + #region CreateFromRotationMatrix + + public static Matrix4d CreateFromRotationMatrix(Matrix3d rotation) + { + Matrix4d result; + CreateFromRotationMatrix(ref rotation, out result); + return result; + } + + public static void CreateFromRotationMatrix(ref Matrix3d rotation, out Matrix4d result) + { + result.Row0.X = rotation.Row0.X; + result.Row0.Y = rotation.Row0.Y; + result.Row0.Z = rotation.Row0.Z; + result.Row0.W = 0; + result.Row1.X = rotation.Row1.X; + result.Row1.Y = rotation.Row1.Y; + result.Row1.Z = rotation.Row1.Z; + result.Row1.W = 0; + result.Row2.X = rotation.Row2.X; + result.Row2.Y = rotation.Row2.Y; + result.Row2.Z = rotation.Row2.Z; + result.Row2.W = 0; + result.Row3.X = 0; + result.Row3.Y = 0; + result.Row3.Z = 0; + result.Row3.W = 1; + } + + #endregion + #region CreateRotation[XYZ] /// -- 2.7.4