Skip to content

Commit

Permalink
feat(Pointers): allow different axis to control direction indicator
Browse files Browse the repository at this point in the history
The Pointer Direction Indicator can now be controlled by a different
coordinate axis such as touchpad two.
  • Loading branch information
thestonefox committed Nov 22, 2017
1 parent 8e10a58 commit 649c5bd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
13 changes: 13 additions & 0 deletions Assets/VRTK/Documentation/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ Adds a Pointer Direction Indicator to a pointer renderer and determines a given
### Inspector Parameters

* **Touchpad Deadzone:** The touchpad axis needs to be above this deadzone for it to register as a valid touchpad angle.
* **Coordinate Axis:** The axis to use for the direction coordinates.
* **Include Headset Offset:** If this is checked then the reported rotation will include the offset of the headset rotation in relation to the play area.
* **Display On Invalid Location:** If this is checked then the direction indicator will be displayed when the location is invalid.
* **Use Pointer Color:** If this is checked then the pointer valid/invalid colours will also be used to change the colour of the direction indicator.
Expand Down Expand Up @@ -3471,6 +3472,18 @@ The GetPinkyFingerSenseAxis method returns a float representing how much of the

The AnyButtonPressed method returns true if any of the controller buttons are being pressed and this can be useful to determine if an action can be taken whilst the user is using the controller.

#### GetAxisState/2

> `public virtual bool GetAxisState(SDK_BaseController.Vector2Axis axis, SDK_BaseController.ButtonPressTypes pressType)`

* Parameters
* `SDK_BaseController.Vector2Axis axis` - The axis to check on.
* `SDK_BaseController.ButtonPressTypes pressType` - The button press type to check for.
* Returns
* `bool` - Returns `true` if the axis is being interacted with via the given press type.

The GetAxisState method takes a given Vector2Axis and returns a boolean whether that given axis is currently being touched or pressed.

#### IsButtonPressed/1

> `public virtual bool IsButtonPressed(ButtonAlias button)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ public enum VisibilityState
}

[Header("Control Settings")]

[Tooltip("The touchpad axis needs to be above this deadzone for it to register as a valid touchpad angle.")]
public Vector2 touchpadDeadzone = Vector2.zero;
[Tooltip("The axis to use for the direction coordinates.")]
public SDK_BaseController.Vector2Axis coordinateAxis = SDK_BaseController.Vector2Axis.Touchpad;

[Header("Appearance Settings")]

Expand Down Expand Up @@ -135,9 +138,9 @@ protected virtual void Awake()

protected virtual void Update()
{
if (controllerEvents != null && controllerEvents.touchpadTouched && !InsideDeadzone(controllerEvents.GetTouchpadAxis()))
if (controllerEvents != null && controllerEvents.GetAxisState(coordinateAxis, SDK_BaseController.ButtonPressTypes.Touch) && !InsideDeadzone(controllerEvents.GetAxis(coordinateAxis)))
{
float touchpadAngle = controllerEvents.GetTouchpadAxisAngle();
float touchpadAngle = controllerEvents.GetAxisAngle(coordinateAxis);
float angle = ((touchpadAngle > 180) ? touchpadAngle -= 360 : touchpadAngle) + headset.eulerAngles.y;
transform.localEulerAngles = new Vector3(0f, angle, 0f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,28 @@ public virtual bool AnyButtonPressed()
return (triggerPressed || gripPressed || touchpadPressed || buttonOnePressed || buttonTwoPressed || startMenuPressed);
}

/// <summary>
/// The GetAxisState method takes a given Vector2Axis and returns a boolean whether that given axis is currently being touched or pressed.
/// </summary>
/// <param name="axis">The axis to check on.</param>
/// <param name="pressType">The button press type to check for.</param>
/// <returns>Returns `true` if the axis is being interacted with via the given press type.</returns>
public virtual bool GetAxisState(SDK_BaseController.Vector2Axis axis, SDK_BaseController.ButtonPressTypes pressType)
{
switch (pressType)
{
case SDK_BaseController.ButtonPressTypes.Press:
case SDK_BaseController.ButtonPressTypes.PressDown:
case SDK_BaseController.ButtonPressTypes.PressUp:
return (axis == SDK_BaseController.Vector2Axis.Touchpad ? touchpadPressed : false);
case SDK_BaseController.ButtonPressTypes.Touch:
case SDK_BaseController.ButtonPressTypes.TouchDown:
case SDK_BaseController.ButtonPressTypes.TouchUp:
return (axis == SDK_BaseController.Vector2Axis.Touchpad ? touchpadTouched : touchpadTwoTouched);
}
return false;
}

/// <summary>
/// The IsButtonPressed method takes a given button alias and returns a boolean whether that given button is currently being pressed or not.
/// </summary>
Expand Down

0 comments on commit 649c5bd

Please sign in to comment.