Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Cherry pick' of work previously committed to Dev_Working with PR #1870: #2050

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ private void Update()
public void OnSourceDetected(SourceStateEventData eventData)
{
// If the source has positional info and there is currently no visible source
if (eventData.InputSource.SupportsInputInfo(eventData.SourceId, SupportedInputInfo.Position))
if (eventData.InputSource.SupportsInputInfo(eventData.SourceId, SupportedInputInfo.GripPosition))
{
trackedHandsCount++;
}
}

public void OnSourceLost(SourceStateEventData eventData)
{
if (eventData.InputSource.SupportsInputInfo(eventData.SourceId, SupportedInputInfo.Position))
if (eventData.InputSource.SupportsInputInfo(eventData.SourceId, SupportedInputInfo.GripPosition))
{
trackedHandsCount--;
}
Expand Down
51 changes: 45 additions & 6 deletions Assets/HoloToolkit/Input/Scripts/InputSources/CustomInputSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,33 @@ public ButtonStates()
public bool ManipulationInProgress;
public bool HoldInProgress;
public Vector3 CumulativeDelta;
public Vector3 CumulativeGripDelta;
}

[Tooltip("This property now represents Pointer position (contrast with Grip position)")]
public bool SupportsPosition;
[Tooltip("This property now represents Pointer rotation (contrast with Grip rotation)")]
public bool SupportsRotation;
public bool SupportsGripPosition;
public bool SupportsGripRotation;
public bool SupportsRay;
public bool SupportsMenuButton;
public bool SupportsGrasp;
public bool RaiseEventsBasedOnVisibility;
public InteractionSourceInfo SourceKind;

[Tooltip("This property now represents controller's Pointer position (contrast with controller Grip position)")]
public Vector3 ControllerPosition;
[Tooltip("This property now represents controller's Pointer rotation (contrast with controller Grip rotation)")]
public Quaternion ControllerRotation;

//Navigation Gesture Emulation vars
Vector3 NavigatorValues = Vector3.zero; //holds the navigation gesture values [-1,1]
Vector2 railUsedCurrently = Vector2.one;
bool isNavigatorUsingRails = false;

public Vector3 ControllerPosition;
public Quaternion ControllerRotation;
public Vector3 ControllerGripPosition;
public Quaternion ControllerGripRotation;

public Ray? PointingRay;

Expand Down Expand Up @@ -106,6 +116,16 @@ public override SupportedInputInfo GetSupportedInputInfo(uint sourceId)
supportedInputInfo |= SupportedInputInfo.Pointing;
}

if (SupportsGripPosition)
{
supportedInputInfo |= SupportedInputInfo.GripPosition;
}

if (SupportsGripRotation)
{
supportedInputInfo |= SupportedInputInfo.GripRotation;
}

