//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
//**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************//
using System;
using bs;
namespace bs.Editor
{
/** @addtogroup Handles
* @{
*/
///
/// Manages various global values relating to handles.
///
public sealed class Handles
{
///
/// Determines if snapping for move handle is active. When active the move handle can only be moved in increments
/// specified by .
///
public static bool MoveHandleSnapActive
{
get { return EditorSettings.MoveHandleSnapActive; }
set { EditorSettings.MoveHandleSnapActive = value; }
}
///
/// Determines if snapping for rotate handle is active. When active the rotate handle can only be rotated in
/// increments specified by .
///
public static bool RotateHandleSnapActive
{
get { return EditorSettings.RotateHandleSnapActive; }
set { EditorSettings.RotateHandleSnapActive = value; }
}
///
/// Determines size of the increments the move handle can be moved when is
/// active.
///
public static float MoveSnapAmount
{
get { return EditorSettings.MoveHandleSnapAmount; }
set { EditorSettings.MoveHandleSnapAmount = value; }
}
///
/// Determines size of the increments the rotate handle can be moved when is
/// active.
///
public static Degree RotateSnapAmount
{
get { return EditorSettings.RotateHandleSnapAmount; }
set { EditorSettings.RotateHandleSnapAmount = value; }
}
///
/// Snaps a value to the specified increments.
///
/// Value to snap.
/// Increment to which to snap the value to.
/// Value snapped to the provided increments.
public static float SnapValue(float value, float snapAmount)
{
if (snapAmount > 0)
return MathEx.RoundToInt(value / snapAmount) * snapAmount;
return value;
}
///
/// Snaps an angle value to the specified increments.
///
/// Value to snap.
/// Increment to which to snap the value to.
/// Value snapped to the provided increments.
public static Degree SnapValue(Degree value, Degree snapAmount)
{
return (Degree)SnapValue(value.Degrees, snapAmount.Degrees);
}
///
/// Returns a scale that can be applied to a handle in order to keep it at constant size regardless of distance
/// from the provided camera.
///
/// Camera through which the handle is being viewed.
/// Center of the handle.
/// Uniform scale to apply to the handle.
public static float GetHandleSize(Camera camera, Vector3 position)
{
if (camera.ProjectionType == ProjectionType.Perspective)
{
Vector3 cameraPos = camera.SceneObject.Position;
Vector3 diff = position - cameraPos;
float distAlongViewDir = Math.Abs(Vector3.Dot(diff, camera.SceneObject.Rotation.Forward));
return distAlongViewDir*EditorSettings.DefaultHandleSize;
}
else
{
return camera.OrthoHeight*EditorSettings.DefaultHandleSize;
}
}
}
/** @} */
}