Skip to content

Commit

Permalink
feat(Controller): add methods to get touchpad axis and angle
Browse files Browse the repository at this point in the history
It's now possible to get the current touchpad axis and angle via
method calls if this is required instead of using the events.
  • Loading branch information
thestonefox committed Jun 27, 2016
1 parent 1366778 commit 7187fed
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions Assets/SteamVR_Unity_Toolkit/Scripts/VRTK_ControllerEvents.cs
Expand Up @@ -217,20 +217,24 @@ public Vector3 GetAngularVelocity()
return controllerAngularVelocity;
}

public Vector2 GetTouchpadAxis()
{
return touchpadAxis;
}

public float GetTouchpadAxisAngle()
{
return CalculateTouchpadAxisAngle(touchpadAxis);
}

private ControllerInteractionEventArgs SetButtonEvent(ref bool buttonBool, bool value, float buttonPressure)
{
buttonBool = value;
ControllerInteractionEventArgs e;
e.controllerIndex = controllerIndex;
e.buttonPressure = buttonPressure;
e.touchpadAxis = device.GetAxis();

float angle = Mathf.Atan2(e.touchpadAxis.y, e.touchpadAxis.x) * Mathf.Rad2Deg;
angle = 90.0f - angle;
if (angle < 0)
angle += 360.0f;

e.touchpadAngle = angle;
e.touchpadAngle = CalculateTouchpadAxisAngle(e.touchpadAxis);

return e;
}
Expand All @@ -246,6 +250,17 @@ private void Start()
device = SteamVR_Controller.Input((int)controllerIndex);
}

private float CalculateTouchpadAxisAngle(Vector2 axis)
{
float angle = Mathf.Atan2(axis.y, axis.x) * Mathf.Rad2Deg;
angle = 90.0f - angle;
if (angle < 0)
{
angle += 360.0f;
}
return angle;
}

private void EmitAlias(ButtonAlias type, bool touchDown, float buttonPressure, ref bool buttonBool)
{
if (pointerToggleButton == type)
Expand Down

0 comments on commit 7187fed

Please sign in to comment.