Example #1
0
    /// <summary>
    ///     - Gizmoss a cone.
    /// </summary>
    /// <param name='position'>
    ///     - The position for the tip of the cone.
    /// </param>
    /// <param name='direction'>
    ///     - The direction for the cone gets wider in.
    /// </param>
    /// <param name='angle'>
    ///     - The angle of the cone.
    /// </param>
    /// <param name='color'>
    ///     - The color of the cone.
    /// </param>
    /// <param name='duration'>
    ///     - How long to draw the cone.
    /// </param>
    /// <param name='depthTest'>
    ///     - Whether or not the cone should be faded when behind other objects.
    /// </param>
    public static void GizmosCone(Vector3 position, Vector3 direction, float angle = 45)
    {
        float length = direction.magnitude;

        Vector3 _forward = direction;
        Vector3 _up      = Vector3.Slerp(_forward, -_forward, 0.5f);
        Vector3 _right   = Vector3.Cross(_forward, _up).normalized *length;

        direction = direction.normalized;

        Vector3 slerpedVector = Vector3.Slerp(_forward, _up, angle / 90.0f);

        float dist;
        var   farPlane = new Plane(-direction, position + _forward);
        var   distRay  = new Ray(position, slerpedVector);

        farPlane.Raycast(distRay, out dist);

        Gizmos.DrawRay(position, slerpedVector.normalized * dist);
        Gizmos.DrawRay(position, Vector3.Slerp(_forward, -_up, angle / 90.0f).normalized *dist);
        Gizmos.DrawRay(position, Vector3.Slerp(_forward, _right, angle / 90.0f).normalized *dist);
        Gizmos.DrawRay(position, Vector3.Slerp(_forward, -_right, angle / 90.0f).normalized *dist);

        GizmosExtension.GizmosCircle(position + _forward, direction, (_forward - (slerpedVector.normalized * dist)).magnitude);
        GizmosExtension.GizmosCircle(position + (_forward * 0.5f), direction, ((_forward * 0.5f) - (slerpedVector.normalized * (dist * 0.5f))).magnitude);
    }
Example #2
0
    /// <summary>
    ///     - Gizmoss a cylinder.
    /// </summary>
    /// <param name='start'>
    ///     - The position of one end of the cylinder.
    /// </param>
    /// <param name='end'>
    ///     - The position of the other end of the cylinder.
    /// </param>
    /// <param name='color'>
    ///     - The color of the cylinder.
    /// </param>
    /// <param name='radius'>
    ///     - The radius of the cylinder.
    /// </param>
    /// <param name='duration'>
    ///     - How long to draw the cylinder.
    /// </param>
    /// <param name='depthTest'>
    ///     - Whether or not the cylinder should be faded when behind other objects.
    /// </param>
    public static void GizmosCylinder(Vector3 start, Vector3 end, float radius = 1)
    {
        Vector3 up      = (end - start).normalized * radius;
        Vector3 forward = Vector3.Slerp(up, -up, 0.5f);
        Vector3 right   = Vector3.Cross(up, forward).normalized *radius;

        //Radial circles
        GizmosExtension.GizmosCircle(start, up, radius);
        GizmosExtension.GizmosCircle(end, -up, radius);
        GizmosExtension.GizmosCircle((start + end) * 0.5f, up, radius);

        //Side lines
        Gizmos.DrawLine(start + right, end + right);
        Gizmos.DrawLine(start - right, end - right);

        Gizmos.DrawLine(start + forward, end + forward);
        Gizmos.DrawLine(start - forward, end - forward);

        //Start endcap
        Gizmos.DrawLine(start - right, start + right);
        Gizmos.DrawLine(start - forward, start + forward);

        //End endcap
        Gizmos.DrawLine(end - right, end + right);
        Gizmos.DrawLine(end - forward, end + forward);
    }