Exemple #1
0
        /// <summary>
        /// Begins a traversing impulse at the provided origin.
        /// Will play on pads that are the origin, destination or 'in-between' them.
        /// Defaults to a simple 'hum' effect if you don't call WithEffect()
        /// Remember to call .Play() on the returned impulse.
        /// </summary>
        /// <param name="origin">The starting AreaFlag. Only provided a single AreaFlag pad.</param>
        /// <param name="destination">The ending location for the traversing impulse.</param>
        /// <returns>The Impulse that you can call .Play() on to play a create a HapticHandle referencing that Haptic</returns>
        public static Impulse BeginTraversingImpulse(AreaFlag origin, AreaFlag destination)
        {
            if (!origin.IsSingleArea() || !destination.IsSingleArea())
            {
                Debug.LogError("Invalid AreaFlag Provided: Origin is [" + origin.NumberOfAreas() + "] area(s) and Destination is [" + destination.NumberOfAreas() + "] area(s).\n\tImpulse Generator only supports single area flag values.\n");
                return(null);
            }
            CreateImpulse creation = delegate(float attenuation, float totalLength, HapticSequence seq)
            {
                HapticPattern emanation = new HapticPattern();
                var           stages    = _grapher.Dijkstras(origin, destination);

                float timeStep     = totalLength / stages.Count;
                float time         = 0.0f;
                float baseStrength = 1f;
                for (int i = 0; i < stages.Count; i++)
                {
                    if (i > 0)
                    {
                        baseStrength *= (attenuation);
                    }
                    //Debug.Log(timeStep + "\n" + baseStrength + "\n");
                    emanation.AddSequence(time, stages[i].Location, Mathf.Clamp(baseStrength, 0f, 1f), seq);
                    time += timeStep;
                }

                return(emanation.CreateHandle().Play());
            };

            return(new Impulse(creation));
        }
        private HapticHandle CreateHandle(SideOfHaptic side)
        {
            HapticHandle handle = null;

            if (TypeOfPlayable == PlayableType.Sequence)
            {
                HapticSequence seq = new HapticSequence();
                seq.LoadFromAsset(PlayableResourceName);

                var areaFlag = side == SideOfHaptic.Left ? Where.Mirror() : Where;
                handle = seq.CreateHandle(areaFlag);
            }
            else if (TypeOfPlayable == PlayableType.Pattern)
            {
                HapticPattern pat = new HapticPattern();
                pat.LoadFromAsset(PlayableResourceName);
                handle = pat.CreateHandle();
            }
            else if (TypeOfPlayable == PlayableType.Experience)
            {
                HapticExperience exp = new HapticExperience();
                exp.LoadFromAsset(PlayableResourceName);
                handle = exp.CreateHandle();
            }
            else if (TypeOfPlayable == PlayableType.Impulse)
            {
                return(CreateImpulseHandle(side));
            }

            return(handle);
        }
Exemple #3
0
        /// <summary>
        /// Begins a traversing impulse at the provided origin.
        /// Will play on pads that are the origin, destination or 'in-between' them.
        /// Defaults to a simple 'hum' effect if you don't call WithEffect()
        /// Remember to call .Play() on the returned impulse.
        /// </summary>
        /// <param name="origin">The starting AreaFlag. Only provided a single AreaFlag pad.</param>
        /// <param name="destination">The ending location for the traversing impulse.</param>
        /// <returns>The Impulse that you can call .Play() on to play a create a HapticHandle referencing that Haptic</returns>
        public static Impulse BeginTraversingImpulse(AreaFlag origin, AreaFlag destination)
        {
            CreateImpulse creation = delegate(float attenuation, float totalLength, HapticSequence seq)
            {
                HapticPattern emanation = new HapticPattern();
                var           stages    = _grapher.Dijkstras(origin, destination);

                float timeStep     = totalLength / stages.Count;
                float time         = 0.0f;
                float baseStrength = 1f;
                for (int i = 0; i < stages.Count; i++)
                {
                    if (i > 0)
                    {
                        baseStrength *= (1.0f - attenuation);
                    }
                    emanation.AddSequence(time, stages[i].Location, Mathf.Clamp(baseStrength, 0f, 1f), seq);
                    time += timeStep;
                }

                return(emanation.CreateHandle().Play());
            };

            return(new Impulse(creation));
        }
