| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- using System.Runtime.CompilerServices;
- using bs;
- using System;
- namespace bs.Editor
- {
- /** @addtogroup Handles
- * @{
- */
- /// <summary>
- /// Contains various method that can be used for drawing handles. These methods should only be called from
- /// <see cref="Handle.Draw"/> method or its overrides.
- /// </summary>
- public sealed class HandleDrawing
- {
- /// <summary>
- /// Determines the color that will be used on any following draw method.
- /// </summary>
- public static Color Color
- {
- set { Internal_SetColor(ref value); }
- }
- /// <summary>
- /// Determines the world transform that will be applied to any following draw method.
- /// </summary>
- public static Matrix4 Transform
- {
- set { Internal_SetTransform(ref value); }
- }
- /// <summary>
- /// Layer bitfield that controls whether a handle is considered visible in a specific camera. Handle layer
- /// must match camera layer in order for the camera to render it.
- /// </summary>
- public static UInt64 Layer
- {
- set { Internal_SetLayer(value); }
- }
- /// <summary>
- /// Draws an axis aligned solid cube.
- /// </summary>
- /// <param name="position">World coordinates of the center of the cube.</param>
- /// <param name="extents">Extents defining the half-size of the cube in each dimension.</param>
- /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
- /// handle size regardless of distance from camera.</param>
- public static void DrawCube(Vector3 position, Vector3 extents, float size = 1.0f)
- {
- Internal_DrawCube(ref position, ref extents, size);
- }
- /// <summary>
- /// Draws a solid sphere.
- /// </summary>
- /// <param name="position">World coordinates of the center of the sphere.</param>
- /// <param name="radius">Sphere radius.</param>
- /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
- /// handle size regardless of distance from camera.</param>
- public static void DrawSphere(Vector3 position, float radius, float size = 1.0f)
- {
- Internal_DrawSphere(ref position, radius, size);
- }
- /// <summary>
- /// Draws an axis aligned wireframe cube.
- /// </summary>
- /// <param name="position">World coordinates of the center of the cube.</param>
- /// <param name="extents">Extents defining the half-size of the cube in each dimension.</param>
- /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
- /// handle size regardless of distance from camera.</param>
- public static void DrawWireCube(Vector3 position, Vector3 extents, float size = 1.0f)
- {
- Internal_DrawWireCube(ref position, ref extents, size);
- }
- /// <summary>
- /// Draws a wireframe sphere.
- /// </summary>
- /// <param name="position">World coordinates of the center of the sphere.</param>
- /// <param name="radius">Sphere radius.</param>
- /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
- /// handle size regardless of distance from camera.</param>
- public static void DrawWireSphere(Vector3 position, float radius, float size = 1.0f)
- {
- Internal_DrawWireSphere(ref position, radius, size);
- }
- /// <summary>
- /// Draws a solid cone.
- /// </summary>
- /// <param name="coneBase">Location of the cone base (center of the cone disc).</param>
- /// <param name="normal">Normal pointing from the base to the cone point.</param>
- /// <param name="height">Distance from the origin to the cone point.</param>
- /// <param name="radius">Radius of the cone disc.</param>
- /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
- /// handle size regardless of distance from camera.</param>
- public static void DrawCone(Vector3 coneBase, Vector3 normal, float height, float radius, float size = 1.0f)
- {
- Internal_DrawCone(ref coneBase, ref normal, height, radius, size);
- }
- /// <summary>
- /// Draws a 3D line.
- /// </summary>
- /// <param name="start">Starting point for the line.</param>
- /// <param name="end">Ending point for the line.</param>
- /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
- /// handle size regardless of distance from camera.</param>
- public static void DrawLine(Vector3 start, Vector3 end, float size = 1.0f)
- {
- Internal_DrawLine(ref start, ref end, size);
- }
- /// <summary>
- /// Draws a solid double-sided disc.
- /// </summary>
- /// <param name="position">Center of the disc.</param>
- /// <param name="normal">Normal towards which to orient the disc.</param>
- /// <param name="radius">Radius of the disc.</param>
- /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
- /// handle size regardless of distance from camera.</param>
- public static void DrawDisc(Vector3 position, Vector3 normal, float radius, float size = 1.0f)
- {
- Internal_DrawDisc(ref position, ref normal, radius, size);
- }
- /// <summary>
- /// Draws a wireframe disc.
- /// </summary>
- /// <param name="position">Center of the disc.</param>
- /// <param name="normal">Normal towards which to orient the disc.</param>
- /// <param name="radius">Radius of the disc.</param>
- /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
- /// handle size regardless of distance from camera.</param>
- public static void DrawWireDisc(Vector3 position, Vector3 normal, float radius, float size = 1.0f)
- {
- Internal_DrawWireDisc(ref position, ref normal, radius, size);
- }
- /// <summary>
- /// Draws a solid double-sided arc.
- /// </summary>
- /// <param name="position">Center of the disc out of which the arc is cut out of.</param>
- /// <param name="normal">Normal towards which to orient the arc.</param>
- /// <param name="radius">Radius of the disc out of which the arc is cut out of.</param>
- /// <param name="startAngle">Angle at which the arc starts.</param>
- /// <param name="amountAngle">Length of the arc.</param>
- /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
- /// handle size regardless of distance from camera.</param>
- public static void DrawArc(Vector3 position, Vector3 normal, float radius, Degree startAngle, Degree amountAngle,
- float size = 1.0f)
- {
- Internal_DrawArc(ref position, ref normal, radius, ref startAngle, ref amountAngle, size);
- }
- /// <summary>
- /// Draws a wireframe arc.
- /// </summary>
- /// <param name="position">Center of the disc out of which the arc is cut out of.</param>
- /// <param name="normal">Normal towards which to orient the arc.</param>
- /// <param name="radius">Radius of the disc out of which the arc is cut out of.</param>
- /// <param name="startAngle">Angle at which the arc starts.</param>
- /// <param name="amountAngle">Length of the arc.</param>
- /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
- /// handle size regardless of distance from camera.</param>
- public static void DrawWireArc(Vector3 position, Vector3 normal, float radius, Degree startAngle,
- Degree amountAngle, float size = 1.0f)
- {
- Internal_DrawWireArc(ref position, ref normal, radius, ref startAngle, ref amountAngle, size);
- }
- /// <summary>
- /// Draws a single-sided rectangle in 3D.
- /// </summary>
- /// <param name="area">Determines the position, orientation and size of the rectangle.</param>
- /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining
- /// handle size regardless of distance from camera.</param>
- public static void DrawRect(Rect3 area, float size = 1.0f)
- {
- Vector3 center = area.Center;
- Vector3 axisHorz = area.AxisHorz;
- Vector3 axisVert = area.AxisVert;
- Internal_DrawRect(ref center, ref axisHorz, ref axisVert, area.ExtentHorz, area.ExtentVert, size);
- }
- /// <summary>
- /// Draws camera aligned text at the specified position.
- /// </summary>
- /// <param name="position">World position to center the text on.</param>
- /// <param name="text">String to draw.</param>
- /// <param name="font">Font used for drawing the characters.</param>
- /// <param name="fontSize">Size of the characters, in points.</param>
- public static void DrawText(Vector3 position, string text, Font font = null, int fontSize = 16)
- {
- IntPtr scriptFont = IntPtr.Zero;
- if (font != null)
- scriptFont = font.GetCachedPtr();
- Internal_DrawText(ref position, text, scriptFont, fontSize);
- }
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_SetColor(ref Color color);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_SetTransform(ref Matrix4 transform);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_SetLayer(UInt64 layer);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_DrawCube(ref Vector3 position, ref Vector3 extents, float size);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_DrawSphere(ref Vector3 position, float radius, float size);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_DrawWireCube(ref Vector3 position, ref Vector3 extents, float size);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_DrawWireSphere(ref Vector3 position, float radius, float size);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_DrawCone(ref Vector3 coneBase, ref Vector3 normal, float height, float radius, float size);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_DrawLine(ref Vector3 start, ref Vector3 end, float size);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_DrawDisc(ref Vector3 position, ref Vector3 normal, float radius, float size);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_DrawWireDisc(ref Vector3 position, ref Vector3 normal, float radius, float size);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_DrawArc(ref Vector3 position, ref Vector3 normal, float radius, ref Degree startAngle, ref Degree amountAngle, float size);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_DrawWireArc(ref Vector3 position, ref Vector3 normal, float radius, ref Degree startAngle, ref Degree amountAngle, float size);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_DrawRect(ref Vector3 center, ref Vector3 axisH, ref Vector3 axisV, float extentH, float extentV, float size);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_DrawText(ref Vector3 position, string text, IntPtr font, int fontSize);
- }
- /** @} */
- }
|