avc81's picture

Matrix4, Matrix4D Shear Matrix

Project:The Open Toolkit library
Version:1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:avc81
Status:in progress (commit)
Description

i think that a Matrix4,Matrix4d.CreateShear will be a useful addition. tomorrow i'm going to implement and test the new function. Just tell me if u want it as a patch


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
avc81's picture

#1

Status:in progress» in progress (commit)

ok implemented tested and delivered as a patch

Index: Source/OpenTK/Math/Matrix4.cs
===================================================================
--- Source/OpenTK/Math/Matrix4.cs	(revision 3066)
+++ Source/OpenTK/Math/Matrix4.cs	(working copy)
@@ -275,6 +275,80 @@
 
         #region Static
 
+        #region CreateFromQuaternion
+        /// <summary>
+        /// Build a rotation matrix from the specified quaternion.
+        /// </summary>
+        /// <param name="q">Quaternion to translate.</param>
+        /// <param name="m">Matrix result.</param>
+        public static void CreateFromQuaternion(ref Quaternion q,ref Matrix4 m)
+        {
+            m = Matrix4.Identity;
+
+			float X = q.X;
+			float Y = q.Y;
+			float Z = q.Z;
+			float W = q.W;
+			
+			float xx = X * X;
+			float xy = X * Y;
+			float xz = X * Z;
+			float xw = X * W;
+			float yy = Y * Y;
+			float yz = Y * Z;
+			float yw = Y * W;
+			float zz = Z * Z;
+			float zw = Z * W;
+			
+			m.M11 = 1 - 2 * (yy + zz);
+			m.M21 = 2 * (xy - zw);
+			m.M31 = 2 * (xz + yw);
+			m.M12 = 2 * (xy + zw);
+			m.M22 = 1 - 2 * (xx + zz);
+			m.M32 = 2 * (yz - xw);
+			m.M13 = 2 * (xz - yw);
+			m.M23 = 2 * (yz + xw);
+			m.M33 = 1 - 2 * (xx + yy);
+        }
+
+        /// <summary>
+        /// Build a rotation matrix from the specified quaternion.
+        /// </summary>
+        /// <param name="q">Quaternion to translate.</param>
+        /// <returns>A matrix instance.</returns>
+        public static Matrix4 CreateFromQuaternion(ref Quaternion q)
+        {
+            Matrix4 result = Matrix4.Identity;
+
+			float X = q.X;
+			float Y = q.Y;
+			float Z = q.Z;
+			float W = q.W;
+			
+			float xx = X * X;
+			float xy = X * Y;
+			float xz = X * Z;
+			float xw = X * W;
+			float yy = Y * Y;
+			float yz = Y * Z;
+			float yw = Y * W;
+			float zz = Z * Z;
+			float zw = Z * W;
+			
+			result.M11 = 1 - 2 * (yy + zz);
+			result.M21 = 2 * (xy - zw);
+			result.M31 = 2 * (xz + yw);
+			result.M12 = 2 * (xy + zw);
+			result.M22 = 1 - 2 * (xx + zz);
+			result.M32 = 2 * (yz - xw);
+			result.M13 = 2 * (xz - yw);
+			result.M23 = 2 * (yz + xw);
+			result.M33 = 1 - 2 * (xx + yy);
+            return result;
+        }
+
+        #endregion
+        
         #region CreateFromAxisAngle
 
         /// <summary>
@@ -399,7 +473,29 @@
         }
 
         #endregion
+        
+        #region CreateShear
 
+        /// <summary>
+        /// Builds a shear matrix.
+        /// </summary>
+        /// <param name="shearXbyY">a shear of X by Y</param>
+        /// <param name="shearXbyZ">a shear of X by Z</param>
+        /// <param name="shearYbyX">a shear of Y by X</param>
+        /// <param name="shearYbyZ">a shear of Y by Z</param>
+        /// <param name="shearZbyX">a shear of Z by X</param>
+        /// <param name="shearZbyY">a shear of Z by Y</param>
+        /// <returns>the shear matrix</returns>
+        public static Matrix4 CreateShearMatrix(float shearXbyY, float shearXbyZ, float shearYbyX, float shearYbyZ, float shearZbyX, float shearZbyY)
+		{
+			return new Matrix4(1, shearYbyX, shearZbyX, 0,
+        	                    shearXbyY, 1, shearZbyY, 0, 
+        	                    shearXbyZ, shearYbyZ,1, 0,
+        	                    0, 0, 0, 1);
+		}
+        
+        #endregion
+
         #region CreateTranslation
 
         /// <summary>