Exemple #4
0
        /// <summary>
        /// Begins an emanating impulse at the provided origin.
        /// Defaults to a simple 'hum' effect if you don't call WithEffect()
        /// Remember to call .Play() on the returned impulse.
        /// </summary>
        /// <param name="origin">The starting AreaFlag. Only provided a single AreaFlag pad.</param>
        /// <param name="depth">How many pads this will traverse before ending (will not reverb off 'end paths')</param>
        /// <returns>An Impulse object which can be given a HapticSequence, duration or Attenuation parameters
        /// Remember to call Play() on the returned object to begin the emanation
        /// <returns>The Impulse that you can call .Play() on to play a create a HapticHandle referencing that Haptic</returns>
        public static Impulse BeginEmanatingEffect(AreaFlag origin, int depth = 2)
        {
            if (depth < 0)
            {
                Debug.LogError("Depth for emanation is negative: " + depth + "\n\tThis will be clamped to 0 under the hood, negative numbers will likely do nothing");
            }

            CreateImpulse creation = delegate(float attenuation, float totalLength, HapticSequence seq)
            {
                HapticPattern emanation    = new HapticPattern();
                var           stages       = _grapher.BFS(origin, depth);
                float         baseStrength = 1.0f;
                float         timeStep     = totalLength / stages.Count;
                float         time         = 0.0f;
                for (int i = 0; i < stages.Count; i++)
                {
                    AreaFlag area = AreaFlag.None;
                    foreach (var item in stages[i])
                    {
                        area |= item.Location;
                    }
                    if (i > 0)
                    {
                        baseStrength *= (1.0f - attenuation);
                    }

                    emanation.AddSequence(time, area, Mathf.Clamp(baseStrength, 0f, 1f), seq);
                    time += timeStep;
                }

                return(emanation.CreateHandle().Play());
            };

            return(new Impulse(creation));
        }
Exemple #5
0
 private void Start()
 {
     hapticOnDrawback.LoadFromAsset(drawHaptic);
     hapticOnRelease.LoadFromAsset(releaseHaptic);
     hapticwhilePulled.LoadFromAsset(pulledHapticName);
     pulledHandle = hapticwhilePulled.CreateHandle();
     bowAnimation = GetComponent <BowAnimation>();
     handle       = GetComponentInChildren <BowHandle>();
     interact     = GetComponent <VRTK_InteractableObject>();
     interact.InteractableObjectGrabbed += new InteractableObjectEventHandler(DoObjectGrab);
 }
Exemple #6
0
        //public static NewGraphEngine _newGrapher = new NewGraphEngine();

        /// <summary>
        /// Begins an emanating impulse at the provided origin.
        /// Defaults to a simple 'hum' effect if you don't call WithEffect()
        /// Remember to call .Play() on the returned impulse.
        /// </summary>
        /// <param name="origin">The starting AreaFlag. Only provided a single AreaFlag pad.</param>
        /// <param name="depth">How many pads this will traverse before ending (will not reverb off 'end paths')</param>
        /// <returns>An Impulse object which can be given a HapticSequence, duration or Attenuation parameters
        /// Remember to call Play() on the returned object to begin the emanation
        /// <returns>The Impulse that you can call .Play() on to play a create a HapticHandle referencing that Haptic</returns>
        public static Impulse BeginEmanatingEffect(AreaFlag origin, int depth = 2)
        {
            if (!origin.IsSingleArea())
            {
                Debug.LogError("Invalid AreaFlag Provided: Origin is [" + origin.NumberOfAreas() + "] area(s).\n\tImpulse Generator only supports single area flag values.\n");
                return(null);
            }

            if (depth < 0)
            {
                Debug.LogError("Depth for emanation is negative: " + depth + "\n\tThis will be clamped to 0 under the hood, negative numbers will likely do nothing");
            }

            CreateImpulse creation = delegate(float attenuation, float totalLength, HapticSequence seq)
            {
                HapticPattern emanation = new HapticPattern();
                var           stages    = _grapher.BFS(origin, depth);
                //var stages = _newGrapher.BFS(origin, depth);
                float baseStrength = 1.0f;
                float timeStep     = totalLength / stages.Count;
                float time         = 0.0f;
                for (int i = 0; i < stages.Count; i++)
                {
                    AreaFlag area = AreaFlag.None;
                    foreach (var item in stages[i])
                    {
                        area |= item.Location;
                        //area |= item.ConvertToAreaFlag();
                    }
                    if (i > 0)
                    {
                        baseStrength *= (attenuation);
                    }

                    emanation.AddSequence(time, area, Mathf.Clamp(baseStrength, 0f, 1f), seq);
                    time += timeStep;
                }

                return(emanation.CreateHandle().Play());
            };

            return(new Impulse(creation));
        }
        public HapticHandle CreateCodeHaptic()
        {
            //Debug.Log("Hit\n");
            HapticSequence seq = new HapticSequence();

            seq.AddEffect(0.0f, new HapticEffect(Effect.Buzz, .2f));
            seq.AddEffect(0.3f, new HapticEffect(Effect.Click, 0.0f));
            //seq.Play(AreaFlag.All_Areas);

            HapticPattern pat = new HapticPattern();

            pat.AddSequence(0.5f, AreaFlag.Lower_Ab_Both, seq);
            pat.AddSequence(1.0f, AreaFlag.Mid_Ab_Both, seq);
            pat.AddSequence(1.5f, AreaFlag.Upper_Ab_Both, seq);
            pat.AddSequence(2.0f, AreaFlag.Chest_Both, seq);
            pat.AddSequence(2.5f, AreaFlag.Shoulder_Both, seq);
            pat.AddSequence(2.5f, AreaFlag.Back_Both, seq);
            pat.AddSequence(3.0f, AreaFlag.Upper_Arm_Both, seq);
            pat.AddSequence(3.5f, AreaFlag.Forearm_Both, seq);
            return(pat.CreateHandle().Play());
        }