void TraceLumpPoints(IInputObservable io) { io.Any().Buffer(io.OnEnd).Subscribe(es => { log($"<color=red>Seqeuence {es.Count} points</color>"); log($" {es[0]}"); if (es.Count > 2) { log($" {string.Join(",", es.Select((e, i) => (e, i)).Where((e, i) => 1 <= i && i < es.Count - 1).Select(x => x.e.position.ToString()))}"); } log($" {es[es.Count - 1]}"); foreach (var e in es) { switch (e.type) { case InputEventType.Begin: draw.Put(e, Color.red); break; case InputEventType.Move: draw.Put(e, Color.black); break; case InputEventType.End: draw.Put(e, Color.yellow); break; } } }).AddTo(disposables); }
public static IObservable <InputEvent> DoubleSequence(this IInputObservable io, double interval) { return(io.OnBegin.TimeInterval() .Buffer(2, 1) .Where(events => events[0].Interval.TotalMilliseconds > interval && events[1].Interval.TotalMilliseconds <= interval) .Select(events => events[1].Value)); }
public OpenGLVisualization(IEnumerable<IGraphicalBody> graphicalBodies, bool vr, params ILightSource[] lights) : base(1220, 720, new GraphicsMode(GraphicsMode.Default.ColorFormat, GraphicsMode.Default.Depth, GraphicsMode.Default.Stencil, NumFSAASamples, GraphicsMode.Default.AccumulatorFormat), "LabBox Vis") { VRFlag = vr; if (VRFlag) { vrScene = OpenVRScene.Create(NearClip, FarClip); Input = vrScene.OpenVRInput; vrDrawable = new BasicDrawable((vpMat, camPos) => RenderVR(vpMat, camPos)); } else { Input = new OpenGLInputObservable(this); } // not sure how we should handle the ICamera interface in VR yet var cam = new FreeCamera(Input); cam.MaxRange = FarClip; cam.MinRange = NearClip; toDispose.Add(cam); Camera = cam; bodies = graphicalBodies.ToList(); lightSources = lights.ToList(); BindEvents(); }
public ItemSelector(IInputObservable input, Func <Optional <T> > selectionFunction) { Input = input; SelectionFunction = selectionFunction; SubToInput(input); }
public OpenGLVisualization(IEnumerable <IGraphicalBody> graphicalBodies, bool vr, params ILightSource[] lights) : base(1220, 720, new GraphicsMode(GraphicsMode.Default.ColorFormat, GraphicsMode.Default.Depth, GraphicsMode.Default.Stencil, NumFSAASamples, GraphicsMode.Default.AccumulatorFormat), "LabBox Vis") { VRFlag = vr; if (VRFlag) { vrScene = OpenVRScene.Create(NearClip, FarClip); Input = vrScene.OpenVRInput; vrDrawable = new BasicDrawable((vpMat, camPos) => RenderVR(vpMat, camPos)); } else { Input = new OpenGLInputObservable(this); } // not sure how we should handle the ICamera interface in VR yet var cam = new FreeCamera(Input); cam.MaxRange = FarClip; cam.MinRange = NearClip; toDispose.Add(cam); Camera = cam; bodies = graphicalBodies.ToList(); lightSources = lights.ToList(); BindEvents(); }
public static IObservable <Unit> Keep(this IInputObservable io, double interval, Func <bool> pred) { return(io.OnBegin.SelectMany(_ => Observable.Interval(TimeSpan.FromMilliseconds(interval)) .TakeUntil(io.OnEnd) .Where(x => pred()) .Select(x => Unit.Default))); }
void TraceLongPress(IInputObservable io) { io.LongSequence(500).Subscribe(e => { log($"<color=green>long press at {e}</color>"); draw.Put(e, Color.green); }).AddTo(disposables); }
public static IObservable <InputEvent> LongSequence(this IInputObservable io, double interval) { return(io.OnBegin.SelectMany(e => Observable.Interval(TimeSpan.FromMilliseconds(interval)) .First() .Select(_ => e) .TakeUntil(io.OnEnd))); }
public static IObservable <VerocityInfo> Verocity(this IInputObservable io) { return(io.OnBegin.SelectMany(e => Observable.Merge(Observable.Return(e), io.Any().TakeUntil(io.OnEnd.DelayFrame(1))) .TimeInterval() .Buffer(2, 1)) .Where(ts => ts.Count > 1) .Select(ts => VerocityInfo.Create(ts[0], ts[1]))); }
void TraceDoubleTap(IInputObservable io) { io.DoubleSequence(250).Subscribe(e => { var msg = $"<color=blue>double click/tap ({e})</color>"; log(msg); draw.Put(e, Color.blue); }).AddTo(disposables); }
void TraceAllVerocity(IInputObservable io) { io.Any().Subscribe(e => { Debug.Log(e); draw.Put(e, Color.blue); }).AddTo(disposables); io.Verocity().Subscribe(v => { Debug.Log($">> {v}"); draw.Put(v, Color.magenta); }).AddTo(disposables); }
public static IObservable <Vector2> Difference(this IInputObservable io) { return(io.OnBegin.SelectMany(e => Observable.Merge(Observable.Return(e), io.Any().TakeUntil(io.OnEnd.DelayFrame(1))) .Buffer(2, 1)) .Where(events => events.Count > 1) .Select(events => { return new Vector2 { x = events[1].position.x - events[0].position.x, y = events[1].position.y - events[0].position.y }; })); }
public static IObservable <IList <VerocityInfo> > TakeLastVerocities(this IInputObservable io, int count) { return(io.TakeLastTimeIntervalBuffer(count).Select(timeEvents => { var verocities = new List <VerocityInfo>(); var prev = timeEvents.First(); for (int i = 1; i < timeEvents.Count; i++) { var t = timeEvents[i]; verocities.Add(VerocityInfo.Create(prev, t)); prev = t; } return verocities; })); }
void TraceLastVerocity(IInputObservable io, int count) { io.Any().Subscribe(e => { draw.Put(e, Color.blue); }).AddTo(disposables); io.TakeLastVerocities(count).Subscribe(vs => { log(string.Join(", ", vs.Select(vi => vi.ToString()))); foreach (var v in vs) { draw.Put(v, Color.magenta); } }).AddTo(disposables); }
// Rect Stream which completes when either one of io1 and io2 // Client have to Repeat() for permanent stream. public static IObservable <Rect> From(IInputObservable io1, IInputObservable io2) { var end = Observable.Merge(io1.OnEnd, io2.OnEnd); return(Observable.CombineLatest(io1.Any(), io2.Any()) .TakeUntil(end) .Select(es => { var x = Mathf.Min(es[0].position.x, es[1].position.x); var y = Mathf.Min(es[0].position.y, es[1].position.y); return new Rect(x, y, Mathf.Abs(es[0].position.x - es[1].position.x), Mathf.Abs(es[0].position.y - es[1].position.y)); }) .DistinctUntilChanged()); }
private void SubToInput(IInputObservable input) { var enabledEvts = from evt in input.InputEvents where Enabled select evt; var primSelects = from evt in enabledEvts where evt.Input == InputType.PrimarySelect select evt; var multiSelects = from evt in enabledEvts where evt.Input == InputType.MultiSelect select evt; subs.Add(multiSelects.Subscribe(inpt => { multiModifierDown = inpt.State != InputState.Finish; })); subs.Add(primSelects.Where(ps => ps.State == InputState.Finish).Subscribe(inpt => { Optional <T> selectedItem = SelectionFunction(); selectedItem.Do(item => NewSelection(item), () => DeselectAll()); })); }
public FreeCamera(IInputObservable camInput) { CameraInput = camInput; // all inputs when were not locked var inputs = from evt in camInput.InputEvents where !IsLocked select evt; // handle look inputs var turnLeftInputs = from inpt in inputs where inpt.Input == InputType.TurnLeft select inpt; var turnRightInputs = from inpt in inputs where inpt.Input == InputType.TurnRight select inpt; var turnUpInputs = from inpt in inputs where inpt.Input == InputType.TurnUp select inpt; var turnDownInputs = from inpt in inputs where inpt.Input == InputType.TurnDown select inpt; subs.Add(turnLeftInputs.Subscribe(inpt => MoveLookAtPos(inpt.Weight * TurnSpeed * -HorizontalRight()))); subs.Add(turnRightInputs.Subscribe(inpt => MoveLookAtPos(inpt.Weight * TurnSpeed * HorizontalRight()))); subs.Add(turnUpInputs.Subscribe(inpt => MoveLookAtPos(inpt.Weight * TurnSpeed * Vector3.J))); subs.Add(turnDownInputs.Subscribe(inpt => MoveLookAtPos(inpt.Weight * TurnSpeed * -Vector3.J))); // handle movement inputs var fwdInputs = from inpt in inputs where inpt.Input == InputType.Forward select inpt; subs.Add(fwdInputs.Where(inpt => inpt.State == InputState.Start).Subscribe(inpt => StartMovement(MovementDir.Forward))); subs.Add(fwdInputs.Where(inpt => inpt.State == InputState.Finish).Subscribe(inpt => EndMovement(MovementDir.Forward))); var bwdInputs = from inpt in inputs where inpt.Input == InputType.Backward select inpt; subs.Add(bwdInputs.Where(inpt => inpt.State == InputState.Start).Subscribe(inpt => StartMovement(MovementDir.Backward))); subs.Add(bwdInputs.Where(inpt => inpt.State == InputState.Finish).Subscribe(inpt => EndMovement(MovementDir.Backward))); var leftInputs = from inpt in inputs where inpt.Input == InputType.Left select inpt; subs.Add(leftInputs.Where(inpt => inpt.State == InputState.Start).Subscribe(inpt => StartMovement(MovementDir.Left))); subs.Add(leftInputs.Where(inpt => inpt.State == InputState.Finish).Subscribe(inpt => EndMovement(MovementDir.Left))); var rightInputs = from inpt in inputs where inpt.Input == InputType.Right select inpt; subs.Add(rightInputs.Where(inpt => inpt.State == InputState.Start).Subscribe(inpt => StartMovement(MovementDir.Right))); subs.Add(rightInputs.Where(inpt => inpt.State == InputState.Finish).Subscribe(inpt => EndMovement(MovementDir.Right))); var upInputs = from inpt in inputs where inpt.Input == InputType.Up select inpt; subs.Add(upInputs.Where(inpt => inpt.State == InputState.Start).Subscribe(inpt => StartMovement(MovementDir.Up))); subs.Add(upInputs.Where(inpt => inpt.State == InputState.Finish).Subscribe(inpt => EndMovement(MovementDir.Up))); var downInputs = from inpt in inputs where inpt.Input == InputType.Down select inpt; subs.Add(downInputs.Where(inpt => inpt.State == InputState.Start).Subscribe(inpt => StartMovement(MovementDir.Down))); subs.Add(downInputs.Where(inpt => inpt.State == InputState.Finish).Subscribe(inpt => EndMovement(MovementDir.Down))); }
void TraceBasic(IInputObservable io) { io.OnBegin.Subscribe(e => { log(e.ToString()); draw.Put(e, Color.red); }).AddTo(disposables); io.OnMove.Subscribe(e => { log(e.ToString()); draw.Put(e, Color.black); }).AddTo(disposables); io.OnEnd.Subscribe(e => { log(e.ToString()); draw.Put(e, Color.yellow); }).AddTo(disposables); }
void TraceDragAndDrop(IInputObservable io) { io.LongSequence(500).Subscribe(begin => { log($"<color=green>Drag begin at. {begin}</color>"); draw.DragBegin(begin, Color.green, begin.ToString()); io.MoveThrottle(100).TakeUntil(io.OnEnd).Subscribe(drag => { log($"Dragging. {drag}"); draw.Dragging(drag, Color.green, drag.ToString()); }).AddTo(disposables); io.OnEnd.First().Subscribe(drop => { log($"<color=green>Drop at. {drop}</color>"); draw.DragEnd(drop, Color.green, drop.ToString()); }).AddTo(disposables); }).AddTo(disposables); }
public static IObservable <InputEvent> Any(this IInputObservable io) { return(Observable.Merge(io.OnBegin, io.OnMove, io.OnEnd)); }
public static ItemSelector <IBody> BodySelector(IInputObservable input, IUniverse uni, Func <Vector3> rayOrigin, Func <Vector3> rayDir) { return(new ItemSelector <IBody>(input, () => uni.RaySelect(rayOrigin(), rayDir()))); }
public static ItemSelector <IBody> BodySelector(IInputObservable input, IUniverse uni, Vector3 rayOrigin, Vector3 rayDir) { return(BodySelector(input, uni, () => rayOrigin, () => rayDir)); }
public static ItemSelector<IBody> BodySelector(IInputObservable input, IUniverse uni, Vector3 rayOrigin, Vector3 rayDir) { return BodySelector(input, uni, () => rayOrigin, () => rayDir); }
public static ItemSelector<IBody> BodySelector(IInputObservable input, IUniverse uni, ICamera cam) { return BodySelector(input, uni, () => cam.Pos, () => (cam.LookAtPos - cam.Pos).UnitDirection); }
public static ItemSelector<IBody> BodySelector(IInputObservable input, IUniverse uni, Func<Vector3> rayOrigin, Func<Vector3> rayDir) { return new ItemSelector<IBody>(input, () => uni.RaySelect(rayOrigin(), rayDir())); }
public static IObservable <TimeInterval <InputEvent> > TimeIntervalSequence(this IInputObservable io) { return(io.OnBegin.SelectMany(e => Observable.Merge(Observable.Return(e), io.Any().TakeUntil(io.OnEnd.DelayFrame(1))) .TimeInterval())); }
public static ItemSelector <IBody> BodySelector(IInputObservable input, IUniverse uni, ICamera cam) { return(BodySelector(input, uni, () => cam.Pos, () => (cam.LookAtPos - cam.Pos).UnitDirection)); }
public static IObservable <InputEvent> MoveThrottle(this IInputObservable io, double interval) { return(io.OnMove.ThrottleFirst(TimeSpan.FromMilliseconds(interval))); }
public static IObservable <IList <TimeInterval <InputEvent> > > TakeLastTimeIntervalBuffer(this IInputObservable io, int count) { // return io.Any().TakeUntil(io.End.DelayFrame(1)) // .TimeInterval() // .TakeLast(count) // .Buffer(count) // .RepeatUntilDestroy(io.Context.gameObject); return(io.OnBegin.SelectMany(e => Observable.Merge(Observable.Return(e), io.Any().TakeUntil(io.OnEnd.DelayFrame(1))) .TimeInterval() .TakeLast(count) .Buffer(count))); }