Skip to content

Commit

Permalink
Merge pull request #176 from Robmaister/develop
Browse files Browse the repository at this point in the history
Added Matrix3[d].Add and Matrix4[d].CreateFromRotationMatrix
  • Loading branch information
thefiddler committed Sep 16, 2014
2 parents d6d6842 + 7a4dfcf commit c295098
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
20 changes: 19 additions & 1 deletion Source/OpenTK/Math/Matrix3.cs
Expand Up @@ -667,7 +667,25 @@ public static void CreateScale(float x, float y, float z, out Matrix3 result)
}

#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

/// <summary>
Expand Down
20 changes: 19 additions & 1 deletion Source/OpenTK/Math/Matrix3d.cs
Expand Up @@ -664,7 +664,25 @@ public static void CreateScale(double x, double y, double z, out Matrix3d result
}

#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

/// <summary>
Expand Down
24 changes: 24 additions & 0 deletions Source/OpenTK/Math/Matrix4.cs
Expand Up @@ -117,6 +117,30 @@ public Matrix4(Vector4 row0, Vector4 row1, Vector4 row2, Vector4 row3)
Row3 = new Vector4(m30, m31, m32, m33);
}

/// <summary>
/// Constructs a new instance.
/// </summary>
/// <param name="topLeft">The top left 3x3 of the matrix.</param>
public Matrix4(Matrix3 topLeft)
{
Row0.X = topLeft.Row0.X;
Row0.Y = topLeft.Row0.Y;
Row0.Z = topLeft.Row0.Z;
Row0.W = 0;
Row1.X = topLeft.Row1.X;
Row1.Y = topLeft.Row1.Y;
Row1.Z = topLeft.Row1.Z;
Row1.W = 0;
Row2.X = topLeft.Row2.X;
Row2.Y = topLeft.Row2.Y;
Row2.Z = topLeft.Row2.Z;
Row2.W = 0;
Row3.X = 0;
Row3.Y = 0;
Row3.Z = 0;
Row3.W = 1;
}

#endregion

#region Public Members
Expand Down
24 changes: 24 additions & 0 deletions Source/OpenTK/Math/Matrix4d.cs
Expand Up @@ -109,6 +109,30 @@ public Matrix4d(Vector4d row0, Vector4d row1, Vector4d row2, Vector4d row3)
Row3 = new Vector4d(m30, m31, m32, m33);
}

/// <summary>
/// Constructs a new instance.
/// </summary>
/// <param name="topLeft">The top left 3x3 of the matrix.</param>
public Matrix4d(Matrix3d topLeft)
{
Row0.X = topLeft.Row0.X;
Row0.Y = topLeft.Row0.Y;
Row0.Z = topLeft.Row0.Z;
Row0.W = 0;
Row1.X = topLeft.Row1.X;
Row1.Y = topLeft.Row1.Y;
Row1.Z = topLeft.Row1.Z;
Row1.W = 0;
Row2.X = topLeft.Row2.X;
Row2.Y = topLeft.Row2.Y;
Row2.Z = topLeft.Row2.Z;
Row2.W = 0;
Row3.X = 0;
Row3.Y = 0;
Row3.Z = 0;
Row3.W = 1;
}

#endregion

#region Public Members
Expand Down

0 comments on commit c295098

Please sign in to comment.