旋转矩阵
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestGame : MonoBehaviour
{
public Vector2 p1;
public Vector2 p2;
public GameObject go;
private void OnGUI()
{
if (GUILayout.Button("计算"))
{
Vector3 right = go.transform.right;
Vector3 up = go.transform.up;
Vector3 forward = go.transform.forward;
//把go的轴旋转到 世界方向
Matrix4x4 rotM = new Matrix4x4();
rotM.m00 = right.x; rotM.m01 = up.x; rotM.m02 = forward.x; rotM.m03 = 0;
rotM.m10 = right.y; rotM.m11 = up.y; rotM.m12 = forward.y; rotM.m13 = 0;
rotM.m20 = right.z; rotM.m21 = up.z; rotM.m22 = forward.z; rotM.m23 = 0;
rotM.m30 = 0; rotM.m31 = 0; rotM.m32 = 0; rotM.m33 = 1;
Matrix4x4 M = rotM.transpose;
Vector4 right4 = new Vector4(right.x, right.y, right.z, 0);
Vector4 rightM = M * right4;
Debug.LogError(rightM);
//Debug.LogError(rightM.x + " " + rightM.y + " " + rightM.z);
Vector4 up4 = new Vector4(up.x, up.y, up.z,0);
Vector4 upM = M * up4;
Debug.LogError(upM);
}
}
}
using System.Collections;using System.Collections.Generic;using UnityEngine;
public class TestGame : MonoBehaviour{
public Vector2 p1; public Vector2 p2;
public GameObject go;
private void OnGUI() { if (GUILayout.Button("计算")) {
Vector3 right = go.transform.right; Vector3 up = go.transform.up; Vector3 forward = go.transform.forward;
//把go的轴旋转到 世界方向 Matrix4x4 rotM = new Matrix4x4(); rotM.m00 = right.x; rotM.m01 = up.x; rotM.m02 = forward.x; rotM.m03 = 0; rotM.m10 = right.y; rotM.m11 = up.y; rotM.m12 = forward.y; rotM.m13 = 0; rotM.m20 = right.z; rotM.m21 = up.z; rotM.m22 = forward.z; rotM.m23 = 0; rotM.m30 = 0; rotM.m31 = 0; rotM.m32 = 0; rotM.m33 = 1;
Matrix4x4 M = rotM.transpose;
Vector4 right4 = new Vector4(right.x, right.y, right.z, 0); Vector4 rightM = M * right4; Debug.LogError(rightM); //Debug.LogError(rightM.x + " " + rightM.y + " " + rightM.z); Vector4 up4 = new Vector4(up.x, up.y, up.z,0); Vector4 upM = M * up4; Debug.LogError(upM);
} }
}
浙公网安备 33010602011771号