【Unity】Mathd系列(五)Double型Matrix4x4

本文探讨Unity中的Double型Matrix4x4结构体,解析其复杂性及在编程过程中的注意事项。尽管存在较多变量导致易出错,但整个Matrix4x4d已完整实现,除了未完成的LookAt方法,该方法实现上遇到困难,期待大神指导。
摘要由CSDN通过智能技术生成

    终于,到了我们万能的矩阵!话说这个结构体写起来还真是烦,变量也太多了吧。长得还挺像,一个不小心就容易出错。好在总算是写完了。

    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;

     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值