public void Evaluate(int spreadMax) { var gestureDevice = FInput[0] ?? GestureDevice.Empty; if (gestureDevice != FGestureDevice) { Unsubscribe(); FGestureDevice = gestureDevice; Subscribe(); } var notifications = FEnumerator.MoveNext() ? FEnumerator.Current : FEmptyList; var gestures = notifications.Where(g => (g.Kind == FGestureFilterKind) || ((g.Kind == GestureNotificationKind.GestureEnd) && (IdOut.Contains(g.Id)))) .ToList(); UseGestures(gestures); PositionOut.SliceCount = gestures.Count; IdOut.SliceCount = gestures.Count; DeviceIDOut.SliceCount = gestures.Count; for (int i = 0; i < gestures.Count; i++) { var position = new Vector2D(gestures[i].Position.X, gestures[i].Position.Y); var clientArea = new Vector2D(gestures[i].ClientArea.Width, gestures[i].ClientArea.Height); var normalizedPosition = VMath.Map(position, Vector2D.Zero, clientArea, new Vector2D(-1, 1), new Vector2D(1, -1), TMapMode.Float); PositionOut[i] = normalizedPosition; IdOut[i] = gestures[i].Id; DeviceIDOut[i] = gestures[i].GestureDeviceID; } }
public void Evaluate(int spreadMax) { var touchDevice = FInput[0] ?? TouchDevice.Empty; if (touchDevice != FTouchDevice) { Unsubscribe(); FTouchDevice = touchDevice; Subscribe(); } var notifications = FEnumerator.MoveNext() ? FEnumerator.Current : FEmptyList; FEventTypeOut.SliceCount = notifications.Count; PositionOut.SliceCount = notifications.Count; IdOut.SliceCount = notifications.Count; ContactAreaOut.SliceCount = notifications.Count; for (int i = 0; i < notifications.Count; i++) { var n = notifications[i]; FEventTypeOut[i] = n.Kind; var position = new Vector2D(n.Position.X, n.Position.Y); var clientArea = new Vector2D(n.ClientArea.Width, n.ClientArea.Height); PositionOut[i] = VMath.Map(position, Vector2D.Zero, clientArea, new Vector2D(-1, 1), new Vector2D(1, -1), TMapMode.Float); IdOut[i] = n.Id; ContactAreaOut[i] = new Vector2D(n.ContactArea.Width, n.ContactArea.Height); } }
static Point ToMousePoint(Vector2D normV) { var clientArea = new Vector2D(FClientArea.Width - 1, FClientArea.Height - 1); var v = VMath.Map(normV, new Vector2D(-1, 1), new Vector2D(1, -1), Vector2D.Zero, clientArea, TMapMode.Clamp); return(new Point((int)v.x, (int)v.y)); }
private void SetScroll(Vector2D scrollTo) { if (FScrollTo != scrollTo) { FScrollTo = scrollTo; using (var mainFrame = FBrowser.GetMainFrame()) { var x = VMath.Map(scrollTo.x, 0, 1, 0, 1, TMapMode.Clamp); var y = VMath.Map(scrollTo.y, 0, 1, 0, 1, TMapMode.Clamp); mainFrame.ExecuteJavaScript( string.Format(CultureInfo.InvariantCulture, @" var body = document.body, html = document.documentElement; var width = Math.max(body.scrollWidth, body.offsetWidth, html.clientWidth, html.scrollWidth, html.offsetWidth); var height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight); window.scrollTo({0} * width, {1} * height); ", x, y ), string.Empty, 0); } } }
public override void Process() { Rectangle[] rectangles; FInput.Image.GetImage(TColorFormat.L8, FGrayScale); var grayImage = FGrayScale.GetImage() as Image <Gray, byte>; if (GpuInvoke.HasCuda && AllowGpu) { rectangles = ProcessOnGpu(grayImage); } else { rectangles = ProcessOnCpu(grayImage); } FTrackingObjects.Clear(); foreach (var rectangle in rectangles) { var trackingObject = new TrackingObject(); var center = new Vector2D(rectangle.X + rectangle.Width / 2, rectangle.Y + rectangle.Height / 2); var maximumSourceXY = new Vector2D(FGrayScale.Width, FGrayScale.Height); trackingObject.Position = VMath.Map(center, FMinimumSourceXY, maximumSourceXY, FMinimumDestXY, FMaximumDestXY, TMapMode.Float); trackingObject.Scale = VMath.Map(new Vector2D(rectangle.Width, rectangle.Height), FMinimumSourceXY.x, maximumSourceXY.x, 0, 1, TMapMode.Float); FTrackingObjects.Add(trackingObject); } }
public void Config(NelderMeadSolver solver) { Configuration = new NelderMeadSolverParams(); Vector3D pos = FEstimatedPosition[0]; Vector3D min = pos - 0.5 * FTolerancePosition[0]; Vector3D max = pos + 0.5 * FTolerancePosition[0]; solver.SetBounds(1, min.x, max.x); // translation solver.SetBounds(2, min.y, max.y); solver.SetBounds(3, min.z, max.z); for (int b = 4; b <= 6; b++) { solver.SetBounds(b, -0.5, 0.5); // rotation } solver.SetBounds(7, 0.05, 0.49); // fov solver.SetBounds(8, -1, 1); // shift x solver.SetBounds(9, -1, 1); // shift y solver.SetValue(1, pos.x); solver.SetValue(2, pos.y); solver.SetValue(3, pos.z); solver.SetValue(4, VMath.Map(VMath.Random.Next(100), 0, 100, -0.05, 0.05, TMapMode.Float)); solver.SetValue(5, VMath.Map(VMath.Random.Next(100), 0, 100, -0.05, 0.05, TMapMode.Float)); solver.SetValue(6, VMath.Map(VMath.Random.Next(100), 0, 100, -0.05, 0.05, TMapMode.Float)); solver.SetValue(7, 0.01); solver.SetValue(8, 0.01); solver.SetValue(9, 0.20); }
//here we go, thats the method called by vvvv each frame //all data handling should be in here public void Evaluate(int SpreadMax) { if (FInput.PinIsChanged || FGamma.PinIsChanged || FBinSize.PinIsChanged) { double curIn, curGamma, tmpBin; int curBin; ArrayList outList = new ArrayList(); ArrayList curList; for (int i = 0; i < SpreadMax; i++) { FInput.GetValue(i, out curIn); FGamma.GetValue(i, out curGamma); FBinSize.GetValue(i, out tmpBin); curBin = (int)Math.Round(tmpBin); curList = new ArrayList(curBin); for (int j = 0; j < curBin; j++) { double start = j / (double)curBin / curGamma; double end = (curBin - 1.0) / (double)curBin / curGamma; end = start + 1.0 - end; curList.Add(VMath.Map(curIn, start, end, 0.0, 1.0, TMapMode.Clamp)); } outList.AddRange(curList); } FOut.SliceCount = outList.Count; for (int i = 0; i < outList.Count; i++) { FOut.SetValue(i, (double)outList[i]); } } }
protected override void CopyData(DX11DynamicTexture2D texture) { lock (m_lock) { for (int i = 0; i < this.colpoints.Length; i++) { if (FRelativeLookup[0]) { this.colorimage[i * 2] = (float)VMath.Map(colpoints[i].X - i % 640, 0, 640, 0, 1, TMapMode.Float); this.colorimage[i * 2 + 1] = (float)VMath.Map(colpoints[i].Y - VMath.Abs(i / 640), 0, 480, 0, 1, TMapMode.Float); } else { this.colorimage[i * 2] = (float)VMath.Map(colpoints[i].X, 0, 640, 0, 1, TMapMode.Clamp); this.colorimage[i * 2 + 1] = (float)VMath.Map(colpoints[i].Y, 0, 480, 0, 1, TMapMode.Clamp); } } fixed(float *f = &this.colorimage[0]) { IntPtr ptr = new IntPtr(f); texture.WriteData(ptr, this.width * this.height * 8); } } }
// Eyetracker to vvvv mapping private Vector2D MapValue_ETToVVVV(Vector2D v) { return(new Vector2D( VMath.Map(v.x, 0, 1, -1, 1, TMapMode.Float), VMath.Map(v.y, 0, 1, 1, -1, TMapMode.Float) )); }
public static Point DoMapPositionInNormalizedProjectionToPixels(this Vector2D normV, Size clientSize) { var clientArea = new Vector2D(clientSize.Width - 1, clientSize.Height - 1); var v = VMath.Map(normV, new Vector2D(-1, 1), new Vector2D(1, -1), Vector2D.Zero, clientArea, TMapMode.Float); return(new Point((int)v.x, (int)v.y)); }
public static Vector2D FromMousePoint(this Point point, Size clientArea) { var position = new Vector2D(point.X, point.Y); var ca = new Vector2D(clientArea.Width - 1, clientArea.Height - 1); return(VMath.Map(position, Vector2D.Zero, ca, new Vector2D(-1, 1), new Vector2D(1, -1), TMapMode.Float)); }
void SetResult(int bin, int id, double refvalue, double?overrideWeight = null) { FirstOut[bin][0] = id; WeightOfNextOut[bin][0] = overrideWeight ?? VMath.Map(refvalue, OrderedInput[bin][id], OrderedInput[bin][id + 1], 0.0, 1.0, TMapMode.Clamp); DistanceOut[bin][0] = Math.Abs(OrderedInput[bin][id + 1] - OrderedInput[bin][id]); }
#pragma warning restore 0649 public void Evaluate(int SpreadMax) { var system = OpenVRManager.System; if (system != null) { FOutStatus.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { FOutStatus[i] = "Ok"; var controller = FControllerIn[i]; if (controller == null) { FOutStatus[i] = "No Controller"; } else if (FInHapticEnabled[i]) { // see: https://github.com/ValveSoftware/openvr/wiki/IVRSystem::TriggerHapticPulse // see: https://steamcommunity.com/app/358720/discussions/0/517141624283630663/ // for now only axis with id 0 is working/implemented in OpenVR... and probably this will ner´ver change var duration = (int)VMath.Map(FInHapticDuration[0], 0, 1, 1, 3999, TMapMode.Clamp); system.TriggerHapticPulse(controller.index, 0, (char)duration); } } } else { FOutStatus.SliceCount = 1; FOutStatus[0] = "OpenVR is not initialized, at least one Poser (OpenVR) or Camera (OpenVR) must exist"; } }
public static Point ToMousePoint(this Vector2D normV) { var clientArea = new Vector2D(ClientArea.Width - 1, ClientArea.Height - 1); var v = VMath.Map(normV, new Vector2D(-1, 1), new Vector2D(1, -1), Vector2D.Zero, clientArea, TMapMode.Float); return(new Point((int)v.x, (int)v.y)); }
private void AllFrameReady(object sender, AllFramesReadyEventArgs e) { if (!FUpdate) { return; } DepthImageFrame df = e.OpenDepthImageFrame(); if (df != null) { df.CopyPixelDataTo(this.depthimage); this.runtime.Runtime.MapDepthFrameToColorFrame(DepthImageFormat.Resolution640x480Fps30, this.depthimage, ColorImageFormat.RgbResolution640x480Fps30, this.cp); lock (m_lock) { for (int i = 0; i < this.cp.Length; i++) { this.colorimage[i * 2] = (float)VMath.Map(cp[i].X, 0, 640, 0, 1, TMapMode.Clamp); this.colorimage[i * 2 + 1] = (float)VMath.Map(cp[i].Y, 0, 480, 0, 1, TMapMode.Clamp); } } this.FInvalidate = true; this.FUpdate = false; this.frameindex = df.FrameNumber; df.Dispose(); } }
public double GetValue(double val) { if (this.Reverse) { val = 1.0 - val; } return(VMath.Map(this.tweener(val), 0, 1, this.MinValue, this.MaxValue, TMapMode.Clamp)); }
public override TLBaseKeyFrame AddKeyFrame(Point P) { //called only from GUI-doubleclick float sliceheight = FPin.Height / FPin.SliceCount; float slicetop = FPin.Top + FSliceIndex * sliceheight; return(AddKeyFrame(FPin.Transformer.XPosToTime(P.X), (float)VMath.Map(P.Y, slicetop, slicetop + sliceheight, 0, 1, TMapMode.Clamp), "(empty)")); }
public override TLBaseKeyFrame AddKeyFrame(Point P) { //called only from GUI-doubleclick float sliceheight = FPin.Height / FPin.SliceCount; float slicetop = FPin.Top + FSliceIndex * sliceheight; return(AddKeyFrame(FPin.Transformer.XPosToTime(P.X), (float)VMath.Map(P.Y, slicetop, slicetop + sliceheight, FMaxValue, FMinValue, TMapMode.Float), FCurrentInType, FCurrentOutType)); }
public void OnImportsSatisfied() { PositionOut.SliceCount = 0; IdOut.SliceCount = 0; ContactAreaOut.SliceCount = 0; IsNewOut.SliceCount = 0; FSubscription = new Subscription <TouchDevice, TouchNotification>( touchDevice => { return(touchDevice.Notifications); }, (touchDevice, n) => { var position = new Vector2D(n.Position.X, n.Position.Y); var clientArea = new Vector2D(n.ClientArea.Width, n.ClientArea.Height); var normalizedPosition = VMath.Map(position, Vector2D.Zero, clientArea, new Vector2D(-1, 1), new Vector2D(1, -1), TMapMode.Float); var contactArea = new Vector2D(n.ContactArea.Width, n.ContactArea.Height); var index = IdOut.IndexOf(n.Id); switch (n.Kind) { case TouchNotificationKind.TouchDown: if (index < 0) { IdOut.Add(n.Id); PositionOut.Add(normalizedPosition); ContactAreaOut.Add(contactArea); IsNewOut.Add(true); } break; case TouchNotificationKind.TouchUp: if (index >= 0) { IdOut.RemoveAt(index); PositionOut.RemoveAt(index); ContactAreaOut.RemoveAt(index); IsNewOut.RemoveAt(index); } break; case TouchNotificationKind.TouchMove: if (index >= 0) { PositionOut[index] = normalizedPosition; ContactAreaOut[index] = contactArea; IsNewOut[index] = false; } break; default: throw new NotImplementedException(); } }, FScheduler ); }
public override TLBaseKeyFrame AddKeyFrame(Point P) { //called only from GUI-doubleclick float sliceheight = FPin.Height / FPin.SliceCount; float slicetop = FPin.Top + FSliceIndex * sliceheight; double start = FPin.Transformer.XPosToTime(P.X); double end = start + 1; int note = (int)VMath.Map(P.Y, slicetop, slicetop + sliceheight, FMaxNote, FMinNote, TMapMode.Float); return(AddKeyFrame(start, end, FSliceIndex, FSliceIndex, note, 100)); }
protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) { double mx = e.X; double my = e.Y; mx = VMath.Map(mx, 0, this.Width, -1.0, 1.0, TMapMode.Clamp); my = VMath.Map(my, 0, this.Height, 1.0, -1.0, TMapMode.Clamp); this.FMousePos.x = mx; this.FMousePos.y = my; base.OnMouseMove(e); }
private void ProcessTouches() { if (Closed) { return; } foreach (var touch in _touches.Values.ToList()) { if (touch.Type == CfxTouchEventType.Released || touch.Type == CfxTouchEventType.Cancelled) { _touches.Remove(touch.Id); //touch.Dispose(); } touch.Type = CfxTouchEventType.Released; } foreach (var(id, f, y, force, rad, rot) in SubmittedTouches.Values) { var ceftouch = new CfxTouchEvent { Type = _touches.ContainsKey(id) ? CfxTouchEventType.Moved : CfxTouchEventType.Pressed, Id = id, X = (float)VMath.Map(f, -1.0, 1.0, 0.0, TextureSize.w, TMapMode.Float), Y = (float)VMath.Map(y, 1.0, -1.0, 0.0, TextureSize.h, TMapMode.Float), Force = force, RadiusX = rad, RadiusY = rad, RotationAngle = rot }; _touches.UpdateGeneric(id, ceftouch); } foreach (var touch in _touches.Values) { Browser.Host.SendTouchEvent(touch); } if (BrowserSettings.NoMouseMoveOnFirstTouch) { return; } var firsttouch = _touches.Values.OrderBy(t => t.Id).FirstOrDefault(); if (firsttouch != null) { var me = new CfxMouseEvent { X = (int)firsttouch.X, Y = (int)firsttouch.Y }; Browser.Host.SendMouseMoveEvent(me, false); } }
/// <summary> /// Apply delta /// </summary> /// <param name="prev"></param> /// <param name="delta"></param> /// <param name="view"></param> /// <param name="rotSpeed"></param> /// <param name="frametime"></param> public CameraProperties( CameraProperties prev, CameraDelta delta, Matrix4x4 view, double rotSpeed = 1, double frametime = 1) : this(prev) { var rotmat = new Matrix4x4(VMath.Inverse(view)) { row4 = new Vector4D(0, 0, 0, 1) }; if (delta.SetTranslation) { Translation = prev.Translation + rotmat * (delta.Translation * frametime); } if (delta.SetRotation) { var inputrotmat = new Matrix4x4(InputView) { row4 = new Vector4D(0, 0, 0, 1) }; var inrotq = Quaternion.RotationMatrix(inputrotmat.ToSlimDXMatrix()); var rottime = frametime * rotSpeed; var rotq = Quaternion.RotationYawPitchRoll((float)(delta.PitchYawRoll.y * rottime), (float)(delta.PitchYawRoll.x * rottime), (float)(delta.PitchYawRoll.z * rottime)); //Rotation = Quaternion.Normalize(inrotq * rotq * Quaternion.Invert(inrotq) * Rotation); Rotation = Quaternion.Normalize(prev.Rotation * Quaternion.Invert(inrotq) * rotq * inrotq); } if (delta.SetPivotDistance) { PivotDistance = Math.Max(0, prev.PivotDistance + delta.PivotDistance * frametime); } if (delta.SetFov) { var nfov = VMath.Map(prev.Fov, 0.01, 0.45, 0, 1, TMapMode.Clamp); nfov += delta.Fov * frametime * (nfov + 0.05); Fov = VMath.Map(nfov, 0, 1, 0.01, 0.45, TMapMode.Clamp); } if (delta.SetNear) { Near = Math.Max(0, prev.Near + delta.Near * frametime); } if (delta.SetFar) { Far = Math.Max(0, prev.Far + delta.Far * frametime); } }
// vvvv to eyetracker mapping private List <Vector2D> MapValues_VVVVToET(List <Vector2D> pointList) { List <Vector2D> pList = new List <Vector2D>(); for (int i = 0; i < pointList.Count; i++) { pList.Add(new Vector2D( VMath.Map(pointList[i].x, -1, 1, 0, 1, TMapMode.Float), VMath.Map(pointList[i].y, -1, 1, 1, 0, TMapMode.Float) )); } return(pList); }
//called when data for any output pin is requested public void Evaluate(int SpreadMax) { int outcnt = Math.Max(FSwitch.SliceCount, FInput.SliceCount); FOutput.SliceCount = outcnt; for (int i = 0; i < outcnt; i++) { double sw = FSwitch[i] % (double)this.FInput[i].SliceCount; int min = (int)Math.Floor(sw) % this.FInput[i].SliceCount; int max = (int)Math.Ceiling(sw) % this.FInput[i].SliceCount; this.FOutput[i] = VMath.Map(sw - min, 0.0, 1.0, FInput[i][min], FInput[i][max], TMapMode.Clamp); } }
public int Read(float[] buffer, int offset, int count) { int samples = count; int index = 0; byte computed = 0; float samp = 0; double accumulator = 0.0; //double prevA = 0.0; double increment = 0.0; if (samples > 0) { increment = bufferCount / samples; } for (int i = 0; i < samples; i++) { index = (int)accumulator; if ((i % Scaler) == 0) { if (_generatorType != null) { computed = (byte)_generatorType.GetMethod("Compute").Invoke(null, new object[] { t, VMath.Lerp(BufferedA[index], BufferedA[index + 1], accumulator - index), VMath.Lerp(BufferedB[index], BufferedB[index + 1], accumulator - index), VMath.Lerp(BufferedC[index], BufferedC[index + 1], accumulator - index), VMath.Lerp(BufferedD[index], BufferedD[index + 1], accumulator - index) }); samp = (float)VMath.Map(computed, 0, 255, -1.0, 1.0, TMapMode.Clamp); accumulator += increment; t++; } else { buffer[i] = 0.0f; } } buffer[i] = samp; } bufferCount = 0; return(count); }
public TouchData Clone(float sizex, float sizey) { TouchData t = new TouchData(); t.Id = this.Id; float x = (float)VMath.Map(this.Pos.X, 0, sizex, -1.0f, 1.0f, TMapMode.Float); float y = (float)VMath.Map(this.Pos.Y, 0, sizey, 1.0f, -1.0f, TMapMode.Float); t.Pos = new Vector2(x, y); t.IsNew = this.IsNew; return(t); }
// Eyetracker to vvvv mapping private Vector2D MapValue_ETToVVVV(Vector2D v) { double inMin = 0; double inMax = 1; double outMinX = -1; double outMaxX = 1; double outMinY = 1; double outMaxY = -1; double x = VMath.Map(v.x, inMin, inMax, outMinX, outMaxX, TMapMode.Float); double y = VMath.Map(v.y, inMin, inMax, outMinY, outMaxY, TMapMode.Float); return(new Vector2D(x, y)); }
public virtual void OnImportsSatisfied() { FGestureFilterKind = SetGestureKindFilter(); PositionOut.SliceCount = 0; IdOut.SliceCount = 0; DeviceIDOut.SliceCount = 0; FSubscription = new Subscription <GestureDevice, GestureNotification>( gestureDevice => { return(gestureDevice.Notifications.Where(g => (g.Kind == FGestureFilterKind) || (g.Kind == GestureNotificationKind.GestureEnd))); }, (gestureDevice, g) => { var index = IdOut.IndexOf(g.Id); var isFilterMatch = g.Kind == FGestureFilterKind; UseGesture(g, isFilterMatch, index); if (isFilterMatch) { var position = new Vector2D(g.Position.X, g.Position.Y); var clientArea = new Vector2D(g.ClientArea.Width, g.ClientArea.Height); var normalizedPosition = VMath.Map(position, Vector2D.Zero, clientArea, new Vector2D(-1, 1), new Vector2D(1, -1), TMapMode.Float); if (index < 0) { PositionOut.Add(normalizedPosition); IdOut.Add(g.Id); DeviceIDOut.Add(g.GestureDeviceID); } else { PositionOut[index] = normalizedPosition; IdOut[index] = g.Id; DeviceIDOut[index] = g.GestureDeviceID; } } else if (index >= 0) { PositionOut.RemoveAt(index); IdOut.RemoveAt(index); DeviceIDOut.RemoveAt(index); } }, FScheduler ); }
public void update(out long tOut, out double envOut) { tOut = t; envOut = envelope; t++; switch (state) { //case ADSRState.FREE: // break; case ADSRState.A: envelope = VMath.Map(t, 0, adsr.aStage.ticks, 0.0, 1.0, TMapMode.Clamp); if (envelope >= 1.0) { state = ADSRState.D; } break; case ADSRState.D: envelope = VMath.Map(t, 0, adsr.dStage.ticks, 0.0, 1.0, TMapMode.Clamp); if (envelope >= 1.0) { state = ADSRState.S; } break; case ADSRState.S: envelope = VMath.Map(t, 0, adsr.sStage.ticks, 0.0, 1.0, TMapMode.Clamp); if (envelope >= 1.0) { state = ADSRState.R; } break; case ADSRState.R: envelope = VMath.Map(t, 0, adsr.rStage.ticks, 0.0, 1.0, TMapMode.Clamp); if (envelope >= 1.0) { state = ADSRState.FREE; t = 0; } break; } }