TransformObject.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /**
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2012-2017 DragonBones team and other contributors
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  7. * this software and associated documentation files (the "Software"), to deal in
  8. * the Software without restriction, including without limitation the rights to
  9. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10. * the Software, and to permit persons to whom the Software is furnished to do so,
  11. * subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. using System;
  24. using System.Collections.Generic;
  25. using System.Text;
  26. namespace DragonBones
  27. {
  28. /// <summary>
  29. /// - The base class of the transform object.
  30. /// </summary>
  31. /// <see cref="DragonBones.Transform"/>
  32. /// <version>DragonBones 4.5</version>
  33. /// <language>en_US</language>
  34. /// <summary>
  35. /// - 变换对象的基类。
  36. /// </summary>
  37. /// <see cref="DragonBones.Transform"/>
  38. /// <version>DragonBones 4.5</version>
  39. /// <language>zh_CN</language>
  40. public abstract class TransformObject : BaseObject
  41. {
  42. /// <private/>
  43. protected static readonly Matrix _helpMatrix = new Matrix();
  44. /// <private/>
  45. protected static readonly TransformDB _helpTransform = new TransformDB();
  46. /// <private/>
  47. protected static readonly Point _helpPoint = new Point();
  48. /// <summary>
  49. /// - A matrix relative to the armature coordinate system.
  50. /// </summary>
  51. /// <version>DragonBones 3.0</version>
  52. /// <language>en_US</language>
  53. /// <summary>
  54. /// - 相对于骨架坐标系的矩阵。
  55. /// </summary>
  56. /// <version>DragonBones 3.0</version>
  57. /// <language>zh_CN</language>
  58. public readonly Matrix globalTransformMatrix = new Matrix();
  59. /// <summary>
  60. /// - A transform relative to the armature coordinate system.
  61. /// </summary>
  62. /// <see cref="UpdateGlobalTransform()"/>
  63. /// <version>DragonBones 3.0</version>
  64. /// <language>en_US</language>
  65. /// <summary>
  66. /// - 相对于骨架坐标系的变换。
  67. /// </summary>
  68. /// <see cref="UpdateGlobalTransform()"/>
  69. /// <version>DragonBones 3.0</version>
  70. /// <language>zh_CN</language>
  71. public readonly TransformDB global = new TransformDB();
  72. /// <summary>
  73. /// - The offset transform relative to the armature or the parent bone coordinate system.
  74. /// </summary>
  75. /// <see cref="dragonBones.Bone.InvalidUpdate()"/>
  76. /// <version>DragonBones 3.0</version>
  77. /// <language>en_US</language>
  78. /// <summary>
  79. /// - 相对于骨架或父骨骼坐标系的偏移变换。
  80. /// </summary>
  81. /// <see cref="dragonBones.Bone.InvalidUpdate()"/>
  82. /// <version>DragonBones 3.0</version>
  83. /// <language>zh_CN</language>
  84. public readonly TransformDB offset = new TransformDB();
  85. /// <private/>
  86. public TransformDB origin;
  87. /// <private/>
  88. public object userData;
  89. /// <private/>
  90. protected bool _globalDirty;
  91. /// <internal/>
  92. /// <private/>
  93. internal Armature _armature;
  94. /// <private/>
  95. protected override void _OnClear()
  96. {
  97. this.globalTransformMatrix.Identity();
  98. this.global.Identity();
  99. this.offset.Identity();
  100. this.origin = null; //
  101. this.userData = null;
  102. this._globalDirty = false;
  103. this._armature = null; //
  104. }
  105. /// <summary>
  106. /// - For performance considerations, rotation or scale in the {@link #global} attribute of the bone or slot is not always properly accessible,
  107. /// some engines do not rely on these attributes to update rendering, such as Egret.
  108. /// The use of this method ensures that the access to the {@link #global} property is correctly rotation or scale.
  109. /// </summary>
  110. /// <example>
  111. /// TypeScript style, for reference only.
  112. /// <pre>
  113. /// bone.updateGlobalTransform();
  114. /// let rotation = bone.global.rotation;
  115. /// </pre>
  116. /// </example>
  117. /// <version>DragonBones 3.0</version>
  118. /// <language>en_US</language>
  119. /// <summary>
  120. /// - 出于性能的考虑,骨骼或插槽的 {@link #global} 属性中的旋转或缩放并不总是正确可访问的,有些引擎并不依赖这些属性更新渲染,比如 Egret。
  121. /// 使用此方法可以保证访问到 {@link #global} 属性中正确的旋转或缩放。
  122. /// </summary>
  123. /// <example>
  124. /// TypeScript 风格,仅供参考。
  125. /// <pre>
  126. /// bone.updateGlobalTransform();
  127. /// let rotation = bone.global.rotation;
  128. /// </pre>
  129. /// </example>
  130. /// <version>DragonBones 3.0</version>
  131. /// <language>zh_CN</language>
  132. public void UpdateGlobalTransform()
  133. {
  134. if (this._globalDirty)
  135. {
  136. this._globalDirty = false;
  137. this.global.FromMatrix(this.globalTransformMatrix);
  138. }
  139. }
  140. /// <summary>
  141. /// - The armature to which it belongs.
  142. /// </summary>
  143. /// <version>DragonBones 3.0</version>
  144. /// <language>en_US</language>
  145. /// <summary>
  146. /// - 所属的骨架。
  147. /// </summary>
  148. /// <version>DragonBones 3.0</version>
  149. /// <language>zh_CN</language>
  150. public Armature armature
  151. {
  152. get{ return this._armature; }
  153. }
  154. }
  155. }