终于,到了我们万能的矩阵!话说这个结构体写起来还真是烦,变量也太多了吧。长得还挺像,一个不小心就容易出错。好在总算是写完了。
Matrix4x4d中也有一个方法暂未实现,叫做LookAt。怎么写都跟原来的方法差很多,不知道问题出在哪。大神快来~
Matrix4x4d:
/// Matrix4x4d.cs
///
/// The double type version of the Unity struct Matrix4x4.
/// It can solve the problem that the float type may not be accurate enough.
/// Function LookAt is unimplmented.
///
/// Unity Matrix4x4结构体的double版实现,以解决float型精度可能不够的问题。其中LookAt方法暂未实现。
///
/// Created by D子宇 on 2018.3.17
///
/// Email: darkziyu@126.com
using System;
using UnityEngine;
namespace Mathd
{
public struct Matrix4x4d
{
#region public members
public double m00;
public double m01;
public double m02;
public double m03;
public double m10;
public double m11;
public double m12;
public double m13;
public double m20;
public double m21;
public double m22;
public double m23;
public double m30;
public double m31;
public double m32;
public double m33;
#endregion
#region public properties
public double this[int index]
{
get
{
switch (index)
{
case 0:
return m00;
case 1:
return m10;
case 2:
return m20;
case 3:
return m30;
case 4:
return m01;
case 5:
return m11;
case 6:
return m21;
case 7:
return m31;
case 8:
return m02;
case 9:
return m12;
case 10:
return m22;
case 11:
return m32;
case 12:
return m03;
case 13:
return m13;
case 14:
return m23;
case 15:
return m33;
default:
throw new IndexOutOfRangeException("Invalid matrixd index!");
}
}
set
{
switch (index)
{
case 0:
m00 = value;
break;
case 1:
m10 = value;
break;
case 2:
m20 = value;
break;
case 3:
m30 = value;
break;
case 4:
m01 = value;
break;
case 5:
m11 = value;
break;
case 6:
m21 = value;
break;
case 7:
m31 = value;
break;
case 8:
m02 = value;
break;
case 9:
m12 = value;
break;
case 10:
m22 = value;
break;
case 11:
m32 = value;
break;
case 12:
m03 = value;
break;
case 13:
m13 = value;
break;
case 14:
m23 = value;
break;
case 15:
m33 = value;
break;
default:
throw new IndexOutOfRangeException("Invalid matrixd index!");
}
}
}
public double this[int row, int column]
{
get
{
return this[row + column * 4];
}
set
{
this[row + column * 4] = value;
}
}
public static Matrix4x4d identity
{
get
{
Matrix4x4d temp = new Matrix4x4d();
temp[0, 0] = 1;
temp[1, 1] = 1;
temp[2, 2] = 1;
temp[3, 3] = 1;