Index: Source/OpenTK/Math/Matrix4d.cs
===================================================================
--- Source/OpenTK/Math/Matrix4d.cs	(revision 3066)
+++ Source/OpenTK/Math/Matrix4d.cs	(working copy)
@@ -275,6 +275,80 @@
 
         #region Static
 
+        #region CreateFromQuaternion
+        /// <summary>
+        /// Build a rotation matrix from the specified quaternion.
+        /// </summary>
+        /// <param name="q">Quaternion to translate.</param>
+        /// <param name="m">Matrix result.</param>
+        public static void CreateFromQuaternion(ref Quaterniond q,ref Matrix4d m)
+        {
+            m = Matrix4d.Identity;
+
+			double X = q.X;
+			double Y = q.Y;
+			double Z = q.Z;
+			double W = q.W;
+			
+			double xx = X * X;
+			double xy = X * Y;
+			double xz = X * Z;
+			double xw = X * W;
+			double yy = Y * Y;
+			double yz = Y * Z;
+			double yw = Y * W;
+			double zz = Z * Z;
+			double zw = Z * W;
+			
+			m.M11 = 1 - 2 * (yy + zz);
+			m.M21 = 2 * (xy - zw);
+			m.M31 = 2 * (xz + yw);
+			m.M12 = 2 * (xy + zw);
+			m.M22 = 1 - 2 * (xx + zz);
+			m.M32 = 2 * (yz - xw);
+			m.M13 = 2 * (xz - yw);
+			m.M23 = 2 * (yz + xw);
+			m.M33 = 1 - 2 * (xx + yy);
+        }
+
+        /// <summary>
+        /// Build a rotation matrix from the specified quaternion.
+        /// </summary>
+        /// <param name="q">Quaternion to translate.</param>
+        /// <returns>A matrix instance.</returns>
+        public static Matrix4d CreateFromQuaternion(ref Quaterniond q)
+        {
+            Matrix4d result = Matrix4d.Identity;
+
+			double X = q.X;
+			double Y = q.Y;
+			double Z = q.Z;
+			double W = q.W;
+			
+			double xx = X * X;
+			double xy = X * Y;
+			double xz = X * Z;
+			double xw = X * W;
+			double yy = Y * Y;
+			double yz = Y * Z;
+			double yw = Y * W;
+			double zz = Z * Z;
+			double zw = Z * W;
+			
+			result.M11 = 1 - 2 * (yy + zz);
+			result.M21 = 2 * (xy - zw);
+			result.M31 = 2 * (xz + yw);
+			result.M12 = 2 * (xy + zw);
+			result.M22 = 1 - 2 * (xx + zz);
+			result.M32 = 2 * (yz - xw);
+			result.M13 = 2 * (xz - yw);
+			result.M23 = 2 * (yz + xw);
+			result.M33 = 1 - 2 * (xx + yy);
+            return result;
+        }
+
+        #endregion
+        
         #region CreateFromAxisAngle
 
         /// <summary>
@@ -399,7 +473,29 @@
         }
 
         #endregion
+        
+        #region CreateShear
 
+        /// <summary>
+        /// Builds a shear matrix.
+        /// </summary>
+        /// <param name="shearXbyY">a shear of X by Y</param>
+        /// <param name="shearXbyZ">a shear of X by Z</param>
+        /// <param name="shearYbyX">a shear of Y by X</param>
+        /// <param name="shearYbyZ">a shear of Y by Z</param>
+        /// <param name="shearZbyX">a shear of Z by X</param>
+        /// <param name="shearZbyY">a shear of Z by Y</param>
+        /// <returns>the shear matrix</returns>
+        public static Matrix4d CreateShearMatrix(double shearXbyY, double shearXbyZ, double shearYbyX, double shearYbyZ, double shearZbyX, double shearZbyY)
+		{
+			return new Matrix4d(1, shearYbyX, shearZbyX, 0,
+        	                    shearXbyY, 1, shearZbyY, 0, 
+        	                    shearXbyZ, shearYbyZ,1, 0,
+        	                    0, 0, 0, 1);
+		}
+
+        #endregion
+
         #region CreateTranslation
 
         /// <summary>
Jessicafin01's picture

#2

Very riveting message will bookmark your situation to analyse if you correspond writer virtually in the futurity.

Regards

Xerox Boerne TX

title company greenwich CT

tutoring utah

offshore banking

Office Supplies Boise