本文整理汇总了C#中UnityEngine.Matrix4x4.GetColumn方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix4x4.GetColumn方法的具体用法?C# Matrix4x4.GetColumn怎么用?C# Matrix4x4.GetColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Matrix4x4
的用法示例。
在下文中一共展示了Matrix4x4.GetColumn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawColumns
public static Matrix4x4 DrawColumns( Matrix4x4 matrix )
{
matrix.SetColumn( 0, EditorGUI.Vector4Field( GetRekt(), "", matrix.GetColumn( 0 ) ) );
matrix.SetColumn( 1, EditorGUI.Vector4Field( GetRekt(), "", matrix.GetColumn( 1 ) ) );
matrix.SetColumn( 2, EditorGUI.Vector4Field( GetRekt(), "", matrix.GetColumn( 2 ) ) );
matrix.SetColumn( 3, EditorGUI.Vector4Field( GetRekt(), "", matrix.GetColumn( 3 ) ) );
return matrix;
}
示例2: DrawAxis
public static void DrawAxis(Matrix4x4 frame)
{
Vector3 X = frame.GetColumn (0)*AxisSize;
Vector3 Y = frame.GetColumn (1)*AxisSize;
Vector3 Z = frame.GetColumn (2)*AxisSize;
Vector3 pos = frame.GetColumn (3);
Debug.DrawLine (pos,pos+X,Color.red);
Debug.DrawLine (pos,pos+Y,Color.green);
Debug.DrawLine (pos,pos+Z,Color.blue);
}
示例3: MatrixToQuaternion
public static Quaternion MatrixToQuaternion(ref Matrix4x4 source)
{
// adapted from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
Matrix4x4 matrix = new Matrix4x4();
matrix.SetColumn(0, source.GetColumn(0));
matrix.SetColumn(1, source.GetColumn(1));
matrix.SetColumn(2, source.GetColumn(2));
matrix.SetColumn(3, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
float trace = Trace(ref matrix);
if (trace > 0.0f)
{
float s = Mathf.Sqrt(trace + 1.0f) * 2.0f; // 4 * qw in Jon's equ
return new Quaternion(
(matrix[2,1] - matrix[1,2]) / s,
(matrix[0,2] - matrix[2,0]) / s,
(matrix[1,0] - matrix[0,1]) / s,
0.25f * s);
}
else if (matrix[0,0] > matrix[1,1] && matrix[0,0] > matrix[2,2])
{
float s = Mathf.Sqrt(1.0f + matrix[0,0] - matrix[1,1] - matrix[2,2]) * 2.0f; // 4 * qx
return new Quaternion(
0.25f * s,
(matrix[0,1] + matrix[1,0]) / s,
(matrix[0,2] + matrix[2,0]) / s,
(matrix[2,1] - matrix[1,2]) / s);
}
else if (matrix[1,1] > matrix[2,2])
{
float s = Mathf.Sqrt(1.0f + matrix[1,1] - matrix[0,0] - matrix[2,2]) * 2.0f; // 4 * qw
return new Quaternion(
(matrix[0,1] + matrix[1,0]) / s,
0.25f * s,
(matrix[1,2] + matrix[2,1]) / s,
(matrix[0,2] - matrix[2,0]) / s);
}
else
{
float s = Mathf.Sqrt(1.0f + matrix[2,2] - matrix[0,0] - matrix[1,1]) * 2.0f; // 4 * qz
return new Quaternion(
(matrix[0,2] + matrix[2,0]) / s,
(matrix[1,2] + matrix[2,1]) / s,
0.25f * s,
(matrix[1,0] - matrix[0,1]) / s);
}
}
示例4: TransformFromMatrix
// Get a Transform ofject from a Matrix
public static void TransformFromMatrix(Matrix4x4 matrix, Transform trans)
{
//trans.localRotation = QuaternionFromMatrix(matrix);
trans.rotation = QuaternionFromMatrix(matrix);
Vector3 tmp = matrix.GetColumn(3); // uses implicit conversion from Vector4 to Vector3
// We need to invert the translation on the Y axis
tmp.y = -tmp.y;
//trans.localPosition = tmp;
//tmp.z = 250;
trans.position = tmp;
}
示例5: ExtractScaleFromMatrix
/// <summary>
/// Extract scale from transform matrix.
/// </summary>
/// <param name="matrix">Transform matrix. This parameter is passed by reference
/// to improve performance; no changes will be made to it.</param>
/// <returns>
/// Scale vector.
/// </returns>
public static Vector3 ExtractScaleFromMatrix(ref Matrix4x4 matrix) {
Vector3 scale = new Vector3(
matrix.GetColumn(0).magnitude,
matrix.GetColumn(1).magnitude,
matrix.GetColumn(2).magnitude
);
if (Vector3.Cross(matrix.GetColumn(0), matrix.GetColumn(1)).normalized != (Vector3)matrix.GetColumn(2).normalized)
{
scale.x *= -1;
}
return scale;
}
示例6: Notify
private GameObject[] cubes; //A list of every cube in the scene
#endregion Fields
#region Methods
/*
* Used to apply transformations made to one Character to the other.
*
* @param transformation Matrix of the transformations applied to the Character calling the function
* @param smallChar true if called by the small Character, false if called by the big one
*/
public void Notify(Matrix4x4 transformation, bool smallChar)
{
GameObject charToAlter = (smallChar) ? smallCharacter : bigCharacter,
otherChar = (smallChar) ? bigCharacter : smallCharacter;
CharController charController = charToAlter.GetComponent<CharController> (),
otherController = otherChar.GetComponent<CharController> ();
//Extracting infos from the Matrix
Vector3 translation = transformation.GetColumn (3),
scale = new Vector3(transformation.GetColumn (0).magnitude,
transformation.GetColumn (1).magnitude,
transformation.GetColumn (2).magnitude);
Quaternion rotation = Quaternion.LookRotation (transformation.GetColumn(2),
transformation.GetColumn(1));
//Reproducing translation
float dirCoef = (otherController.DistCamToCenter (translation) < otherController.DistCamToCenter (Vector3.zero))
? -1f : 1f;
translation = charController.charCamera.transform.forward * translation.magnitude * scale.magnitude * dirCoef;
charController.TranslateBy (translation);
/*
* Version using the Matrix4x4 infos only.
* Translation is okay, but could not get the rotation to work.
* Solved problem of the angle direction conservation with a custom function,
* but does not alter the rotation correctly
Quaternion relativeRotation = Quaternion.Inverse (otherChar.transform.rotation) * charToAlter.transform.rotation;
translation *= scale.magnitude;
translation = relativeRotation * translation;
charController.TranslateBy (translation);
if (translation.Equals (Vector3.zero)) {
rotation = relativeRotation * rotation;
charController.RotateAroundCenter (QuaternionToEulerSigned(rotation));
}
*/
}
示例7: QuaternionFromMatrix
//Gets a quaternion from a matrix
public static Quaternion QuaternionFromMatrix(Matrix4x4 m)
{
return Quaternion.LookRotation(m.GetColumn(2), m.GetColumn(1));
}
示例8: OrthogonalizeMatrix
public static Matrix4x4 OrthogonalizeMatrix(Matrix4x4 m)
{
Matrix4x4 identity = Matrix4x4.identity;
Vector3 vector = m.GetColumn(0);
Vector3 vector2 = m.GetColumn(1);
Vector3 normalized = m.GetColumn(2).normalized;
vector = Vector3.Cross(vector2, normalized).normalized;
vector2 = Vector3.Cross(normalized, vector).normalized;
identity.SetColumn(0, vector);
identity.SetColumn(1, vector2);
identity.SetColumn(2, normalized);
return identity;
}
示例9: MatrixToTranslation
public static Vector3 MatrixToTranslation(Matrix4x4 m)
{
var col = m.GetColumn(3);
return new Vector3(col.x, col.y, col.z);
}
示例10: TranslateMatrix
public static void TranslateMatrix(ref Matrix4x4 m, Vector3 position)
{
m.SetColumn(3,(Vector3)(m.GetColumn(3))+position);
m[3,3] = 1;
}
示例11: MatrixSlerp
public static Matrix4x4 MatrixSlerp(Matrix4x4 a, Matrix4x4 b, float t)
{
t = Mathf.Clamp01(t);
Matrix4x4 m = MatrixFromQuaternion(Quaternion.Slerp(QuaternionFromMatrix(a),QuaternionFromMatrix(b),t));
m.SetColumn(3,a.GetColumn(3)*(1-t)+b.GetColumn(3)*t);
m[3,3] = 1;
return m;
}
示例12: QuaternionFromMatrix
private static Quaternion QuaternionFromMatrix (Matrix4x4 m)
{
Quaternion q = Quaternion.LookRotation (m.GetColumn (2), m.GetColumn (1));
return q;
}
示例13: Matrix2Transform
public static void Matrix2Transform(Transform transform, Matrix4x4 mat)
{
transform.position = mat.GetColumn(3);
transform.rotation = ConvertCoord.QuaternionFromMatrix(mat);
transform.localScale = Vector3.one;
}
示例14: QuaternionFromMatrix
private static Quaternion QuaternionFromMatrix(Matrix4x4 m)
{
// Adapted from: http://forum.unity3d.com/threads/is-it-possible-to-get-a-quaternion-from-a-matrix4x4.142325/
return Quaternion.LookRotation(m.GetColumn(2), m.GetColumn(1));
// [DEPRECATED]
/*
// Adapted from: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
Quaternion q = new Quaternion();
q.w = (float)Mathf.Sqrt(Mathf.Max(0.0f, 1.0f + m.m00 + m.m11 + m.m22)) * 0.5f;
q.x = (float)Mathf.Sqrt(Mathf.Max(0.0f, 1.0f + m.m00 - m.m11 - m.m22)) * 0.5f;
q.y = (float)Mathf.Sqrt(Mathf.Max(0.0f, 1.0f - m.m00 + m.m11 - m.m22)) * 0.5f;
q.z = (float)Mathf.Sqrt(Mathf.Max(0.0f, 1.0f - m.m00 - m.m11 + m.m22)) * 0.5f;
q.x *= Mathf.Sign(m.m21 - m.m12);
q.y *= Mathf.Sign(m.m02 - m.m20);
q.z *= Mathf.Sign(m.m10 - m.m01);
return q;
//*/
}
示例15: TranslationFromMatrix
/// <summary>
/// Vector3 translation from the 4x4 matrix
/// </summary>
/// <param name="m">
/// A 4x4 transformation matrix <see cref="Matrix4x4"/>
/// </param>
/// <returns>
/// A translation vector <see cref="Vector3"/>
/// </returns>
public static Vector3 TranslationFromMatrix(Matrix4x4 m)
{
Vector4 pos = m.GetColumn(3);
Vector3 returnPos=new Vector3(pos.x,pos.y,pos.z);
return returnPos;
}