public static void CreateMyAsset() { HapticEvent asset = ScriptableObject.CreateInstance <HapticEvent>(); AssetDatabase.CreateAsset(asset, "Assets/NewHapticEvent.asset"); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = asset; }
public IEnumerator TriggerHapticEvent(SteamVR_Input_Sources hand, HapticEvent hapticEvent) { float startTime = Time.time; float currentTime = Time.time; while (currentTime - startTime < hapticEvent.curveTime) { steamVRHaptics.Execute(0, 0, hapticEvent.curveFrequency.Evaluate(currentTime - startTime), hapticEvent.curveAmplitude.Evaluate(currentTime - startTime), hand); currentTime = Time.time; yield return(null); } steamVRHaptics.Execute(0, 0, 0, 0, hand); yield return(null); }
public IEnumerator TriggerHapticEvent(OVRInput.Controller hand, HapticEvent hapticEvent) { float startTime = Time.time; float currentTime = Time.time; while (currentTime - startTime < hapticEvent.curveTime) { OVRInput.SetControllerVibration(hapticEvent.curveFrequency.Evaluate(currentTime - startTime), hapticEvent.curveAmplitude.Evaluate(currentTime - startTime), hand); currentTime = Time.time; yield return(null); } OVRInput.SetControllerVibration(0, 0, hand); yield return(null); }
public void AddEvent(HapticEvent evt) { HapticEvents.Add(evt); }
public virtual void TriggerHapticEvent(HapticEvent hapticEvent) { }
public override void TriggerHapticEvent(HapticEvent hapticEvent) { StartCoroutine(TriggerHapticEvent(SteamVR_Input_Sources.LeftHand, hapticEvent)); StartCoroutine(TriggerHapticEvent(SteamVR_Input_Sources.RightHand, hapticEvent)); }
public static Task ParseScript(string si) { return Task.Factory.StartNew( () => { string[] lines = null; try { lines = File.ReadAllLines(si); } catch (Exception ex) { //Logger.LogException(ex); } if (lines == null) { MessageBox.Show("Problem parsing script.txt!"); } var topAxis = new HapticCollection(); var bothAxis = new HapticCollection(); var bottomAxis = new HapticCollection(); var squeezeAxis = new HapticCollection(); var topPeriodic = new HapticCollection(); var bothPeriodic = new HapticCollection(); var bottomPeriodic = new HapticCollection(); var squeezePeriodic = new HapticCollection(); var lube = new HapticCollection(); var heat = new HapticCollection(); var stop = new HapticCollection(); foreach (string s in lines) { string[] split = s.Split(' '); HapticEvent rt = new HapticEvent(); switch (split[1]) { case "V": { rt.Start = Convert.ToInt32(split[0]); rt.Magnitude = Convert.ToInt32(split[2]); rt.Direction = (String.CompareOrdinal("IN", split[4]) == 0) ? HapticEvent.DirectionType.In : HapticEvent.DirectionType.Out; rt.Duration = Convert.ToInt32(split[5]); rt.InMagnitude = Convert.ToInt32(split[6]); rt.InDuration = Convert.ToInt32(split[7]); rt.OutMagnitude = Convert.ToInt32(split[8]); rt.OutDuration = Convert.ToInt32(split[9]); switch (split[3]) { case "U": { rt.Type = HapticEvent.HapticEventType.AxisBoth; bothAxis.Add(rt); break; } case "T": { rt.Type = HapticEvent.HapticEventType.AxisTop; topAxis.Add(rt); break; } case "B": { rt.Type = HapticEvent.HapticEventType.AxisBottom; bottomAxis.Add(rt); break; } case "S": { rt.Type = HapticEvent.HapticEventType.AxisSqueeze; squeezeAxis.Add(rt); break; } } break; } case "P": { rt.Start = Convert.ToInt32(split[0]); rt.Period = Convert.ToInt32(split[2]); rt.Magnitude = Convert.ToInt32(split[3]); rt.Direction = (String.CompareOrdinal("IN", split[5]) == 0) ? HapticEvent.DirectionType.In : HapticEvent.DirectionType.Out; rt.Duration = Convert.ToInt32(split[6]); rt.InMagnitude = Convert.ToInt32(split[7]); rt.InDuration = Convert.ToInt32(split[8]); rt.OutMagnitude = Convert.ToInt32(split[9]); rt.OutDuration = Convert.ToInt32(split[10]); switch (split[4]) { case "U": { rt.Type = HapticEvent.HapticEventType.PeriodicBoth; bothPeriodic.Add(rt); break; } case "T": { rt.Type = HapticEvent.HapticEventType.PeriodicTop; topPeriodic.Add(rt); break; } case "B": { rt.Type = HapticEvent.HapticEventType.PeriodicBottom; bottomPeriodic.Add(rt); break; } case "S": { rt.Type = HapticEvent.HapticEventType.PeriodicSqueeze; squeezePeriodic.Add(rt); break; } } break; } case "H": { rt.Start = Convert.ToInt32(split[0]); rt.Magnitude = Convert.ToInt32(split[2]); rt.Duration = 100; heat.Add(rt); break; } case "L": { rt.Start = Convert.ToInt32(split[0]); rt.Magnitude = Convert.ToInt32(split[2]); rt.Duration = Convert.ToInt32(split[3]); lube.Add(rt); break; } case "S": { rt.Start = Convert.ToInt32(split[0]); rt.Duration = 100; switch (split[2]) { case "A": { rt.StopType = HapticEvent.TypeOfStop.All; break; } case "H": { rt.StopType = HapticEvent.TypeOfStop.Heater; break; } case "T": { rt.StopType = HapticEvent.TypeOfStop.TopBelt; break; } case "B": { rt.StopType = HapticEvent.TypeOfStop.BottomBelt; break; } case "U": { rt.StopType = HapticEvent.TypeOfStop.BothBelts; break; } case "S": { rt.StopType = HapticEvent.TypeOfStop.Squeeze; break; } } stop.Add(rt); break; } } } AppViewModel.DataViewModel.TopAxisData = topAxis; AppViewModel.DataViewModel.BothAxisData = bothAxis; AppViewModel.DataViewModel.BottomAxisData = bottomAxis; AppViewModel.DataViewModel.SqueezeAxisData = squeezeAxis; AppViewModel.DataViewModel.TopPeriodicData = topPeriodic; AppViewModel.DataViewModel.BothPeriodicData = bothPeriodic; AppViewModel.DataViewModel.BottomPeriodicData = bottomPeriodic; AppViewModel.DataViewModel.SqueezePeriodicData = squeezePeriodic; AppViewModel.DataViewModel.LubeAxisData = lube; AppViewModel.DataViewModel.HeatAxisData = heat; AppViewModel.DataViewModel.StopAxisData = stop; }); }
public void process() { if (movements.Count < 2) return; if (movements.Count == 2) return; //todo later Console.WriteLine("********Here*********"); foreach (var movement in movements) { Console.WriteLine(movement.Value + " " + movement.Position.ToString()); } var start = movements[0]; this.movementTrend = start.Value < this.movements[1].Value ? Trend.Out : Trend.In; var lastVal = this.movements[1].Value; for (int i = 2; i < this.movements.Count; i++) { var movement = this.movements[i]; switch (movementTrend) { case Trend.In: if (lastVal <= movement.Value) { TimeSpan span = movement.Position - start.Position; if (span.TotalMilliseconds < 100) break; var startInMilli = start.Position.TotalMilliseconds; HapticEvent evt = new HapticEvent(); evt.Start = (int)startInMilli; evt.Duration = (int)span.TotalMilliseconds; evt.Magnitude = 200; evt.Direction = HapticEvent.DirectionType.In; start = movements[i]; AppViewModel.DataViewModel.TopAxisData.AddNewEvent(evt); if (i != movements.Count) { for (int j = i; j < movements.Count; j++ ) { if (!nearlyEqual((float)start.Value, (float)this.movements[j].Value, 0.00001f)) { this.movementTrend = start.Value < this.movements[j].Value ? Trend.Out : Trend.In; } } } } break; case Trend.Out: if (lastVal >= movement.Value) { TimeSpan span = movement.Position - start.Position; if (span.TotalMilliseconds < 100) break; var startInMilli = start.Position.TotalMilliseconds; HapticEvent evt = new HapticEvent(); evt.Start = (int)startInMilli; evt.Duration = (int)span.TotalMilliseconds; evt.Magnitude = 200; evt.Direction = HapticEvent.DirectionType.Out; start = movements[i]; AppViewModel.DataViewModel.TopAxisData.AddNewEvent(evt); if (i != movements.Count) { for (int j = i; j < movements.Count; j++) { if (!nearlyEqual((float)start.Value, (float)this.movements[j].Value, 0.00001f)) { this.movementTrend = start.Value < this.movements[j].Value ? Trend.Out : Trend.In; } } } } break; } lastVal = movement.Value; } movements.Clear(); }
public void Add(double val) { var m = new Movement { Value = val, Position = AppViewModel.VideoViewModel.Position }; movements.Add(m); if (movements.Count<2) return; if (movementTrend == Trend.None) figureMovementTrend(); if (movementTrend == Trend.None) return; if (movementTrend == Trend.In) { //value decreasing if (val > movements[movements.Count-2].Value) { //changing trend TimeSpan span = m.Position - movements[0].Position; if (span.TotalMilliseconds < 100) return; var startInMilli = movements[0].Position.TotalMilliseconds; HapticEvent evt = new HapticEvent(); evt.Start = (int)startInMilli; evt.Duration = (int)span.TotalMilliseconds; evt.Magnitude = 200; evt.Direction = HapticEvent.DirectionType.In; AppViewModel.DataViewModel.TopAxisData.AddNewEvent(evt); } else { return; } } if (movementTrend == Trend.Out) { //value increasing if (val < movements[movements.Count - 2].Value) { //changing trend TimeSpan span = m.Position - movements[0].Position; if (span.TotalMilliseconds < 100) return; var startInMilli = movements[0].Position.TotalMilliseconds; HapticEvent evt = new HapticEvent(); evt.Start = (int)startInMilli; evt.Duration = (int)span.TotalMilliseconds; evt.Magnitude = 200; evt.Direction = HapticEvent.DirectionType.Out; AppViewModel.DataViewModel.TopAxisData.AddNewEvent(evt); } else { return; } } movementTrend = Trend.None; movements.Clear(); }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { AppViewModel.TimelineViewModel.TimelineScroller = TimelineScroller; int count = 1; Task.Factory.StartNew( () => { var temp = new HapticCollection(); for (int i = 0; i < count; i++) { var evt = new HapticEvent { Direction = HapticEvent.DirectionType.Out, Duration = 100, InDuration = 25, InMagnitude = 100, Magnitude = 200, OutDuration = 25, OutMagnitude = 100, Period = 5, Start = 100 + (100 * i), StopType = HapticEvent.TypeOfStop.All }; temp.Add(evt); } AppViewModel.DataViewModel.TopAxisData = temp; }); Task.Factory.StartNew( () => { var temp = new HapticCollection(); for (int i = 0; i < count; i++) { var evt = new HapticEvent { Direction = HapticEvent.DirectionType.In, Duration = 100, InDuration = 25, InMagnitude = 100, Magnitude = 200, OutDuration = 25, OutMagnitude = 100, Period = 5, Start = 100 + (100 * i), StopType = HapticEvent.TypeOfStop.All }; temp.Add(evt); } AppViewModel.DataViewModel.BothAxisData = temp; }); Task.Factory.StartNew( () => { var temp = new HapticCollection(); for (int i = 0; i < count; i++) { var evt = new HapticEvent { Direction = HapticEvent.DirectionType.In, Duration = 100, InDuration = 25, InMagnitude = 100, Magnitude = 200, OutDuration = 25, OutMagnitude = 100, Period = 5, Start = 100 + (100 * i), StopType = HapticEvent.TypeOfStop.All }; temp.Add(evt); } AppViewModel.DataViewModel.BottomAxisData = temp; }); Task.Factory.StartNew( () => { var temp = new HapticCollection(); for (int i = 0; i < count; i++) { var evt = new HapticEvent { Direction = HapticEvent.DirectionType.In, Duration = 100, InDuration = 25, InMagnitude = 100, Magnitude = 200, OutDuration = 25, OutMagnitude = 100, Period = 5, Start = 100 + (100 * i), StopType = HapticEvent.TypeOfStop.All }; temp.Add(evt); } AppViewModel.DataViewModel.SqueezeAxisData = temp; }); Task.Factory.StartNew( () => { var temp = new HapticCollection(); for (int i = 0; i < count; i++) { var evt = new HapticEvent { Direction = HapticEvent.DirectionType.In, Duration = 100, InDuration = 25, InMagnitude = 100, Magnitude = 200, OutDuration = 25, OutMagnitude = 100, Period = 5, Start = 100 + (100 * i), StopType = HapticEvent.TypeOfStop.All }; temp.Add(evt); } AppViewModel.DataViewModel.TopPeriodicData = temp; }); Task.Factory.StartNew( () => { var temp = new HapticCollection(); for (int i = 0; i < count; i++) { var evt = new HapticEvent { Direction = HapticEvent.DirectionType.In, Duration = 100, InDuration = 25, InMagnitude = 100, Magnitude = 200, OutDuration = 25, OutMagnitude = 100, Period = 5, Start = 100 + (100 * i), StopType = HapticEvent.TypeOfStop.All }; temp.Add(evt); } AppViewModel.DataViewModel.BothPeriodicData = temp; }); Task.Factory.StartNew( () => { var temp = new HapticCollection(); for (int i = 0; i < count; i++) { var evt = new HapticEvent { Direction = HapticEvent.DirectionType.In, Duration = 100, InDuration = 25, InMagnitude = 100, Magnitude = 200, OutDuration = 25, OutMagnitude = 100, Period = 5, Start = 100 + (100 * i), StopType = HapticEvent.TypeOfStop.All }; temp.Add(evt); } AppViewModel.DataViewModel.BottomPeriodicData = temp; }); Task.Factory.StartNew( () => { var temp = new HapticCollection(); for (int i = 0; i < count; i++) { var evt = new HapticEvent { Direction = HapticEvent.DirectionType.In, Duration = 100, InDuration = 25, InMagnitude = 100, Magnitude = 200, OutDuration = 25, OutMagnitude = 100, Period = 5, Start = 100 + (100 * i), StopType = HapticEvent.TypeOfStop.All }; temp.Add(evt); } AppViewModel.DataViewModel.SqueezePeriodicData = temp; }); Task.Factory.StartNew( () => { var temp = new HapticCollection(); for (int i = 0; i < count; i++) { var evt = new HapticEvent { Direction = HapticEvent.DirectionType.In, Duration = 100, InDuration = 25, InMagnitude = 100, Magnitude = 200, OutDuration = 25, OutMagnitude = 100, Period = 5, Start = 100 + (100 * i), StopType = HapticEvent.TypeOfStop.All }; temp.Add(evt); } AppViewModel.DataViewModel.LubeAxisData = temp; }); Task.Factory.StartNew( () => { var temp = new HapticCollection(); for (int i = 0; i < count; i++) { var evt = new HapticEvent { Direction = HapticEvent.DirectionType.In, Duration = 100, InDuration = 25, InMagnitude = 100, Magnitude = 200, OutDuration = 25, OutMagnitude = 100, Period = 5, Start = 100 + (100 * i), StopType = HapticEvent.TypeOfStop.All }; temp.Add(evt); } AppViewModel.DataViewModel.HeatAxisData = temp; }); Task.Factory.StartNew( () => { var temp = new HapticCollection(); for (int i = 0; i < count; i++) { var evt = new HapticEvent { Direction = HapticEvent.DirectionType.In, Duration = 100, InDuration = 25, InMagnitude = 100, Magnitude = 200, OutDuration = 25, OutMagnitude = 100, Period = 5, Start = 100 + (100 * i), StopType = HapticEvent.TypeOfStop.All }; temp.Add(evt); } AppViewModel.DataViewModel.StopAxisData = temp; }); }
public override void TriggerHapticEvent(HapticEvent hapticEvent) { StartCoroutine(TriggerHapticEvent(OVRInput.Controller.LTouch, hapticEvent)); StartCoroutine(TriggerHapticEvent(OVRInput.Controller.RTouch, hapticEvent)); }