When you click on a gizmo handle and then start dragging the mouse, the hovered gizmo enters a drag session. This section illustrates how drag information can be extracted.

Accessing the Dragged Gizmo

In order to get access to the currently dragged gizmo, you need to use the RTGizmosEngine class:

// Get a reference to the dragged gizmo
// Note: If no gizmo is dragged, the DraggedGizmo property returns null.
Gizmo draggedGizmo = RTGizmosEngine.Get.DraggedGizmo;

If the returned value is null, it means no gizmo is dragged.

Note

There will always be ONE gizmo dragged at any one time.

Gizmo Drag State

You can check if a gizmo is dragged using the Gizmo.IsDragged property:

if (gizmo.IsDragged)
{
    // Do stuff
}

You can use this property to check if a specific gizmo is dragged. For example, the following code will check if either one of the move or rotation gizmos are dragged.

Gizmo moveGizmo = RTObjectSelectionGizmos.Get.GetGizmoById(ObjectSelectionGizmoId.MoveGizmo);
Gizmo rotationGizmo = RTObjectSelectionGizmos.Get.GetGizmoById(ObjectSelectionGizmoId.RotationGizmo);
if (moveGizmo.IsDragged || rotationGizmo.IsDragged)
{
    // Do stuff
}

Note

When the IsDragged property returns false, all other drag related properties (discussed next) should be ignored.

Drag Handle Information

You can also retrieve information about the dragged handle:

// Get the id of the gizmo drag handle
// Note: If the gizmo is not dragged, the DragHandleId property will return GizmoHandleId.None;
int dragHandleId = gizmo.DragHandleId;

// Get the dimension of the gizmo drag handle
// Note: If the gizmo is not dragged, the DragHandleDimension property will return GizmoDimension.None;
GizmoDimension dragHandleDim = gizmo.DragHandleDimension;

As indicated by the comments, when the gizmo is not dragged the DragHandleId and DragHandleDimension properties will return a None value.

Drag Begin Point

It is possible to retrieve the intersection point between the mouse cursor and the drag handle right when the drag session began.

Vector3 dragBeginPoint = gizmo.DragBeginPoint;

Note

The drag begin point is a 3D point in the 3D world if the drag handle is a 3D handle. But if the drag handle is a 2D handle, the drag begin point is a 2D point in screen space. If you need to make any decisions in code based on the drag begin point, it might first be useful to check the dimension of the drag handle first:

if (gizmo.DragHandleDimension == GizmoDimension.Dim3D)
{
    // Implement logic for a **3D** drag begin point
}
else
if (gizmo.DragHandleDimension == GizmoDimension.Dim2D)
{   
    // Implement logic for a **2D** drag begin point (a point expressed in screen space coordinates)
}
else 
{
    // GizmoDimension.None - this means the gizmo is not dragged
}

Note

During a drag session, the drag begin point will always have the same value as the gizmo.HoverPoint at the time when the left mouse button was clicked.

The Active Drag Channel

When a gizmo is dragged you can use the ActiveDragChannel property to check the type of output that is produced during the active drag session:

GizmoDragChannel activeDragChannel = gizmo.ActiveDragChannel;
if (activeDragChannel == GizmoDragChannel.Offset)
{
    // The gizmo is moving something
}
else 
if (activeDragChannel == GizmoDragChannel.Rotation)
{
    // The gizmo is rotating something
]
else
if (activeDragChannel == GizmoDragChannel.Scale)
{
    // The gizmo is scaling something
}
else 
{
    // GizmoDragChannel.None - the gizmo is not being dragged
}

Drag Offset

It is possible to get access to the relative and total drag offset values which are produced by a gizmo during a drag session:

Vector3 relativeOffset = gizmo.RelativeDragOffset;
Vector3 totalOffset = gizmo.TotalDragOffset;

The relative drag offset is an offset vector that represents the amount of movement applied (or produced) since the last mouse move event. For example, if you drag the move gizmo, the relative drag offset might be set to <0.3f, 0.0f, 0.0f> during one mouse move event. This means that during that event, the gizmo was moved 0.3f units along the world X axis.

The total drag offset represents the sum of all relative offsets produced during successive mouse movements. For example, let's assume that a move gizmo produces the following relative offsets during successive mouse move events:

  • <0.1f, 0.0f, 0.0f>;
  • <0.2f, 0.0f, 0.0f>;
  • <-0.3f, 0.0f, 0.0f>;
  • <-0.15f, 0.0f, 0.0f>;

