We have a series of VG onboarding tasks to show how to tackle different practical use cases in a VR application.

Task Description

Interaction behaviors wanted

  • Push once a button stay in lowered position, light turn on
  • Push another time button come back to original position, light turns off

Tips for VR developers

  • Which joint type should be assigned to the button?
  • Which state affordance to use to allow button be switch between these two states?
  • How to determine when light should be on or off (use GetObjectJointState function)?
  • More systemtic understanding can be obtained in push interaction.

Solution

In VirtualGrasp SDK, we packed the solution of this task in VirtualGrasp\Scenes\onboarding.

VirtualGrasp\Scenes\onboarding\VG_Onboarding.unity

is the unity scene showing how VG_Articulation component is used to setup this object’s articulation settings.

//VirtualGrasp\Scenes\onboarding\Scripts\ToggleLight.cs:

using UnityEngine;
using VirtualGrasp;

public class ToggleLight : MonoBehaviour
{
    public Light m_light = null;
    private VG_Articulation m_articulation = null;

    void Start()
    {
        m_articulation = GetComponent<VG_Articulation>();
    }

    void Update()
    {
        float state = VG_Controller.GetObjectJointState(transform);
        if (state == m_articulation.m_min) m_light.enabled = false;
        else if (state == m_articulation.m_max) m_light.enabled = true;
    }
}

is the script showing how to use API function GetObjectJointState to get the object’s joint state in order to determine when the light is on or off.