HandleDrawing.cs 12 KB

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