|
@@ -2,6 +2,10 @@
|
|
|
|
|
|
|
|
namespace BansheeEditor
|
|
namespace BansheeEditor
|
|
|
{
|
|
{
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Handle that allows an object to be rotated around the three primary axes, as well as a free axis currently
|
|
|
|
|
+ /// facing the camera.
|
|
|
|
|
+ /// </summary>
|
|
|
public sealed class RotateHandle : DefaultHandle
|
|
public sealed class RotateHandle : DefaultHandle
|
|
|
{
|
|
{
|
|
|
private Quaternion delta;
|
|
private Quaternion delta;
|
|
@@ -15,11 +19,15 @@ namespace BansheeEditor
|
|
|
private bool isDragged;
|
|
private bool isDragged;
|
|
|
private Quaternion dragStartRotation;
|
|
private Quaternion dragStartRotation;
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Amount of rotation applied since the last frame. Only valid while the handle is being dragged.
|
|
|
|
|
+ /// </summary>
|
|
|
public Quaternion Delta
|
|
public Quaternion Delta
|
|
|
{
|
|
{
|
|
|
get { return delta; }
|
|
get { return delta; }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <inheritdoc/>
|
|
|
internal override bool IsDragged()
|
|
internal override bool IsDragged()
|
|
|
{
|
|
{
|
|
|
return xAxis.State == HandleSlider.StateType.Active ||
|
|
return xAxis.State == HandleSlider.StateType.Active ||
|
|
@@ -28,6 +36,9 @@ namespace BansheeEditor
|
|
|
freeAxis.State == HandleSlider.StateType.Active;
|
|
freeAxis.State == HandleSlider.StateType.Active;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Creates a new rotation handle.
|
|
|
|
|
+ /// </summary>
|
|
|
public RotateHandle()
|
|
public RotateHandle()
|
|
|
{
|
|
{
|
|
|
xAxis = new HandleSliderDisc(this, Vector3.XAxis, 1.0f);
|
|
xAxis = new HandleSliderDisc(this, Vector3.XAxis, 1.0f);
|
|
@@ -36,7 +47,8 @@ namespace BansheeEditor
|
|
|
freeAxis = new HandleSliderDisc(this, -Vector3.ZAxis, 1.2f);
|
|
freeAxis = new HandleSliderDisc(this, -Vector3.ZAxis, 1.2f);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected override void PreInput()
|
|
|
|
|
|
|
+ /// <inheritdoc/>
|
|
|
|
|
+ protected internal override void PreInput()
|
|
|
{
|
|
{
|
|
|
xAxis.Position = position;
|
|
xAxis.Position = position;
|
|
|
yAxis.Position = position;
|
|
yAxis.Position = position;
|
|
@@ -54,7 +66,8 @@ namespace BansheeEditor
|
|
|
zAxis.SetCutoffPlane(GetZStartAngle(isDragged), true);
|
|
zAxis.SetCutoffPlane(GetZStartAngle(isDragged), true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected override void PostInput()
|
|
|
|
|
|
|
+ /// <inheritdoc/>
|
|
|
|
|
+ protected internal override void PostInput()
|
|
|
{
|
|
{
|
|
|
if (IsDragged())
|
|
if (IsDragged())
|
|
|
{
|
|
{
|
|
@@ -96,64 +109,65 @@ namespace BansheeEditor
|
|
|
delta *= Quaternion.FromAxisAngle(cameraForward, freeAxisValue);
|
|
delta *= Quaternion.FromAxisAngle(cameraForward, freeAxisValue);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected override void Draw()
|
|
|
|
|
|
|
+ /// <inheritdoc/>
|
|
|
|
|
+ protected internal override void Draw()
|
|
|
{
|
|
{
|
|
|
- HandleDrawing.SetTransform(Matrix4.TRS(Position, Rotation, Vector3.One));
|
|
|
|
|
|
|
+ HandleDrawing.Transform = Matrix4.TRS(Position, Rotation, Vector3.One);
|
|
|
float handleSize = Handles.GetHandleSize(EditorApplication.SceneViewCamera, position);
|
|
float handleSize = Handles.GetHandleSize(EditorApplication.SceneViewCamera, position);
|
|
|
|
|
|
|
|
// Draw arcs
|
|
// Draw arcs
|
|
|
if (xAxis.State == HandleSlider.StateType.Active)
|
|
if (xAxis.State == HandleSlider.StateType.Active)
|
|
|
- HandleDrawing.SetColor(Color.White);
|
|
|
|
|
|
|
+ HandleDrawing.Color = Color.White;
|
|
|
else if(xAxis.State == HandleSlider.StateType.Hover)
|
|
else if(xAxis.State == HandleSlider.StateType.Hover)
|
|
|
- HandleDrawing.SetColor(Color.BansheeOrange);
|
|
|
|
|
|
|
+ HandleDrawing.Color = Color.BansheeOrange;
|
|
|
else
|
|
else
|
|
|
- HandleDrawing.SetColor(Color.Red);
|
|
|
|
|
|
|
+ HandleDrawing.Color = Color.Red;
|
|
|
|
|
|
|
|
HandleDrawing.DrawWireArc(Vector3.Zero, Vector3.XAxis, 1.0f, GetXStartAngle(false), -180.0f, handleSize);
|
|
HandleDrawing.DrawWireArc(Vector3.Zero, Vector3.XAxis, 1.0f, GetXStartAngle(false), -180.0f, handleSize);
|
|
|
|
|
|
|
|
if (yAxis.State == HandleSlider.StateType.Active)
|
|
if (yAxis.State == HandleSlider.StateType.Active)
|
|
|
- HandleDrawing.SetColor(Color.White);
|
|
|
|
|
|
|
+ HandleDrawing.Color = Color.White;
|
|
|
else if (yAxis.State == HandleSlider.StateType.Hover)
|
|
else if (yAxis.State == HandleSlider.StateType.Hover)
|
|
|
- HandleDrawing.SetColor(Color.BansheeOrange);
|
|
|
|
|
|
|
+ HandleDrawing.Color = Color.BansheeOrange;
|
|
|
else
|
|
else
|
|
|
- HandleDrawing.SetColor(Color.Green);
|
|
|
|
|
|
|
+ HandleDrawing.Color = Color.Green;
|
|
|
|
|
|
|
|
HandleDrawing.DrawWireArc(Vector3.Zero, Vector3.YAxis, 1.0f, GetYStartAngle(false), -180.0f, handleSize);
|
|
HandleDrawing.DrawWireArc(Vector3.Zero, Vector3.YAxis, 1.0f, GetYStartAngle(false), -180.0f, handleSize);
|
|
|
|
|
|
|
|
if (zAxis.State == HandleSlider.StateType.Active)
|
|
if (zAxis.State == HandleSlider.StateType.Active)
|
|
|
- HandleDrawing.SetColor(Color.White);
|
|
|
|
|
|
|
+ HandleDrawing.Color = Color.White;
|
|
|
else if (zAxis.State == HandleSlider.StateType.Hover)
|
|
else if (zAxis.State == HandleSlider.StateType.Hover)
|
|
|
- HandleDrawing.SetColor(Color.BansheeOrange);
|
|
|
|
|
|
|
+ HandleDrawing.Color = Color.BansheeOrange;
|
|
|
else
|
|
else
|
|
|
- HandleDrawing.SetColor(Color.Blue);
|
|
|
|
|
|
|
+ HandleDrawing.Color = Color.Blue;
|
|
|
|
|
|
|
|
HandleDrawing.DrawWireArc(Vector3.Zero, Vector3.ZAxis, 1.0f, GetZStartAngle(false), -180.0f, handleSize);
|
|
HandleDrawing.DrawWireArc(Vector3.Zero, Vector3.ZAxis, 1.0f, GetZStartAngle(false), -180.0f, handleSize);
|
|
|
|
|
|
|
|
// Draw "bounds" and free handle
|
|
// Draw "bounds" and free handle
|
|
|
Color gray = new Color(1.0f, 1.0f, 1.0f, 0.3f);
|
|
Color gray = new Color(1.0f, 1.0f, 1.0f, 0.3f);
|
|
|
Vector3 cameraNormal = EditorApplication.SceneViewCamera.SceneObject.Rotation.Rotate(Vector3.ZAxis);
|
|
Vector3 cameraNormal = EditorApplication.SceneViewCamera.SceneObject.Rotation.Rotate(Vector3.ZAxis);
|
|
|
- HandleDrawing.SetTransform(Matrix4.TRS(Position, Quaternion.Identity, Vector3.One));
|
|
|
|
|
- HandleDrawing.SetColor(gray);
|
|
|
|
|
|
|
+ HandleDrawing.Transform = Matrix4.TRS(Position, Quaternion.Identity, Vector3.One);
|
|
|
|
|
+ HandleDrawing.Color = gray;
|
|
|
|
|
|
|
|
HandleDrawing.DrawWireDisc(cameraNormal * 0.1f, cameraNormal, 1.0f, handleSize);
|
|
HandleDrawing.DrawWireDisc(cameraNormal * 0.1f, cameraNormal, 1.0f, handleSize);
|
|
|
|
|
|
|
|
if (freeAxis.State == HandleSlider.StateType.Active)
|
|
if (freeAxis.State == HandleSlider.StateType.Active)
|
|
|
- HandleDrawing.SetColor(Color.White);
|
|
|
|
|
|
|
+ HandleDrawing.Color = Color.White;
|
|
|
else if (freeAxis.State == HandleSlider.StateType.Hover)
|
|
else if (freeAxis.State == HandleSlider.StateType.Hover)
|
|
|
- HandleDrawing.SetColor(Color.BansheeOrange);
|
|
|
|
|
|
|
+ HandleDrawing.Color = Color.BansheeOrange;
|
|
|
else
|
|
else
|
|
|
- HandleDrawing.SetColor(gray);
|
|
|
|
|
|
|
+ HandleDrawing.Color = gray;
|
|
|
|
|
|
|
|
HandleDrawing.DrawWireDisc(Vector3.Zero, cameraNormal, 1.2f, handleSize);
|
|
HandleDrawing.DrawWireDisc(Vector3.Zero, cameraNormal, 1.2f, handleSize);
|
|
|
|
|
|
|
|
// Draw active rotation pie
|
|
// Draw active rotation pie
|
|
|
- HandleDrawing.SetColor(gray);
|
|
|
|
|
- HandleDrawing.SetTransform(Matrix4.TRS(Position, EditorApplication.SceneViewCamera.SceneObject.Rotation, Vector3.One));
|
|
|
|
|
|
|
+ HandleDrawing.Color = gray;
|
|
|
|
|
+ HandleDrawing.Transform = Matrix4.TRS(Position, EditorApplication.SceneViewCamera.SceneObject.Rotation, Vector3.One);
|
|
|
|
|
|
|
|
if (freeAxis.State == HandleSlider.StateType.Active)
|
|
if (freeAxis.State == HandleSlider.StateType.Active)
|
|
|
HandleDrawing.DrawArc(Vector3.Zero, -Vector3.ZAxis, 1.2f, freeAxis.StartAngle, freeAxis.Delta, handleSize);
|
|
HandleDrawing.DrawArc(Vector3.Zero, -Vector3.ZAxis, 1.2f, freeAxis.StartAngle, freeAxis.Delta, handleSize);
|
|
|
|
|
|
|
|
- HandleDrawing.SetTransform(Matrix4.TRS(Position, dragStartRotation, Vector3.One));
|
|
|
|
|
|
|
+ HandleDrawing.Transform = Matrix4.TRS(Position, dragStartRotation, Vector3.One);
|
|
|
|
|
|
|
|
if (xAxis.State == HandleSlider.StateType.Active)
|
|
if (xAxis.State == HandleSlider.StateType.Active)
|
|
|
HandleDrawing.DrawArc(Vector3.Zero, Vector3.XAxis, 1.0f, xAxis.StartAngle, xAxis.Delta, handleSize);
|
|
HandleDrawing.DrawArc(Vector3.Zero, Vector3.XAxis, 1.0f, xAxis.StartAngle, xAxis.Delta, handleSize);
|
|
@@ -163,6 +177,14 @@ namespace BansheeEditor
|
|
|
HandleDrawing.DrawArc(Vector3.Zero, Vector3.ZAxis, 1.0f, zAxis.StartAngle, zAxis.Delta, handleSize);
|
|
HandleDrawing.DrawArc(Vector3.Zero, Vector3.ZAxis, 1.0f, zAxis.StartAngle, zAxis.Delta, handleSize);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// The rotate handle only displays the 180 degree arc facing the camera and this method returns the angle at which
|
|
|
|
|
+ /// the arc starts for the X axis.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="frozen">Determines should the local handle rotation be taken into account, or should it be frozen
|
|
|
|
|
+ /// to the value when handle drag started. This is useful because we do not want the visible
|
|
|
|
|
+ /// arc to change while the user is in the process of rotating the handle.</param>
|
|
|
|
|
+ /// <returns>Angle at which to display the visible arc for the X axis rotations.</returns>
|
|
|
private Degree GetXStartAngle(bool frozen)
|
|
private Degree GetXStartAngle(bool frozen)
|
|
|
{
|
|
{
|
|
|
Quaternion handleRotation = frozen ? dragStartRotation : Rotation;
|
|
Quaternion handleRotation = frozen ? dragStartRotation : Rotation;
|
|
@@ -171,6 +193,14 @@ namespace BansheeEditor
|
|
|
return PointOnCircleToAngle(Vector3.XAxis, xStartDir);
|
|
return PointOnCircleToAngle(Vector3.XAxis, xStartDir);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// The rotate handle only displays the 180 degree arc facing the camera and this method returns the angle at which
|
|
|
|
|
+ /// the arc starts for the Y axis.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="frozen">Determines should the local handle rotation be taken into account, or should it be frozen
|
|
|
|
|
+ /// to the value when handle drag started. This is useful because we do not want the visible
|
|
|
|
|
+ /// arc to change while the user is in the process of rotating the handle.</param>
|
|
|
|
|
+ /// <returns>Angle at which to display the visible arc for the Y axis rotations.</returns>
|
|
|
private Degree GetYStartAngle(bool frozen)
|
|
private Degree GetYStartAngle(bool frozen)
|
|
|
{
|
|
{
|
|
|
Quaternion handleRotation = frozen ? dragStartRotation : Rotation;
|
|
Quaternion handleRotation = frozen ? dragStartRotation : Rotation;
|
|
@@ -179,6 +209,14 @@ namespace BansheeEditor
|
|
|
return PointOnCircleToAngle(Vector3.YAxis, yStartDir);
|
|
return PointOnCircleToAngle(Vector3.YAxis, yStartDir);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// The rotate handle only displays the 180 degree arc facing the camera and this method returns the angle at which
|
|
|
|
|
+ /// the arc starts for the Z axis.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="frozen">Determines should the local handle rotation be taken into account, or should it be frozen
|
|
|
|
|
+ /// to the value when handle drag started. This is useful because we do not want the visible
|
|
|
|
|
+ /// arc to change while the user is in the process of rotating the handle.</param>
|
|
|
|
|
+ /// <returns>Angle at which to display the visible arc for the Z axis rotations.</returns>
|
|
|
private Degree GetZStartAngle(bool frozen)
|
|
private Degree GetZStartAngle(bool frozen)
|
|
|
{
|
|
{
|
|
|
Quaternion handleRotation = frozen ? dragStartRotation : Rotation;
|
|
Quaternion handleRotation = frozen ? dragStartRotation : Rotation;
|
|
@@ -187,6 +225,12 @@ namespace BansheeEditor
|
|
|
return PointOnCircleToAngle(Vector3.ZAxis, zStartDir);
|
|
return PointOnCircleToAngle(Vector3.ZAxis, zStartDir);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Converts a point on the circle to an angle on the circle.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="up">Up vector determining the orientation of the circle.</param>
|
|
|
|
|
+ /// <param name="point">Point along a unit circle centered around the origin.</param>
|
|
|
|
|
+ /// <returns>Angle at which the provided point is located on the circle.</returns>
|
|
|
private Degree PointOnCircleToAngle(Vector3 up, Vector3 point)
|
|
private Degree PointOnCircleToAngle(Vector3 up, Vector3 point)
|
|
|
{
|
|
{
|
|
|
Quaternion rot = Quaternion.FromToRotation(up, Vector3.YAxis);
|
|
Quaternion rot = Quaternion.FromToRotation(up, Vector3.YAxis);
|