using UnityEngine;
using System.Collections;
using System.Collections;
public class juzhenTest : MonoBehaviour {
#region MultiplyVector
//public Transform tr;
//Matrix4x4 m1 = Matrix4x4.identity;
//Matrix4x4 m2 = Matrix4x4.identity;
// Use this for initialization
//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));
// //Debug.Log(m1);
// //Vector3 v1 = new Vector3(3,4,5);
// //Debug.Log(v1);
// //Vector3 v2 = m1.MultiplyPoint(v1);
// //Debug.Log(v2);
// //分别设置变换矩阵的位置变换和角度变换都不为0
// m1.SetTRS(Vector3.one*10.0f,Quaternion.Euler(new Vector3(0.0f,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 is called once per frame
//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);
#region MultiplyVector
//public Transform tr;
//Matrix4x4 m1 = Matrix4x4.identity;
//Matrix4x4 m2 = Matrix4x4.identity;
// Use this for initialization
//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));
// //Debug.Log(m1);
// //Vector3 v1 = new Vector3(3,4,5);
// //Debug.Log(v1);
// //Vector3 v2 = m1.MultiplyPoint(v1);
// //Debug.Log(v2);
// //分别设置变换矩阵的位置变换和角度变换都不为0
// m1.SetTRS(Vector3.one*10.0f,Quaternion.Euler(new Vector3(0.0f,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 is called once per frame
//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;
#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);
//}
// 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);
//}
//void FixedUpdate() {
// 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);
}
// 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;//相机是正交的true,是透视的false
Camera.main.ResetProjectionMatrix();//让投影反映正常的相机参数
Camera.main.orthographicSize = 5.1f;//在正交模式下相机的一半尺寸
//使用默认正交投影
if (GUI.Button(new Rect(10, 8, 150, 20), "Rect Ortho")) {
Camera.main.orthographic = true;//相机是正交的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, 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
}
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
}