public BlendStruct Interpolate(BlendStruct a, BlendStruct b, float alpha) { return(new BlendStruct( VMath.Lerp(a.A, b.A, (double)alpha), VMath.Lerp(a.B, b.B, (double)alpha), VMath.Lerp(a.C, b.C, (double)alpha) )); }
private (double p, double t) BezierCurveDC(double p1, double p2, double c1, double c2, double mu, double tandist) { var ls = DeCasteljau(p1, p2, c1, c2, mu); var p = VMath.Lerp(ls.a, ls.b, mu); var t = VMath.Lerp(ls.a, ls.b, mu + tandist) - p; return(p, t); }
public CameraProperties Lerp(CameraProperties other, double alpha) { return(new CameraProperties( InputView, VMath.Lerp(Translation, other.Translation, alpha), Quaternion.Slerp(Rotation, other.Rotation, (float)alpha), VMath.Lerp(PivotDistance, other.PivotDistance, alpha), VMath.Lerp(Fov, other.Fov, alpha), Near, Far )); }
private (double a, double b) DeCasteljau(double p1, double p2, double c1, double c2, double mu) { var p1c1 = VMath.Lerp(p1, c1, mu); var c1c2 = VMath.Lerp(c1, c2, mu); var c2p2 = VMath.Lerp(c2, p2, mu); var p1c1_c1c2 = VMath.Lerp(p1c1, c1c2, mu); var c1c2_c2p2 = VMath.Lerp(c1c2, c2p2, mu); return(p1c1_c1c2, c1c2_c2p2); }
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 override int Read(byte[] buffer, int offset, int count) { int samples = count; int index = 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 (_generatorType != null) { buffer[i] = (byte)_generatorType.GetMethod("Compute").Invoke(null, new object[] { t, BufferedA[index], BufferedB[index], BufferedC[index], VMath.Lerp(BufferedD[index], BufferedD[index + 1], accumulator - index) }); accumulator += increment; t++; } else { buffer[i] = 127; } } bufferCount = 0; return(count); }
public override void Evaluate(double CurrentTime) { base.Evaluate(CurrentTime); double t; TLBaseKeyFrame kf = FKeyFrames.FindLast(delegate(TLBaseKeyFrame k) { return(k.Time <= CurrentTime); }); TLBaseKeyFrame kf1 = FKeyFrames.Find(delegate(TLBaseKeyFrame k) { return(k.Time >= CurrentTime); }); if (kf == null && kf1 == null) { FOutput = 0; } else if (kf == null) { FOutput = (kf1 as TLValueKeyFrame).Value; } else if (kf1 == null) { FOutput = (kf as TLValueKeyFrame).Value; } else { if ((kf as TLValueKeyFrame).OutType == TLInterpolationType.Step) { FOutput = (kf as TLValueKeyFrame).Value; } else if ((kf as TLValueKeyFrame).OutType == TLInterpolationType.Linear) { // LINEAR INTERPOLATION t = VMath.Map(CurrentTime, kf.Time, kf1.Time, 0, 1, TMapMode.Float); FOutput = VMath.Lerp((kf as TLValueKeyFrame).Value, (kf1 as TLValueKeyFrame).Value, t); } else if ((kf as TLValueKeyFrame).OutType == TLInterpolationType.Cubic) { // CUBIC INTERPOLATION t = VMath.Map(CurrentTime, kf.Time, kf1.Time, 0, 1, TMapMode.Float); FOutput = VMath.SolveCubic(t, (kf as TLValueKeyFrame).Value, (kf as TLValueKeyFrame).Value, (kf1 as TLValueKeyFrame).Value, (kf1 as TLValueKeyFrame).Value); } //spline here } OutputAsString = FOutput.ToString("f4", TimelinerPlugin.GNumberFormat); }
public void update(double dt, double amount) { vel += VMath.Lerp(acc, force, amount) * dt; loc += vel; timer -= dt; }
private IEnumerable <EtherDreamPoint> GetFrame() { var colIndex = 0; var shapeIndex = 0; var result = Enumerable.Empty <EtherDreamPoint>(); foreach (var shape in FPointsInput) { var isClosed = FClosedShapeInput[shapeIndex]; Vector2D start; Vector2D end; if (isClosed) { start = shape[shape.SliceCount - 1]; end = start; } else { start = shape[0]; end = shape[shape.SliceCount - 1]; } //start blanks result = result.Concat(Enumerable.Repeat(CreateEtherDreamPoint(start, VColor.Black), FStartBlanksInput[shapeIndex])); var lastPoint = Vector2D.Zero; var doInterpolate = false; foreach (var p in shape) { var col = FColorsInput[colIndex++]; //interpolate from last point if (doInterpolate) { var count = (int)Math.Floor(VMath.Dist(lastPoint, p) / Math.Max(FPointInterpolationDistanceInput[shapeIndex], 0.0001)); var factor = 1.0 / (count + 1); //points in between, need to be caculated directly since linq lazyness would access only the last value in lastPoint result = result.Concat(Enumerable.Range(1, count).Select(index => CreateEtherDreamPoint(VMath.Lerp(lastPoint, p, index * factor), col)).ToArray()); } else if (isClosed) // first iteration { var count = (int)Math.Floor(VMath.Dist(end, p) / Math.Max(FPointInterpolationDistanceInput[shapeIndex], 0.0001)); var factor = 1.0 / (count + 1); //points in between, need to be caculated directly since linq lazyness would access only the last value in lastPoint result = result.Concat(Enumerable.Range(1, count).Select(index => CreateEtherDreamPoint(VMath.Lerp(end, p, index * factor), col)).ToArray()); } //actual point result = result.Concat(Enumerable.Repeat(CreateEtherDreamPoint(p, col), FPointRepeatInput[shapeIndex])); lastPoint = p; doInterpolate = true; } //end blanks result = result.Concat(Enumerable.Repeat(CreateEtherDreamPoint(end, VColor.Black), FEndBlanksInput[shapeIndex++])); } return(result); }
public void Evaluate(int SpreadMax) { if (FDeltaIn.IsConnected) { FCamDelta.SliceCount = FDeltaIn.SliceCount + 1; for (int i = 0; i < FDeltaIn.SliceCount; i++) { FCamDelta[i] = FDeltaIn[i]; } FCamDelta[-1] = Delta; } else { FCamDelta[0] = Delta; } Delta.LockCursor = false; Delta.ResetSignals(); if (Delta.InputMouse != null) { if (Init) { Init = false; MouseObserver = new AccumulatingMouseObserver(); KeyboardObserver = new AccumulatingKeyboardObserver(); MouseObserver.SubscribeTo(Delta.InputMouse.MouseNotifications); KeyboardObserver.SubscribeTo(Delta.InputKeyboard.KeyNotifications); PrevFrameTime = FHDEHost.FrameTime; } var dt = FHDEHost.FrameTime - PrevFrameTime; var smoothness = FSmooth[0] > 0.00001 ? Math.Min(1.0f / (((float)FSmooth[0] / 6.0f) / (float)dt), 1.0f) : 1; //var carea = MouseObserver?.LastNotification?.ClientArea ?? new Size(1, 1); //var aspx = Math.Min(1, (double)carea.Height / (double)carea.Width); //var aspy = Math.Min(1, (double)carea.Width / (double)carea.Height); var mousepos = new Vector2D( MouseObserver.AccumulatedXDelta /* aspx*/, MouseObserver.AccumulatedYDelta /* aspy*/); var mousewheel = new Vector2D( (double)MouseObserver.AccumulatedWheelDelta / 120, (double)MouseObserver.AccumulatedHorizontalWheelDelta / 120); try { if (Delta.InteractUpstream) { if (MouseObserver.MouseClicks[FRotationButton[0]].DoubleClick) { Delta.ResetRotation = true; } if (MouseObserver.MouseClicks[FTranslationXYButton[0]].DoubleClick) { Delta.ResetTranslation = true; } if (MouseObserver.MouseClicks[FPivotDistanceButton[0]].DoubleClick) { Delta.ResetPivotDistance = true; } if (MouseObserver.MouseClicks[FZoomButton[0]].DoubleClick) { Delta.ResetFov = true; } } } catch { } //FMousePos[0] = new Vector4D(mousepos, mousewheel); //FMouseButtons[0] = (uint) Delta.InputMouse.PressedButtons; var translxykey = FTranslationXYKey[0] == Keys.None; var translzkey = FTranslationZKey[0] == Keys.None; var forw = false; var left = false; var backw = false; var right = false; var up = false; var down = false; var rotkey = FRotationKey[0] == Keys.None; var rollkey = FRollKey[0] == Keys.None; var pdkey = FPivotDistanceKey[0] == Keys.None; var zoomkey = FZoomKey[0] == Keys.None; var keyboard = from kp in KeyboardObserver.Keypresses.Values select kp.KeyCode; foreach (var key in keyboard) { translxykey = translxykey || key == FTranslationXYKey[0]; translzkey = translzkey || key == FTranslationZKey[0]; if (FWASDSpeed[0] > 0.0) { forw = forw || key == FForwardKey[0]; left = left || key == FStrafeLeftKey[0]; backw = backw || key == FBackwardKey[0]; right = right || key == FStrafeRightKey[0]; up = up || key == FStrafeUpKey[0]; down = down || key == FStrafeDownKey[0]; } rotkey = rotkey || key == FRotationKey[0]; rollkey = rollkey || key == FRollKey[0]; pdkey = pdkey || key == FPivotDistanceKey[0]; zoomkey = zoomkey || key == FZoomKey[0]; } if (Delta.InteractUpstream) { //// Translation var transl = new Vector3D(0, 0, 0); var crot = new Vector3D(0, 0, 0); var translinf = VMath.Lerp(1.0, Math.Max(Delta.ConnectedCamera.Properties.PivotDistance * 0.25, 0.1), FTranslDistInf[0]); if (MouseObserver.MouseClicks[FTranslationXYButton[0]].Pressed && translxykey) { if (!translzkey || FTranslationZKey[0] == Keys.None) { transl.x += mousepos.x; transl.y -= mousepos.y; Delta.LockCursor = true; } } if (MouseObserver.MouseClicks[FTranslationZButton[0]].Pressed && translzkey) { if (!translxykey || FTranslationXYKey[0] == Keys.None) { transl.z += mousepos.y; Delta.LockCursor = true; } } transl *= FTranslSpeed[0] * translinf; // WASD Transl if (forw) { transl.z -= FWASDSpeed[0]; } if (backw) { transl.z += FWASDSpeed[0]; } if (left) { transl.x += FWASDSpeed[0]; } if (right) { transl.x -= FWASDSpeed[0]; } if (up) { transl.y -= FWASDSpeed[0]; } if (down) { transl.y += FWASDSpeed[0]; } Delta.Translation = Filters.Lowpass(Delta.Translation.AsSystemVector(), transl.AsSystemVector(), new Vector3(smoothness)).AsVVector(); //// Rotation bool rotate = false; var mouserot = new Vector2D(mousepos * FRotSpeed[0]); if (FInvY[0]) { mouserot.y *= -1; } if (Delta.ConnectedCamera.Properties.PivotDistance < 0.1) { mouserot *= -1; } if (MouseObserver.MouseClicks[FRotationButton[0]].Pressed && rotkey || forw || backw || left || right || up || down) { if (!rollkey || FRollKey[0] == Keys.None) { Delta.LockCursor = true; // Prepare mouserot.x = Math.Min(Math.Abs(mouserot.x) * 0.1, 0.499) * Math.Sign(mouserot.x); mouserot.y = Math.Min(Math.Abs(mouserot.y) * 0.1, 0.499) * Math.Sign(mouserot.y); // Trackball var trackbpos = new Vector2D( Math.Pow(Math.Abs(FTrackballScreenPos[0].x), 2) * Math.Sign(FTrackballScreenPos[0].x), Math.Pow(Math.Abs(FTrackballScreenPos[0].y), 2) * Math.Sign(FTrackballScreenPos[0].y)); trackbpos *= -0.25; var trackbtr = VMath.Rotate(trackbpos.y * Math.PI * 2, trackbpos.x * Math.PI * -2, 0); var trackxv = trackbtr * new Vector3D(-1, 0, 0); var trackyv = trackbtr * new Vector3D(0, -1, 0); crot = VMath.QuaternionToEulerYawPitchRoll( (Quaternion.RotationAxis(trackxv.ToSlimDXVector(), (float)(mouserot.y * Math.PI * -2)) * Quaternion.RotationAxis(trackyv.ToSlimDXVector(), (float)(mouserot.x * Math.PI * -2)) ).ToVector4D()); //crot = new Vector3D(mouserot.y, mouserot.x, 0); crot *= 10; rotate = true; } } if (MouseObserver.MouseClicks[FRollButton[0]].Pressed && rollkey) { if (!rotkey || FRotationKey[0] == Keys.None) { Delta.LockCursor = true; crot += new Vector3D(0, 0, mouserot.x * Math.PI * 2); rotate = true; } } if (rotate) { Delta.LockCursor = true; } Delta.PitchYawRoll = Filters.Lowpass(Delta.PitchYawRoll.AsSystemVector(), crot.AsSystemVector(), new Vector3(smoothness)).AsVVector(); double pivotd = 0; double zoom = mousewheel.y * FScrollMul[0] * FZoomSpeed[0]; if (zoomkey && (!pdkey || FPivotDistanceKey[0] == Keys.None)) { zoom -= mousewheel.x * FScrollMul[0] * FZoomSpeed[0]; if (MouseObserver.MouseClicks[FZoomButton[0]].Pressed && zoomkey) { Delta.LockCursor = true; zoom -= mousepos.y * FZoomSpeed[0]; } } if (pdkey && (!zoomkey || FZoomKey[0] == Keys.None)) { pivotd -= mousewheel.x * FScrollMul[0] * FTranslSpeed[0]; if (MouseObserver.MouseClicks[FPivotDistanceButton[0]].Pressed && pdkey) { Delta.LockCursor = true; pivotd -= mousepos.y * FTranslSpeed[0]; } } Delta.PivotDistance = Filters.Lowpass((float)Delta.PivotDistance, (float)pivotd, smoothness); Delta.Fov = Filters.Lowpass((float)Delta.Fov, (float)zoom, smoothness); } MouseObserver.ResetAccumulation(); KeyboardObserver.ResetAccumulation(); } else { MouseObserver?.Unsubscribe(); KeyboardObserver?.Unsubscribe(); Init = true; } PrevFrameTime = FHDEHost.FrameTime; }
/// <summary> /// Reads from this provider. /// </summary> public int Read(float[] buffer, int offset, int count) { int outIndex = offset; // Generator current value double multiple; double sampleValue; double sampleSaw; int index = 0; double accumulator = 0.0; double increment = 0.0; if (count > 0) { increment = bufferCount / count; } // Complete Buffer for (int sampleCount = 0; sampleCount < count / waveFormat.Channels; sampleCount++) { index = (int)accumulator; Gain = VMath.Lerp(BufferedGain[index], BufferedGain[index + 1], accumulator - index); switch (Type) { case SignalGeneratorType.Sin: // Sinus Generator multiple = TwoPi * Frequency / waveFormat.SampleRate; sampleValue = Gain * Math.Sin(nSample * multiple); nSample++; break; case SignalGeneratorType.Square: // Square Generator multiple = 2 * Frequency / waveFormat.SampleRate; sampleSaw = ((nSample * multiple) % 2) - 1; sampleValue = sampleSaw > 0 ? Gain : -Gain; nSample++; break; case SignalGeneratorType.Triangle: // Triangle Generator multiple = 2 * Frequency / waveFormat.SampleRate; sampleSaw = ((nSample * multiple) % 2); sampleValue = 2 * sampleSaw; if (sampleValue > 1) { sampleValue = 2 - sampleValue; } if (sampleValue < -1) { sampleValue = -2 - sampleValue; } sampleValue *= Gain; nSample++; break; case SignalGeneratorType.SawTooth: // SawTooth Generator multiple = 2 * Frequency / waveFormat.SampleRate; sampleSaw = ((nSample * multiple) % 2) - 1; sampleValue = Gain * sampleSaw; nSample++; break; case SignalGeneratorType.White: // White Noise Generator sampleValue = (Gain * NextRandomTwo()); break; case SignalGeneratorType.Pink: // Pink Noise Generator double white = NextRandomTwo(); pinkNoiseBuffer[0] = 0.99886 * pinkNoiseBuffer[0] + white * 0.0555179; pinkNoiseBuffer[1] = 0.99332 * pinkNoiseBuffer[1] + white * 0.0750759; pinkNoiseBuffer[2] = 0.96900 * pinkNoiseBuffer[2] + white * 0.1538520; pinkNoiseBuffer[3] = 0.86650 * pinkNoiseBuffer[3] + white * 0.3104856; pinkNoiseBuffer[4] = 0.55000 * pinkNoiseBuffer[4] + white * 0.5329522; pinkNoiseBuffer[5] = -0.7616 * pinkNoiseBuffer[5] - white * 0.0168980; double pink = pinkNoiseBuffer[0] + pinkNoiseBuffer[1] + pinkNoiseBuffer[2] + pinkNoiseBuffer[3] + pinkNoiseBuffer[4] + pinkNoiseBuffer[5] + pinkNoiseBuffer[6] + white * 0.5362; pinkNoiseBuffer[6] = white * 0.115926; sampleValue = (Gain * (pink / 5)); break; case SignalGeneratorType.Sweep: // Sweep Generator double f = Math.Exp(FrequencyLog + (nSample * (FrequencyEndLog - FrequencyLog)) / (SweepLengthSecs * waveFormat.SampleRate)); multiple = TwoPi * f / waveFormat.SampleRate; phi += multiple; sampleValue = Gain * (Math.Sin(phi)); nSample++; if (nSample > SweepLengthSecs * waveFormat.SampleRate) { nSample = 0; phi = 0; } break; default: sampleValue = 0.0; break; } // Phase Reverse Per Channel for (int i = 0; i < waveFormat.Channels; i++) { if (PhaseReverse[i]) { buffer[outIndex++] = (float)-sampleValue; } else { buffer[outIndex++] = (float)sampleValue; } } accumulator += increment; } bufferCount = 0; return(count); }