if (SupportsMenuButton)
{
supportedInputInfo |= SupportedInputInfo.Menu;
Expand Down Expand Up @@ -173,9 +193,9 @@ public override bool TryGetGripPosition(uint sourceId, out Vector3 position)
{
Debug.Assert(sourceId == controllerId, "Controller data requested for a mismatched source ID.");

if (SupportsPosition)
if (SupportsGripPosition)
{
position = ControllerPosition;
position = ControllerGripPosition;
return true;
}

Expand All @@ -187,9 +207,9 @@ public override bool TryGetGripRotation(uint sourceId, out Quaternion rotation)
{
Debug.Assert(sourceId == controllerId, "Controller data requested for a mismatched source ID.");

if (SupportsRotation)
if (SupportsGripRotation)
{
rotation = ControllerRotation;
rotation = ControllerGripRotation;
return true;
}

Expand Down Expand Up @@ -387,6 +407,25 @@ private void UpdateControllerState(DebugInteractionSourceState source)
PointingRay = source.SourcePose.PointerRay;
}

if (SupportsGripPosition)
{
Vector3 controllerGripPosition;
if (source.SourcePose.TryGetGripPosition(out controllerGripPosition))
{
currentButtonStates.CumulativeGripDelta += controllerGripPosition - ControllerGripPosition;
ControllerGripPosition = controllerGripPosition;
}
}

if (SupportsGripRotation)
{
Quaternion controllerGripRotation;
if (source.SourcePose.TryGetGripRotation(out controllerGripRotation))
{
ControllerGripRotation = controllerGripRotation;
}
}

if (SupportsMenuButton)
{
currentButtonStates.MenuButtonStateChanged = (currentButtonStates.IsMenuButtonDown != source.MenuPressed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,10 @@ public override SupportedInputInfo GetSupportedInputInfo(uint sourceId)
SourceData sourceData;
if (sourceIdToData.TryGetValue(sourceId, out sourceData))
{
retVal |= GetSupportFlag(sourceData.PointerPosition, SupportedInputInfo.Position);
retVal |= GetSupportFlag(sourceData.PointerRotation, SupportedInputInfo.Rotation);
retVal |= GetSupportFlag(sourceData.PointerPosition, SupportedInputInfo.PointerPosition);
retVal |= GetSupportFlag(sourceData.PointerRotation, SupportedInputInfo.PointerRotation);
retVal |= GetSupportFlag(sourceData.GripPosition, SupportedInputInfo.GripPosition);
retVal |= GetSupportFlag(sourceData.GripRotation, SupportedInputInfo.GripRotation);
retVal |= GetSupportFlag(sourceData.PointingRay, SupportedInputInfo.Pointing);
retVal |= GetSupportFlag(sourceData.Thumbstick, SupportedInputInfo.Thumbstick);
retVal |= GetSupportFlag(sourceData.Touchpad, SupportedInputInfo.Touchpad);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ namespace HoloToolkit.Unity.InputModule
public enum SupportedInputInfo
{
None = 0,
[Obsolete("use PointerPosition")]
Position = (1 << 0),
PointerPosition = (1 << 0),
[Obsolete("use PointerRotation")]
Rotation = (1 << 1),
PointerRotation = (1 << 1),
Pointing = (1 << 2),
Thumbstick = (1 << 3),
Touchpad = (1 << 4),
Select = (1 << 5),
Menu = (1 << 6),
Grasp = (1 << 7),
GripPosition = (1 << 8),
GripRotation = (1 << 9)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public override bool TryGetGripRotation(uint sourceId, out Quaternion rotation)

public override SupportedInputInfo GetSupportedInputInfo(uint sourceId)
{
return SupportedInputInfo.Position | SupportedInputInfo.Pointing;
return SupportedInputInfo.PointerPosition | SupportedInputInfo.Pointing;
}

public override bool TryGetThumbstick(uint sourceId, out bool isPressed, out Vector2 position)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@ public class DebugInteractionSourcePose
public bool TryGetFunctionsReturnTrue;
public bool IsPositionAvailable;
public bool IsRotationAvailable;
public bool IsGripPositionAvailable;
public bool IsGripRotationAvailable;

public Vector3 Position;
public Vector3 Velocity;
public Quaternion Rotation;
public Ray? PointerRay;
public Vector3 GripPosition;
public Quaternion GripRotation;

public DebugInteractionSourcePose()
{
TryGetFunctionsReturnTrue = false;
IsPositionAvailable = false;
IsRotationAvailable = false;
IsGripPositionAvailable = false;
IsGripRotationAvailable = false;
Position = new Vector3(0, 0, 0);
Velocity = new Vector3(0, 0, 0);
Rotation = Quaternion.identity;
Expand All @@ -38,7 +44,7 @@ public DebugInteractionSourcePose()
public bool TryGetPosition(out Vector3 position)
{
position = Position;
if (!TryGetFunctionsReturnTrue)
if (!TryGetFunctionsReturnTrue) // TODO: bug? does not test IsPositionAvailable (see TryGetRotation)
{
return false;
}
Expand Down Expand Up @@ -74,5 +80,25 @@ public bool TryGetPointerRay(out Ray pointerRay)
}
return true;
}

public bool TryGetGripPosition(out Vector3 position)
{
position = GripPosition;
if (!TryGetFunctionsReturnTrue) // TODO: should test IsGripPositionAvailable? (see TryGetPosition)
{
return false;
}
return true;
}

public bool TryGetGripRotation(out Quaternion rotation)
{
rotation = GripRotation;
if (!TryGetFunctionsReturnTrue || !IsGripRotationAvailable)
{
return false;
}
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ public void OnInputDown(InputEventData eventData)
eventData.InputSource.TryGetSourceKind(eventData.SourceId, out sourceKind);
if (sourceKind != InteractionSourceInfo.Hand)
{
if (!eventData.InputSource.SupportsInputInfo(eventData.SourceId, SupportedInputInfo.Position))
if (!eventData.InputSource.SupportsInputInfo(eventData.SourceId, SupportedInputInfo.GripPosition))
{
// The input source must provide positional data for this script to be usable
// The input source must provide grip positional data for this script to be usable
return;
}
}
Expand Down