Skip to content

Commit

Permalink
feat(SDK): add method to auto generate controller pointer origins
Browse files Browse the repository at this point in the history
It may be plausible that some SDKs require to provide a custom
pointer origin by default as the default transform may not be oriented
in the correct way.

This new method allows each SDK to provide a custom transform if one
is required.
  • Loading branch information
thestonefox committed Dec 22, 2016
1 parent 2b511ac commit c923f14
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Assets/VRTK/SDK/Base/SDK_BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ public enum ControllerHand
/// <returns>A Transform containing the origin of the controller.</returns>
public abstract Transform GetControllerOrigin(GameObject controller);

/// <summary>
/// The GenerateControllerPointerOrigin method can create a custom pointer origin Transform to represent the pointer position and forward.
/// </summary>
/// <returns>A generated Transform that contains the custom pointer origin.</returns>
public abstract Transform GenerateControllerPointerOrigin();

/// <summary>
/// The GetControllerLeftHand method returns the GameObject containing the representation of the left hand controller.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions Assets/VRTK/SDK/Fallback/SDK_FallbackController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ public override Transform GetControllerOrigin(GameObject controller)
return null;
}

/// <summary>
/// The GenerateControllerPointerOrigin method can create a custom pointer origin Transform to represent the pointer position and forward.
/// </summary>
/// <returns>A generated Transform that contains the custom pointer origin.</returns>
public override Transform GenerateControllerPointerOrigin()
{
return null;
}

/// <summary>
/// The GetControllerLeftHand method returns the GameObject containing the representation of the left hand controller.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions Assets/VRTK/SDK/SteamVR/SDK_SteamVRController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ public override Transform GetControllerOrigin(GameObject controller)
return null;
}

/// <summary>
/// The GenerateControllerPointerOrigin method can create a custom pointer origin Transform to represent the pointer position and forward.
/// </summary>
/// <returns>A generated Transform that contains the custom pointer origin.</returns>
public override Transform GenerateControllerPointerOrigin()
{
return null;
}

/// <summary>
/// The GetControllerLeftHand method returns the GameObject containing the representation of the left hand controller.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions Assets/VRTK/SDK/VRTK_SDK_Bridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public static Transform GetControllerOrigin(GameObject controller)
return GetControllerSDK().GetControllerOrigin(controller);
}

public static Transform GenerateControllerPointerOrigin()
{
return GetControllerSDK().GenerateControllerPointerOrigin();
}

public static GameObject GetControllerLeftHand(bool actual)
{
return GetControllerSDK().GetControllerLeftHand(actual);
Expand Down
3 changes: 3 additions & 0 deletions Assets/VRTK/Scripts/Pointers/VRTK_BasePointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ protected virtual void Awake()
protected override void OnEnable()
{
base.OnEnable();

pointerOriginTransform = (pointerOriginTransform == null ? VRTK_SDK_Bridge.GenerateControllerPointerOrigin() : pointerOriginTransform);

AttemptSetController();

var tmpMaterial = Resources.Load("WorldPointer") as Material;
Expand Down
2 changes: 2 additions & 0 deletions Assets/VRTK/Scripts/UI/VRTK_UIPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ public Vector3 GetOriginForward()

private void OnEnable()
{
pointerOriginTransform = (pointerOriginTransform == null ? VRTK_SDK_Bridge.GenerateControllerPointerOrigin() : pointerOriginTransform);

if (controller == null)
{
controller = GetComponent<VRTK_ControllerEvents>();
Expand Down
33 changes: 33 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -5092,6 +5092,17 @@ The GetControllerByIndex method returns the GameObject of a controller with a sp

The GetControllerOrigin method returns the origin of the given controller.

#### GenerateControllerPointerOrigin/0

> `public abstract Transform GenerateControllerPointerOrigin();`
* Parameters
* _none_
* Returns
* `Transform` - A generated Transform that contains the custom pointer origin.

The GenerateControllerPointerOrigin method can create a custom pointer origin Transform to represent the pointer position and forward.

#### GetControllerLeftHand/1

> `public abstract GameObject GetControllerLeftHand(bool actual = false);`
Expand Down Expand Up @@ -5857,6 +5868,17 @@ The GetControllerByIndex method returns the GameObject of a controller with a sp

The GetControllerOrigin method returns the origin of the given controller.

#### GenerateControllerPointerOrigin/0

> `public override Transform GenerateControllerPointerOrigin()`
* Parameters
* _none_
* Returns
* `Transform` - A generated Transform that contains the custom pointer origin.

The GenerateControllerPointerOrigin method can create a custom pointer origin Transform to represent the pointer position and forward.

#### GetControllerLeftHand/1

> `public override GameObject GetControllerLeftHand(bool actual = false)`
Expand Down Expand Up @@ -6616,6 +6638,17 @@ The GetControllerByIndex method returns the GameObject of a controller with a sp

The GetControllerOrigin method returns the origin of the given controller.

#### GenerateControllerPointerOrigin/0

> `public override Transform GenerateControllerPointerOrigin()`
* Parameters
* _none_
* Returns
* `Transform` - A generated Transform that contains the custom pointer origin.

The GenerateControllerPointerOrigin method can create a custom pointer origin Transform to represent the pointer position and forward.

#### GetControllerLeftHand/1

> `public override GameObject GetControllerLeftHand(bool actual = false)`
Expand Down

0 comments on commit c923f14

Please sign in to comment.