当前位置:   article > 正文

Unity Matrix.TRS 大概源码_matrix4x4.trs

matrix4x4.trs
  1. private Matrix4x4 TRS(Vector3 position, Quaternion rotation, Vector3 scale)
  2. {
  3. float num = rotation.x * 2f;
  4. float num2 = rotation.y * 2f;
  5. float num3 = rotation.z * 2f;
  6. float num4 = rotation.x * num;
  7. float num5 = rotation.y * num2;
  8. float num6 = rotation.z * num3;
  9. float num7 = rotation.x * num2;
  10. float num8 = rotation.x * num3;
  11. float num9 = rotation.y * num3;
  12. float num10 = rotation.w * num;
  13. float num11 = rotation.w * num2;
  14. float num12 = rotation.w * num3;
  15. Matrix4x4 result = default(Matrix4x4);
  16. result.m00 = scale.x * (1f - (num5 + num6));
  17. result.m01 = scale.y * (num7 - num12);
  18. result.m02 = scale.z * (num8 + num11);
  19. result.m03 = position.x;
  20. result.m10 = scale.x * (num7 + num12);
  21. result.m11 = scale.y * (1f - (num4 + num6));
  22. result.m12 = scale.z * (num9 - num10);
  23. result.m13 = position.y;
  24. result.m20 = scale.x * (num8 - num11);
  25. result.m21 = scale.y * (num9 + num10);
  26. result.m22 = scale.z * (1f - (num4 + num5));
  27. result.m23 = position.z;
  28. result.m30 = 0f;
  29. result.m31 = 0f;
  30. result.m32 = 0f;
  31. result.m33 = 1f;
  32. return result;
  33. }

使用和对比:

  1.     var obj = GameObject.Find("Cube (1)").transform;
  2. Debug.Log(TRS(obj.position, obj.rotation, obj.localScale));
  3. Debug.Log(Matrix4x4.TRS(obj.position, obj.rotation, obj.localScale));

运行效果:一模一样

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/100273
推荐阅读
相关标签
  

闽ICP备14008679号