マトリックス4x4

UnityEngine を使用する。
System.Collections を使用します。
public class juzhenTest : MonoBehaviour {
#region MultiplyVector
    //public Transform tr;
    //Matrix4x4 m1 = Matrix4x4.identity;
    //Matrix4x4 m2 = Matrix4x4.identity;
 // これを初期化に使用します
    //void Start () {
    // //m1.SetRow(0,new Vector4(1,2,3,4));
    // //m1.SetRow(1, new Vector4(1, 2, 3, 4));
    // //m1.SetRow(2, new Vector4(1, 2, 3, 4));
    // //m1.SetRow(3, new Vector4(1, 2, 3, 4));
    // //デバッグ.ログ(m1);
    // //Vector3 v1 = 新しい Vector3(3,4,5);
    // //デバッグ.ログ(v1);
    // //Vector3 v2 = m1.MultiplyPoint(v1);
    // //Debug.Log(v2);
    // //変換行列の位置変換と角度変換をそれぞれ 0 に設定
    // m1.SetTRS(Vector3.one*10.0f,Quaternion.Euler(new Vector3(0.0 f,30.0f,0.0f)),Vector3.one);
    // m2.SetTRS(Vector3.one * 10.0f, Quaternion.Euler(new Vector3(0.0f, 0.6f, 0.0f)), Vector3.one) ;
    //}
 
 // Update はフレームごとに 1 回呼び出されます
    //void Update () {
    // print(tr.position);
    // tr.position = m2.MultiplyVector(tr.position);
    // print(tr.position) ) );
    //}
    //void OnGUI(){
    //if(GUI.Button(new Rect(10.0f,10.0f,120.0f,45.0f),"方向を 30 度回転"))
    // {
    // Vector3 v=m1.MultiplyVector(new Vector3(10.0f,0.0f,0.0f));
    // //方向が回転された、回転されたベクトルを出力します
    // print("変換されたベクトル"+v) ;
    // print(v.magnitude);
    // }
    //}
#endregion
    #region MyRegion
    // Vector3 v1 = Vector3.one;
    //Vector3 v2 = Vector3.zero;
    //void Start() {
    // Matrix4x4 m1 = Matrix4x4.identity;
    // m1.SetTRS(Vector3.up*5,Quaternion.Euler(Vector3.up*45.0f),Vector3.one*2.0f);
    // v2 = m1.MultiplyPoint3x4(v1);
    // print(v1);
    // print(v2);
   
    //}
    //voidFixedUpdate() {
    // Debug.DrawLine(Vector3.zero,v1,Color.green);
    // Debug.DrawLine(Vector3.zero, v2, Color.red);
    //}
    #endregion
    #region MyRegion1
    Matrix4x4 Perspective = Matrix4x4.identity;//遠近投影変数
    Matrix4x4 ortho = Matrix4x4.identity;//直交投影変数
    float l, r, b, t;// の左、右、下、上の値を記録するために使用されます。直交ビューポート
    void Start (){
        //透視投影行列を設定します
        Perspective = Matrix4x4.Perspective(65.0f,1.5f,0.1f,500f);
        t = 10.0f;
        b = -t;
        //ビューの変形を防ぐために、 Camera.main.aspect と組み合わせる必要があります。
        l = b*Camera.main.aspect を乗算します。
        r = t * Camera.main.aspect;
        //直交射影行列を設定
        ortho = Matrix4x4.Ortho(l,r,b,t,0.1f,100.0f);
    }
    void OnGUI() {
        //デフォルトの正投影を使用します
        if (GUI.Button(new Rect(10, 8, 150, 20), "Rect Ortho")) {
            Camera.main.orthographic = true; //カメラはorthogonal 交差の場合は True、パースペクティブの場合は false
            Camera.main.ResetProjectionMatrix();//投影に通常のカメラ パラメータを反映させます
            Camera.main.orthographicSize = 5.1f;//正投影モードのカメラの半分のサイズ
        }
        //カスタム直交投影を使用する
        if (GUI.Button(new Rect(10, 38, 150, 20), "use Ortho")) {
        ortho
            = Matrix4x4.Ortho(l,r,b,t,0.1f ,100f );
            Camera.main.orthographic = true;
            Camera.main.ResetProjectionMatrix();
            Camera.main.projectionMatrix = ortho;//カスタム投影行列を設定します
            Camera.main.orthographicSize = 5.1f;
        }
        //カスタム投影を使用する
        if (GUI.Button(new Rect(10, 68, 150, 20), "use Perspective")) {
        Camera.main.orthographic
            = false;
            Camera.main.projectionMatrix = Perspective;
        }
        // 復元システムのデフォルトの透視投影
      if (GUI.Button(new Rect(10, 98, 150, 20), "Rect Perspective")) {
          Camera.main.orthographic = false;
          Camera.main.ResetProjectionMatrix();
        }
    }
    #endregion
}

おすすめ

転載: blog.csdn.net/hemiaoyuan1989/article/details/44858317