当前位置:   article > 正文

【Unity】Mathd系列(五)Double型Matrix4x4_unity double4x4

unity double4x4

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

    Matrix4x4d中也有一个方法暂未实现,叫做LookAt。怎么写都跟原来的方法差很多,不知道问题出在哪。大神快来~

Matrix4x4d:

  1. /// Matrix4x4d.cs
  2. ///
  3. /// The double type version of the Unity struct Matrix4x4.
  4. /// It can solve the problem that the float type may not be accurate enough.
  5. /// Function LookAt is unimplmented.
  6. ///
  7. /// Unity Matrix4x4结构体的double版实现,以解决float型精度可能不够的问题。其中LookAt方法暂未实现。
  8. ///
  9. /// Created by D子宇 on 2018.3.17
  10. ///
  11. /// Email: darkziyu@126.com
  12. using System;
  13. using UnityEngine;
  14. namespace Mathd
  15. {
  16. public struct Matrix4x4d
  17. {
  18. #region public members
  19. public double m00;
  20. public double m01;
  21. public double m02;
  22. public double m03;
  23. public double m10;
  24. public double m11;
  25. public double m12;
  26. public double m13;
  27. public double m20;
  28. public double m21;
  29. public double m22;
  30. public double m23;
  31. public double m30;
  32. public double m31;
  33. public double m32;
  34. public double m33;
  35. #endregion
  36. #region public properties
  37. public double this[int index]
  38. {
  39. get
  40. {
  41. switch (index)
  42. {
  43. case 0:
  44. return m00;
  45. case 1:
  46. return m10;
  47. case 2:
  48. return m20;
  49. case 3:
  50. return m30;
  51. case 4:
  52. return m01;
  53. case 5:
  54. return m11;
  55. case 6:
  56. return m21;
  57. case 7:
  58. return m31;
  59. case 8:
  60. return m02;
  61. case 9:
  62. return m12;
  63. case 10:
  64. return m22;
  65. case 11:
  66. return m32;
  67. case 12:
  68. return m03;
  69. case 13:
  70. return m13;
  71. case 14:
  72. return m23;
  73. case 15:
  74. return m33;
  75. default:
  76. throw new IndexOutOfRangeException("Invalid matrixd index!");
  77. }
  78. }
  79. set
  80. {
  81. switch (index)
  82. {
  83. case 0:
  84. m00 = value;
  85. break;
  86. case 1:
  87. m10 = value;
  88. break;
  89. case 2:
  90. m20 = value;
  91. break;
  92. case 3:
  93. m30 = value;
  94. break;
  95. case 4:
  96. m01 = value;
  97. break;
  98. case 5:
  99. m11 = value;
  100. break;
  101. case 6:
  102. m21 = value;
  103. break;
  104. case 7:
  105. m31 = value;
  106. break;
  107. case 8:
  108. m02 = value;
  109. break;
  110. case 9:
  111. m12 = value;
  112. break;
  113. case 10:
  114. m22 = value;
  115. break;
  116. case 11:
  117. m32 = value;
  118. break;
  119. case 12:
  120. m03 = value;
  121. break;
  122. case 13:
  123. m13 = value;
  124. break;
  125. case 14:
  126. m23 = value;
  127. break;
  128. case 15:
  129. m33 = value;
  130. break;
  131. default:
  132. throw new IndexOutOfRangeException("Invalid matrixd index!");
  133. }
  134. }
  135. }
  136. public double this[int row, int column]
  137. {
  138. get
  139. {
  140. return this[row + column * 4];
  141. }
  142. set
  143. {
  144. this[row + column * 4] = value;
  145. }
  146. }
  147. public static Matrix4x4d identity
  148. {
  149. get
  150. {
  151. Matrix4x4d temp = new Matrix4x4d();
  152. temp[0, 0] = 1;
  153. temp[1, 1] = 1;
  154. temp[2, 2] = 1;
  155. temp[3, 3] = 1;
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/108441
推荐阅读
相关标签
  

闽ICP备14008679号