Gizmos.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using System.Runtime.CompilerServices;
  2. using BansheeEngine;
  3. namespace BansheeEditor
  4. {
  5. /// <summary>
  6. /// Provides functionality for drawing gizmos. This class should only be used in methods defined with
  7. /// <see cref="DrawGizmo"/> attribute.
  8. /// </summary>
  9. public class Gizmos
  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. get
  17. {
  18. Color value;
  19. Internal_GetColor(out value);
  20. return value;
  21. }
  22. set
  23. {
  24. Internal_SetColor(ref value);
  25. }
  26. }
  27. /// <summary>
  28. /// Determines the world transform that will be applied to any following draw method.
  29. /// </summary>
  30. public static Matrix4 Transform
  31. {
  32. get
  33. {
  34. Matrix4 value;
  35. Internal_GetTransform(out value);
  36. return value;
  37. }
  38. set
  39. {
  40. Internal_SetTransform(ref value);
  41. }
  42. }
  43. /// <summary>
  44. /// Draws an axis aligned solid cube.
  45. /// </summary>
  46. /// <param name="position">World coordinates of the center of the cube.</param>
  47. /// <param name="extents">Extents defining the half-size of the cube in each dimension.</param>
  48. public static void DrawCube(Vector3 position, Vector3 extents)
  49. {
  50. Internal_DrawCube(ref position, ref extents);
  51. }
  52. /// <summary>
  53. /// Draws a solid sphere.
  54. /// </summary>
  55. /// <param name="position">World coordinates of the center of the sphere.</param>
  56. /// <param name="radius">Sphere radius.</param>
  57. public static void DrawSphere(Vector3 position, float radius)
  58. {
  59. Internal_DrawSphere(ref position, radius);
  60. }
  61. /// <summary>
  62. /// Draws an axis aligned wireframe cube.
  63. /// </summary>
  64. /// <param name="position">World coordinates of the center of the cube.</param>
  65. /// <param name="extents">Extents defining the half-size of the cube in each dimension.</param>
  66. public static void DrawWireCube(Vector3 position, Vector3 extents)
  67. {
  68. Internal_DrawWireCube(ref position, ref extents);
  69. }
  70. /// <summary>
  71. /// Draws a wireframe sphere.
  72. /// </summary>
  73. /// <param name="position">World coordinates of the center of the sphere.</param>
  74. /// <param name="radius">Sphere radius.</param>
  75. public static void DrawWireSphere(Vector3 position, float radius)
  76. {
  77. Internal_DrawWireSphere(ref position, radius);
  78. }
  79. /// <summary>
  80. /// Draws a 3D line.
  81. /// </summary>
  82. /// <param name="start">Starting point for the line.</param>
  83. /// <param name="end">Ending point for the line.</param>
  84. public static void DrawLine(Vector3 start, Vector3 end)
  85. {
  86. Internal_DrawLine(ref start, ref end);
  87. }
  88. /// <summary>
  89. /// Draws a wireframe disc.
  90. /// </summary>
  91. /// <param name="position">Center of the disc.</param>
  92. /// <param name="normal">Normal towards which to orient the disc.</param>
  93. /// <param name="radius">Radius of the disc.</param>
  94. public static void DrawWireDisc(Vector3 position, Vector3 normal, float radius)
  95. {
  96. Internal_DrawWireDisc(ref position, ref normal, radius);
  97. }
  98. /// <summary>
  99. /// Draws a wireframe arc.
  100. /// </summary>
  101. /// <param name="position">Center of the disc out of which the arc is cut out of.</param>
  102. /// <param name="normal">Normal towards which to orient the arc.</param>
  103. /// <param name="radius">Radius of the disc out of which the arc is cut out of.</param>
  104. /// <param name="startAngle">Angle at which the arc starts.</param>
  105. /// <param name="amountAngle">Length of the arc.</param>
  106. public static void DrawWireArc(Vector3 position, Vector3 normal, float radius, Degree startAngle, Degree amountAngle)
  107. {
  108. Internal_DrawWireArc(ref position, ref normal, radius, startAngle.Degrees, amountAngle.Degrees);
  109. }
  110. /// <summary>
  111. /// Draws a wireframe camera frustum.
  112. /// </summary>
  113. /// <param name="position">Origin of the frustum (place where the camera origin would normally be).</param>
  114. /// <param name="aspect">Aspect radio (width/height).</param>
  115. /// <param name="FOV">Horizontal field of view.</param>
  116. /// <param name="near">Distance from the origin to the near plane.</param>
  117. /// <param name="far">Distance from the origin to the far plane.</param>
  118. public static void DrawFrustum(Vector3 position, float aspect, Degree FOV, float near, float far)
  119. {
  120. Internal_DrawFrustum(ref position, aspect, ref FOV, near, far);
  121. }
  122. /// <summary>
  123. /// Draws a texture as a camera-facing quad at a specific position.
  124. /// </summary>
  125. /// <param name="position">World position of the center of the quad the texture will be drawn on.</param>
  126. /// <param name="image">Texture to draw.</param>
  127. /// <param name="fixedScale">If true the icon will remain consistent size regardless of distance from camera.
  128. /// If false normal perspective foreshortening effect will occurr.</param>
  129. public static void DrawIcon(Vector3 position, SpriteTexture image, bool fixedScale)
  130. {
  131. Internal_DrawIcon(ref position, image, fixedScale);
  132. }
  133. [MethodImpl(MethodImplOptions.InternalCall)]
  134. private static extern void Internal_SetColor(ref Color color);
  135. [MethodImpl(MethodImplOptions.InternalCall)]
  136. private static extern void Internal_GetColor(out Color color);
  137. [MethodImpl(MethodImplOptions.InternalCall)]
  138. private static extern void Internal_SetTransform(ref Matrix4 transform);
  139. [MethodImpl(MethodImplOptions.InternalCall)]
  140. private static extern void Internal_GetTransform(out Matrix4 transform);
  141. [MethodImpl(MethodImplOptions.InternalCall)]
  142. private static extern void Internal_DrawCube(ref Vector3 position, ref Vector3 extents);
  143. [MethodImpl(MethodImplOptions.InternalCall)]
  144. private static extern void Internal_DrawSphere(ref Vector3 position, float radius);
  145. [MethodImpl(MethodImplOptions.InternalCall)]
  146. private static extern void Internal_DrawWireCube(ref Vector3 position, ref Vector3 extents);
  147. [MethodImpl(MethodImplOptions.InternalCall)]
  148. private static extern void Internal_DrawWireSphere(ref Vector3 position, float radius);
  149. [MethodImpl(MethodImplOptions.InternalCall)]
  150. private static extern void Internal_DrawLine(ref Vector3 start, ref Vector3 end);
  151. [MethodImpl(MethodImplOptions.InternalCall)]
  152. private static extern void Internal_DrawWireDisc(ref Vector3 position, ref Vector3 normal, float radius);
  153. [MethodImpl(MethodImplOptions.InternalCall)]
  154. private static extern void Internal_DrawWireArc(ref Vector3 position, ref Vector3 normal, float radius,
  155. float startAngle, float amountAngle);
  156. [MethodImpl(MethodImplOptions.InternalCall)]
  157. private static extern void Internal_DrawFrustum(ref Vector3 position, float aspect, ref Degree FOV, float near, float far);
  158. [MethodImpl(MethodImplOptions.InternalCall)]
  159. private static extern void Internal_DrawIcon(ref Vector3 position, SpriteTexture image, bool fixedScale);
  160. }
  161. }