记录Unity Matrix4x4的一个坑。

public class TestMatrix : MonoBehaviour
{
    //声明一个零矩阵,然后将其第四列改为(1,1,1,1)
    //分别将零矩阵单独声明,用数组装,用泛型装
    Matrix4x4 matrix;
    Matrix4x4[] matrix4x4Array;
    List<Matrix4x4> matrix4x4List = new List<Matrix4x4>();

    void Start()
    {
        matrix = Matrix4x4.zero;
        matrix4x4Array = new Matrix4x4[1] { Matrix4x4.zero };
        matrix4x4List.Add(Matrix4x4.zero);

        Debug.Log(matrix);
        matrix.SetColumn(3, Vector4.one);
        Debug.Log(matrix);

        Debug.Log("matrix4x4sBefore" + this.matrix4x4Array[0]);
        this.matrix4x4Array[0].SetColumn(3, Vector4.one);
        Debug.Log("matrix4x4sAfter" + this.matrix4x4Array[0]);

        //单独声明,和数组中都运行正常,但是泛型不可以。
        //虽然不报错,但是测试发现当矩阵被添加到泛型中,泛型中的元素的SetColumn方法是无效的,运行之后矩阵没有变化。
        Debug.Log("matrix4x4sBefore" + this.matrix4x4List[0]);
        this.matrix4x4List[0].SetColumn(3, Vector4.one);
        Debug.Log("matrix4x4sAfter" + this.matrix4x4List[0]);

        //修改List中的矩阵元素的有效方法
        // Debug.Log("matrix4x4sBefore" + this.matrix4x4List[0]);
        // Matrix4x4 tempM = this.matrix4x4List[0];
        // tempM.SetColumn(3, Vector4.one);
        // this.matrix4x4List[0] = tempM;
        // Debug.Log("matrix4x4sAfter" + this.matrix4x4List[0]);

    }
}

当Matrix4x4是泛型的元素时,他的函数SetRow() 和SetColumn()是无效的。

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值