Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.3 KiB

  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. //
  3. // Purpose: Triggers haptic pulses based on distance between 2 positions
  4. //
  5. //=============================================================================
  6. using UnityEngine;
  7. using System.Collections;
  8. namespace Valve.VR.InteractionSystem
  9. {
  10. //-------------------------------------------------------------------------
  11. public class DistanceHaptics : MonoBehaviour
  12. {
  13. public Transform firstTransform;
  14. public Transform secondTransform;
  15. public AnimationCurve distanceIntensityCurve = AnimationCurve.Linear( 0.0f, 800.0f, 1.0f, 800.0f );
  16. public AnimationCurve pulseIntervalCurve = AnimationCurve.Linear( 0.0f, 0.01f, 1.0f, 0.0f );
  17. //-------------------------------------------------
  18. IEnumerator Start()
  19. {
  20. while ( true )
  21. {
  22. float distance = Vector3.Distance( firstTransform.position, secondTransform.position );
  23. SteamVR_TrackedObject trackedObject = GetComponentInParent<SteamVR_TrackedObject>();
  24. if ( trackedObject )
  25. {
  26. float pulse = distanceIntensityCurve.Evaluate( distance );
  27. SteamVR_Controller.Input( (int)trackedObject.index ).TriggerHapticPulse( (ushort)pulse );
  28. }
  29. float nextPulse = pulseIntervalCurve.Evaluate( distance );
  30. yield return new WaitForSeconds( nextPulse );
  31. }
  32. }
  33. }
  34. }