private static uint Round(uint seed, uint input) { seed += input * PRIME32_2; seed = MathR.RotateLeft(seed, 13); seed += PRIME32_1; return(seed); }
public (Vec3 color, Ray ray) Scatter(Ray rIn, HitRecord hitRec) { var col = new Vec3(1, 1, 1); var nOverNP = hitRec.IsFrontFace ? (1 / RefIndex) : RefIndex; var unitDirection = rIn.Direction.Normalize(); var cosAlpha = Math.Min(MathR.Dot(unitDirection * -1, hitRec.N), 1.0F); var sinAlpha = MathF.Sqrt(1.0F - (cosAlpha * cosAlpha)); // TIR if (nOverNP * sinAlpha > 1) { var reflect = MathR.Reflect(unitDirection, hitRec.N); var scatterRay = new Ray(hitRec.P, reflect); return(col, scatterRay); } //Reflection var reflectionProp = MathR.Schlick(cosAlpha, RefIndex); if (Rand.Rand01() < reflectionProp) { var reflect = MathR.Reflect(unitDirection, hitRec.N); var scatterRay = new Ray(hitRec.P, reflect); return(col, scatterRay); } //Refraction var refract = MathR.Refract(unitDirection, hitRec.N, nOverNP); var scatterRay2 = new Ray(hitRec.P, refract); return(col, scatterRay2); }
public void SmallerThanOneException(int n) { void action() => MathR.NthPrime(n); Assert.ThrowsException <ArgumentOutOfRangeException>(action); AssertExtensions.ThrowsExceptionMessage <ArgumentOutOfRangeException>(action, "N can't be smaller than one. (Parameter 'n')"); }
public (Vec3 color, Ray ray) Scatter(Ray rIn, HitRecord hitRec) { var scatteredDirection = hitRec.N + MathR.RandomUnitVector(); var scatterRay = new Ray(hitRec.P, scatteredDirection); return(Color, scatterRay); }
float Alpha(float height) { float minHeight = verticalCorrectionSlider.minValue; float maxHeight = verticalCorrectionSlider.maxValue; return(MathR.Map(height, minHeight, maxHeight, 0, 1)); }
// Unity function void LateUpdate() { if (target && spatialIndicator) { spatialIndicator.position = target.position; } if (!shouldHide && target && overlayIndicator) { var point = Camera.main.WorldToViewportPoint(target.position); overlayIndicator.gameObject.SetActive(true); var z = overlayIndicator.localEulerAngles.z; if (point.z > 0 && Mathf.Abs(point.x) < 1) { overlayIndicator.gameObject.SetActive(false); } else if (point.z > 0) { if (point.x > 0 && point.x < 10) { z = MathR.Map(point.x, 3f, 10f, -45f, -90f); } else if (point.x < 0 && point.x > -10) { z = MathR.Map(point.x, -3f, -10f, 45f, 90f); } } else if (point.z < 0 && point.x > -10 && point.x < 10) { z = MathR.Map(point.x, -10f, 10f, 90f, -90f) + 180; } var eu = new Vector3(0, 0, z); overlayIndicator.localEulerAngles = eu; } }
void Update() { if (!playing) { return; } time += Time.deltaTime; if (time.OutOfBounds(0, maxTime)) { playing = false; return; } float length = MathR.Lerp( min: (direction) ? 0 : maxLength, max: (direction) ? maxLength : 0, time: time / maxTime, type: MathR.LerpType.LINEAR); if (length.OutOfBounds(0, maxLength)) { playing = false; return; } UpdateElements(length); }
public static IEnumerator Fade(this Renderer self, float start, float end, float time) { foreach (var value in MathR.LerpE(start, end, time)) { self.SetAlpha(value); yield return(null); } }
public static IEnumerable Fade(this MediaPlayerCtrl self, float start, float end, float time, MathR.LerpType type) { foreach (var value in MathR.LerpE(start, end, time, type)) { self.ForEachRenderer(r => r.SetAlpha(value)); yield return(null); } }
public void SetPosition(float normalized) { var topPosN = MathR.Map(normalized, 0, 1, TOP_MIN, TOP_MAX); var btmPosN = MathR.Map(normalized, 0, 1, BTM_MIN, BTM_MAX); topPanel.SetNormalizedLocalPosition(topPosN.WithX(.5f), screen); bottomPanel.SetNormalizedLocalPosition(btmPosN.WithX(.5f), screen); position = position_last = normalized; }
public float Evaluate(float x, float y, float z) { int xi0 = ((int)Floor(x)) & TABLE_SIZE_MASK; int yi0 = ((int)Floor(y)) & TABLE_SIZE_MASK; int zi0 = ((int)Floor(z)) & TABLE_SIZE_MASK; int xi1 = (xi0 + 1) & TABLE_SIZE_MASK; int yi1 = (yi0 + 1) & TABLE_SIZE_MASK; int zi1 = (zi0 + 1) & TABLE_SIZE_MASK; float tx = x - (int)Floor(x); float ty = y - (int)Floor(y); float tz = z - (int)Floor(z); float u = MathR.Smoothstep(tx); float v = MathR.Smoothstep(ty); float w = MathR.Smoothstep(tz); // Edge Vectors Vector3 c000 = Gradient[HashV3(xi0, yi0, zi0)]; Vector3 c100 = Gradient[HashV3(xi1, yi0, zi0)]; Vector3 c010 = Gradient[HashV3(xi0, yi1, zi0)]; Vector3 c110 = Gradient[HashV3(xi1, yi1, zi0)]; Vector3 c001 = Gradient[HashV3(xi0, yi0, zi1)]; Vector3 c101 = Gradient[HashV3(xi1, yi0, zi1)]; Vector3 c011 = Gradient[HashV3(xi0, yi1, zi1)]; Vector3 c111 = Gradient[HashV3(xi1, yi1, zi1)]; float x0 = tx, x1 = tx - 1; float y0 = ty, y1 = ty - 1; float z0 = tz, z1 = tz - 1; // Point Vectors Vector3 p000 = new Vector3(x0, y0, z0); Vector3 p100 = new Vector3(x1, y0, z0); Vector3 p010 = new Vector3(x0, y1, z0); Vector3 p110 = new Vector3(x1, y1, z0); Vector3 p001 = new Vector3(x0, y0, z1); Vector3 p101 = new Vector3(x1, y0, z1); Vector3 p011 = new Vector3(x0, y1, z1); Vector3 p111 = new Vector3(x1, y1, z1); // Lerping float a = MathR.Lerp(Vector3.Dot(c000, p000), Vector3.Dot(c100, p100), u); float b = MathR.Lerp(Vector3.Dot(c010, p010), Vector3.Dot(c110, p110), u); float c = MathR.Lerp(Vector3.Dot(c001, p001), Vector3.Dot(c101, p101), u); float d = MathR.Lerp(Vector3.Dot(c011, p011), Vector3.Dot(c111, p111), u); float e = MathR.Lerp(a, b, v); float f = MathR.Lerp(c, d, v); return(MathR.Lerp(e, f, w)); }
public (Vec3 color, Ray ray) Scatter(Ray rIn, HitRecord hitRec) { var reflect = rIn.Direction.Reflect(hitRec.N); var scatteredDirection = reflect + (MathR.RandomUnitVector() * Fuzz); if (scatteredDirection.Dot(hitRec.N) > 0) { var scatterRay = new Ray(hitRec.P, scatteredDirection); return(Color, scatterRay); } return(default);
//Shifts from top to bottom and swaps them. IEnumerator _ShiftPanels(float time) { foreach (var pos in MathR.LerpE(0f, 1f, time, shiftType)) { if (pos < position) { continue; //starts from the current location } SetPosition(pos); yield return(null); } SwapPanels(); }
IEnumerator Lerp(bool blurIn) { float itrMin = (blurIn) ? 0 : maxIteration; float itrMax = (blurIn) ? maxIteration : 0; float sprMin = (blurIn) ? 0 : maxSpread; float sprMax = (blurIn) ? maxSpread : 0; var itrEnm = MathR.LerpE(itrMin, itrMax, lerpTime, lerpType).GetEnumerator(); var sprEnm = MathR.LerpE(sprMin, sprMax, lerpTime, lerpType).GetEnumerator(); while (itrEnm.MoveNext() | sprEnm.MoveNext()) { iterations = (int)itrEnm.Current; blurSpread = sprEnm.Current; yield return(null); } }
private IEnumerator Lerp(bool win) { m_lerp = 0.0f; while (m_lerp < 1.0f) { m_lerp += Time.deltaTime * 15.0f; transform.localScale = MathR.Lerp(Constantes.VECTOR_3_ZERO, m_scale, m_lerp, INTERPOLATION.ExponentialEaseIn); yield return(null); } if (!win) { Invoke("Deactive", 0.25f); } }
private IEnumerator ActivePillar() { m_lerp = 0.0f; m_isActive = true; m_currentCharacter.Invoke("ActiveCuspe", 0.1f); while (m_lerp < 1.0f) { m_lerp += Time.deltaTime * m_upSpeed; transform.localPosition = MathR.Lerp(m_normalPos, m_activePos, m_lerp, m_upInterpolation); yield return(null); } m_currentCharacter = null; m_isChanging = false; }
private IEnumerator MoveTo() { while (m_lerp < 1.0f) { m_lerp += Time.deltaTime; m_position = transform.position; m_endPosition = m_winner.transform.position; m_endPosition.z = m_position.z; transform.position = MathR.Lerp(m_position, m_endPosition, m_lerp, INTERPOLATION.Linear); mainCamera.orthographicSize = Mathf.Lerp(5.0f, 2.0f, m_lerp); yield return(null); } m_winner.animationController.PlayByType(ANIMATION_TYPE.IDLE); m_winner.PlayBallon(true); Invoke("Load", 2.0f); }
private IEnumerator DeactivePillar() { if (m_sword != null) { m_sword.SetState(new Fall()); m_sword = null; } m_lerp = 0.0f; m_currentCharacter.Invoke("ActiveCuspe", 0.1f); while (m_lerp < 1.0f) { m_lerp += Time.deltaTime * m_downSpeed; transform.localPosition = MathR.Lerp(m_activePos, m_normalPos, m_lerp, m_downInterpolation); yield return(null); } m_isActive = false; m_isChanging = false; m_currentCharacter = null; }
public HitRecord(float t, Vec3 p, Vec3 n, Ray r, IMaterial material) : this() { (T, P, R, N, Material) = (t, p, r, n, material); IsFrontFace = MathR.Dot(r.Direction, N) < 0; N = IsFrontFace ? n : n * -1; }
public BigInteger Fibonacci() => MathR.Fibonacci(N);
float NormalizeFromLocalPosition(float posL) { return(MathR.Map(posL, MinLocalPosition(), MaxLocalPosition(), 0, 1)); }
float DenormalizeToLocalPosition(float posN) { return(MathR.Map(posN, 0, 1, MinLocalPosition(), MaxLocalPosition())); }
float NormalizeFromValue(float val) { return(MathR.Map(val, minValue, maxValue, 0, 1)); }
float DenormalizeToValue(float posN) { return(MathR.Map(posN, 0, 1, minValue, maxValue)); }
public static Vector2 Lerp(Vector2 a, Vector2 b, float t) { return(new Vector2(MathR.Lerp(a.X, b.X, t), MathR.Lerp(a.Y, b.Y, t))); }
private static void AssertEquals(int n, long prime) => Assert.AreEqual(prime, MathR.NthPrime(n));
///<summary> /// Linearly interpolates between 2 vectors ///</summary> public static Vector3 Lerp(Vector3 a0, Vector3 a1, float t) { return(new Vector3(MathR.Lerp(a0.X, a1.X, t), MathR.Lerp(a0.Y, a1.Y, t), MathR.Lerp(a0.Z, a1.Z, t))); }
IEnumerable <float> IterateScales() { return(MathR.LerpE(minSize, maxSize, lerpTime, lerpType)); }
public BigInteger NthPrime() => MathR.NthPrime(N);
public BigInteger Factorial() => MathR.Factorial(N);