The sum of these is: <0.1f + 0.2f - 0.3f - 0.15f, 0.0f, 0.0f> = <-0.15f, 0.0f, 0.0f> and this is the total drag offset.

Drag Rotation

It is possible to get access to the relative and total drag rotation values which are produced by a gizmo during a drag session:

Quaternion relativeRotation = gizmo.RelativeDragRotation;
Quaternion totalRotation = gizmo.TotalDragRotation;

The relative drag rotation is a rotation quaternion that represents the amount of rotation applied (or produced) since the last mouse move event. For example, if you drag the rotation gizmo, the relative drag rotation might be set to a quaternion that describes a rotation of 2.0f degrees around the gizmo local X axis during one mouse move event. This means that during that event, the gizmo was rotated 2.0f degrees around its local X axis.

The total drag rotation represents the sum of all relative rotations produced during successive mouse movements. For example, let's assume that a rotation gizmo produces the following relative rotation values around its own local X axis during successive mouse move events:

  • -0.3f;
  • 0.2f;
  • 0.1f;
  • 0.14f;

The sum of these is: -0.3f + 0.2f + 0.1f + 0.14f = 0.14f and this is the total drag rotation applied during the drag session.

Drag Scale

It is possible to get access to the relative and total drag scale values which are produced by a gizmo during a drag session:

Vector3 relativeScale = gizmo.RelativeDragScale;
Vector3 totalScale = gizmo.TotalDragScale;

The relative drag scale is a scale vector that represents the amount of scale applied (or produced) since the last mouse move event. For example, if you drag the scale gizmo, the relative drag scale might be set to a vector that describes a scale factor of 0.5f units along the gizmo local X axis during one mouse move event. This means that during that event, the gizmo produced a scale value that can be used to scale entities by a factor of 0.5f (i.e. make them 2 times smaller). The drag vector would look like this: <0.5f, 1.0f, 1.0f>.

Note

In contrast to other types of drag outputs, the scale drag value will use a value of 1 (instead of 0) for the vector components which contain no scale. This is because no scale means multiply by 1.

The total drag scale represents the total amount of scale applied during a drag session.

Note

There is a difference between the type of total that we are talking about here and the total discussed for the offset and rotation drag values. The total scale is not calculated as a sum of relative drag scale values. Suffice to say that if (for example) an object has a volume size of <2.0f, 2.0f, 5.0f> before the scale session begins, assuming a total scale value of <1.0f, 2.0f, 0.5f>, at the end of the drag session the object volume size would be <2.0f * 1.0f, 2.0f * 2.0f, 5.0f * 0.5f> = <2.0f, 4.0f, 2.5f>. The object size has doubled along its local Y axis and halfed along its local Z axis.

The GizmoDragInfo Struct

You can also retrieve an instance of the GizmoDragInfo struct to get access to all drag related states at once:

GizmoDragInfo dragInfo = gizmo.DragInfo;

This struct exposes the following properties:

public struct GizmoDragInfo
{
    public bool IsDragged { get { return _isDragged; } set { _isDragged = value; } }
    public int HandleId { get { return _handleId; } set { _handleId = value; } }
    public Vector3 DragBeginPoint { get { return _dragBeginPoint; } set { _dragBeginPoint = value; } }
    public GizmoDragChannel DragChannel { get { return _dragChannel; } set { _dragChannel = value; } }
    public GizmoDimension HandleDimension { get { return _handleDimension; } set { _handleDimension = value; } }
    public Vector3 TotalOffset { get { return _totalOffset; } set { _totalOffset = value; } }
    public Quaternion TotalRotation { get { return _totalRotation; } set { _totalRotation = value; } }
    public Vector3 TotalScale { get { return _totalScale; } set { _totalScale = value; } }
    public Vector3 RelativeOffset { get { return _relativeOffset; } set { _relativeOffset = value; } }
    public Quaternion RelativeRotation { get { return _relativeRotation; } set { _relativeRotation = value; } }
    public Vector3 RelativeScale { get { return _relativeScale; } set { _relativeScale = value; } }
}

These are the same as the properties that can be accessed via the Gizmo class properties which have already been discussed in earlier sections.