HandleDrawing.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using System.Runtime.CompilerServices;
  2. using BansheeEngine;
  3. namespace BansheeEditor
  4. {
  5. /// <summary>
  6. /// Contains various method that can be used for drawing handles. These methods should only be called from
  7. /// <see cref="Handle.Draw"/> method or its overrides.
  8. /// </summary>
  9. public sealed class HandleDrawing
  10. {
  11. /// <summary>
  12. /// Determines the color that will be used on any following draw method.
  13. /// </summary>
  14. public static Color Color
  15. {
  16. set { Internal_SetColor(value); }
  17. }
  18. /// <summary>
  19. /// Determines the world transform that will be applied to any following draw method.
  20. /// </summary>
  21. public static Matrix4 Transform
  22. {
  23. set { Internal_SetTransform(value); }
  24. }
  25. /// <summary>
  26. /// Draws an axis aligned solid cube.
  27. /// </summary>
  28. /// <param name="position">World coordinates of the center of the cube.</param>
  29. /// <param name="extents">Extents defining the half-size of the cube in each dimension.</param>
  30. /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
  31. /// handle size regardless of distance from camera.</param>
  32. public static void DrawCube(Vector3 position, Vector3 extents, float size = 1.0f)
  33. {
  34. Internal_DrawCube(position, extents, size);
  35. }
  36. /// <summary>
  37. /// Draws a solid sphere.
  38. /// </summary>
  39. /// <param name="position">World coordinates of the center of the sphere.</param>
  40. /// <param name="radius">Sphere radius.</param>
  41. /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
  42. /// handle size regardless of distance from camera.</param>
  43. public static void DrawSphere(Vector3 position, float radius, float size = 1.0f)
  44. {
  45. Internal_DrawSphere(position, radius, size);
  46. }
  47. /// <summary>
  48. /// Draws an axis aligned wireframe cube.
  49. /// </summary>
  50. /// <param name="position">World coordinates of the center of the cube.</param>
  51. /// <param name="extents">Extents defining the half-size of the cube in each dimension.</param>
  52. /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
  53. /// handle size regardless of distance from camera.</param>
  54. public static void DrawWireCube(Vector3 position, Vector3 extents, float size = 1.0f)
  55. {
  56. Internal_DrawWireCube(position, extents, size);
  57. }
  58. /// <summary>
  59. /// Draws a wireframe sphere.
  60. /// </summary>
  61. /// <param name="position">World coordinates of the center of the sphere.</param>
  62. /// <param name="radius">Sphere radius.</param>
  63. /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
  64. /// handle size regardless of distance from camera.</param>
  65. public static void DrawWireSphere(Vector3 position, float radius, float size = 1.0f)
  66. {
  67. Internal_DrawWireSphere(position, radius, size);
  68. }
  69. /// <summary>
  70. /// Draws a solid cone.
  71. /// </summary>
  72. /// <param name="coneBase">Location of the cone base (center of the cone disc).</param>
  73. /// <param name="normal">Normal pointing from the base to the cone point.</param>
  74. /// <param name="height">Distance from the origin to the cone point.</param>
  75. /// <param name="radius">Radius of the cone disc.</param>
  76. /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
  77. /// handle size regardless of distance from camera.</param>
  78. public static void DrawCone(Vector3 coneBase, Vector3 normal, float height, float radius, float size = 1.0f)
  79. {
  80. Internal_DrawCone(coneBase, normal, height, radius, size);
  81. }
  82. /// <summary>
  83. /// Draws a 3D line.
  84. /// </summary>
  85. /// <param name="start">Starting point for the line.</param>
  86. /// <param name="end">Ending point for the line.</param>
  87. /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
  88. /// handle size regardless of distance from camera.</param>
  89. public static void DrawLine(Vector3 start, Vector3 end, float size = 1.0f)
  90. {
  91. Internal_DrawLine(start, end, size);
  92. }
  93. /// <summary>
  94. /// Draws a solid double-sided disc.
  95. /// </summary>
  96. /// <param name="position">Center of the disc.</param>
  97. /// <param name="normal">Normal towards which to orient the disc.</param>
  98. /// <param name="radius">Radius of the disc.</param>
  99. /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
  100. /// handle size regardless of distance from camera.</param>
  101. public static void DrawDisc(Vector3 position, Vector3 normal, float radius, float size = 1.0f)
  102. {
  103. Internal_DrawDisc(position, normal, radius, size);
  104. }
  105. /// <summary>
  106. /// Draws a wireframe disc.
  107. /// </summary>
  108. /// <param name="position">Center of the disc.</param>
  109. /// <param name="normal">Normal towards which to orient the disc.</param>
  110. /// <param name="radius">Radius of the disc.</param>
  111. /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
  112. /// handle size regardless of distance from camera.</param>
  113. public static void DrawWireDisc(Vector3 position, Vector3 normal, float radius, float size = 1.0f)
  114. {
  115. Internal_DrawWireDisc(position, normal, radius, size);
  116. }
  117. /// <summary>
  118. /// Draws a solid double-sided arc.
  119. /// </summary>
  120. /// <param name="position">Center of the disc out of which the arc is cut out of.</param>
  121. /// <param name="normal">Normal towards which to orient the arc.</param>
  122. /// <param name="radius">Radius of the disc out of which the arc is cut out of.</param>
  123. /// <param name="startAngle">Angle at which the arc starts.</param>
  124. /// <param name="amountAngle">Length of the arc.</param>
  125. /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
  126. /// handle size regardless of distance from camera.</param>
  127. public static void DrawArc(Vector3 position, Vector3 normal, float radius, Degree startAngle, Degree amountAngle, float size = 1.0f)
  128. {
  129. Internal_DrawArc(position, normal, radius, startAngle, amountAngle, size);
  130. }
  131. /// <summary>
  132. /// Draws a wireframe arc.
  133. /// </summary>
  134. /// <param name="position">Center of the disc out of which the arc is cut out of.</param>
  135. /// <param name="normal">Normal towards which to orient the arc.</param>
  136. /// <param name="radius">Radius of the disc out of which the arc is cut out of.</param>
  137. /// <param name="startAngle">Angle at which the arc starts.</param>
  138. /// <param name="amountAngle">Length of the arc.</param>
  139. /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
  140. /// handle size regardless of distance from camera.</param>
  141. public static void DrawWireArc(Vector3 position, Vector3 normal, float radius, Degree startAngle, Degree amountAngle, float size = 1.0f)
  142. {
  143. Internal_DrawWireArc(position, normal, radius, startAngle, amountAngle, size);
  144. }
  145. /// <summary>
  146. /// Draws a single-sided rectangle in 3D.
  147. /// </summary>
  148. /// <param name="area">Determines the position, orientation and size of the rectangle.</param>
  149. /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
  150. /// handle size regardless of distance from camera.</param>
  151. public static void DrawRect(Rect3 area, float size = 1.0f)
  152. {
  153. Internal_DrawRect(area.Center, area.AxisHorz, area.AxisVert, area.ExtentHorz, area.ExtentVert, size);
  154. }
  155. [MethodImpl(MethodImplOptions.InternalCall)]
  156. private static extern void Internal_SetColor(Color color);
  157. [MethodImpl(MethodImplOptions.InternalCall)]
  158. private static extern void Internal_SetTransform(Matrix4 transform);
  159. [MethodImpl(MethodImplOptions.InternalCall)]
  160. private static extern void Internal_DrawCube(Vector3 position, Vector3 extents, float size);
  161. [MethodImpl(MethodImplOptions.InternalCall)]
  162. private static extern void Internal_DrawSphere(Vector3 position, float radius, float size);
  163. [MethodImpl(MethodImplOptions.InternalCall)]
  164. private static extern void Internal_DrawWireCube(Vector3 position, Vector3 extents, float size);
  165. [MethodImpl(MethodImplOptions.InternalCall)]
  166. private static extern void Internal_DrawWireSphere(Vector3 position, float radius, float size);
  167. [MethodImpl(MethodImplOptions.InternalCall)]
  168. private static extern void Internal_DrawCone(Vector3 coneBase, Vector3 normal, float height, float radius, float size);
  169. [MethodImpl(MethodImplOptions.InternalCall)]
  170. private static extern void Internal_DrawLine(Vector3 start, Vector3 end, float size);
  171. [MethodImpl(MethodImplOptions.InternalCall)]
  172. private static extern void Internal_DrawDisc(Vector3 position, Vector3 normal, float radius, float size);
  173. [MethodImpl(MethodImplOptions.InternalCall)]
  174. private static extern void Internal_DrawWireDisc(Vector3 position, Vector3 normal, float radius, float size);
  175. [MethodImpl(MethodImplOptions.InternalCall)]
  176. private static extern void Internal_DrawArc(Vector3 position, Vector3 normal, float radius, Degree startAngle, Degree amountAngle, float size);
  177. [MethodImpl(MethodImplOptions.InternalCall)]
  178. private static extern void Internal_DrawWireArc(Vector3 position, Vector3 normal, float radius, Degree startAngle, Degree amountAngle, float size);
  179. [MethodImpl(MethodImplOptions.InternalCall)]
  180. private static extern void Internal_DrawRect(Vector3 center, Vector3 axisH, Vector3 axisV, float extentH, float extentV, float size);
  181. }
  182. }