private ushort GetUShortUnsignedFloatSmallerThan512(float floatVal) { if (floatVal < 0 || floatVal > 512) { throw new FormatException($"Error, can only represent values in the following ranges: 0 <= x <= 512, value given: {floatVal}"); } ushort ushortVal = 0; for (sbyte bitIndex = 15; bitIndex >= 0; bitIndex--) { float takeAway = Mathf.Pow(2f, bitIndex - 7); float newVal = floatVal - takeAway; if (newVal < 0) { continue; } ushort bitValue = (ushort)Mathf.Pow(2f, bitIndex); ushortVal += bitValue; floatVal = newVal; } return(ushortVal); }
public static float InOut(float k) { if ((k *= 2f) < 1f) { return(-0.5f * Mathf.Pow(2f, 10f * (k -= 1f)) * Mathf.Sin((k - 0.1f) * (2f * Mathf.PI) / 0.4f)); } return(Mathf.Pow(2f, -10f * (k -= 1f)) * Mathf.Sin((k - 0.1f) * (2f * Mathf.PI) / 0.4f) * 0.5f + 1f); }
public static float Root3(float t) { const float pow = 1f / 3f; float sign = Mathf.Sign(t); float root = Mathf.Pow(sign * t, pow); return(sign * root); }
/// <summary> /// Modeled after the piecewise exponentially-damped sine wave: /// y = (1/2)*sin(13pi/2*(2*x))*Math.Pow(2, 10 * ((2*x) - 1)) ; [0,0.5) /// y = (1/2)*(sin(-13pi/2*((2x-1)+1))*Math.Pow(2,-10(2*x-1)) + 2) ; [0.5, 1] /// </summary> static public float ElasticEaseInOut(float p) { if (p < 0.5f) { return(0.5f * Math.Sin(13.0f * HALFPI * (2.0f * p)) * Math.Pow(2.0f, 10.0f * ((2.0f * p) - 1.0f))); } else { return(0.5f * (Math.Sin(-13.0f * HALFPI * ((2.0f * p - 1.0f) + 1.0f)) * Math.Pow(2.0f, -10.0f * (2.0f * p - 1)) + 2.0f)); } }
/// <summary> /// Modeled after the piecewise exponentially-damped sine wave: /// y = (1/2)*sin(13pi/2*(2*x))*Math.Pow(2, 10 * ((2*x) - 1)) ; [0,0.5) /// y = (1/2)*(sin(-13pi/2*((2x-1)+1))*Math.Pow(2,-10(2*x-1)) + 2) ; [0.5, 1] /// </summary> static public float ElasticEaseInOut(float p) { if (p < 0.5f) { return(0.5f * Math.Sin(13 * HALFPI * (2 * p)) * Math.Pow(2, 10 * ((2 * p) - 1))); } else { return(0.5f * (Math.Sin(-13 * HALFPI * ((2 * p - 1) + 1)) * Math.Pow(2, -10 * (2 * p - 1)) + 2)); } }
public static float In(float k) { if (k == 0) { return(0); } if (k == 1) { return(1); } return(-Mathf.Pow(2f, 10f * (k -= 1f)) * Mathf.Sin((k - 0.1f) * (2f * Mathf.PI) / 0.4f)); }
public static float Out(float k) { if (k == 0) { return(0); } if (k == 1) { return(1); } return(Mathf.Pow(2f, -10f * k) * Mathf.Sin((k - 0.1f) * (2f * Mathf.PI) / 0.4f) + 1f); }
public static float Expo_EaseIn(float a, float b, float t, int power = 1) { if (t > 1.0F) { t = 1.0F; } if (t < 0.0F) { t = 0.0F; } float x = (float)Math.Pow(2, power * 10 * (t - 1.0F)); // F(x) = 2^(10 * (x-1)) for x in (0,1) return(a + x * (b - a)); }
/// <summary> /// Evaluates this value. /// </summary> public float Evaluate(float stat, float?min = null, float?max = null) { float result = Offset + (Scale * Mathf.Pow(stat, Exp)); if (min.HasValue && result < min.Value) { result = min.Value; } if (max.HasValue && result > max.Value) { result = max.Value; } return(result); }
public static float Expo_EaseOut(float a, float b, float t, int power = 1) { if (t > 1.0F) { t = 1.0F; } if (t < 0.0F) { t = 0.0F; } float x = -(float)Math.Pow(2, power * -10 * t) + 1.0F; // F(x) = -2^(-10x) + 1 for x in (0,1) return(a + x * (b - a)); }
/// <summary> /// Modeled after the piecewise exponential /// y = (1/2)2^(10(2x - 1)) ; [0,0.5) /// y = -(1/2)*2^(-10(2x - 1))) + 1 ; [0.5,1] /// </summary> static public float ExponentialEaseInOut(float p) { if (p == 0.0 || p == 1.0) { return(p); } if (p < 0.5f) { return(0.5f * Math.Pow(2, (20 * p) - 10)); } else { return(-0.5f * Math.Pow(2, (-20 * p) + 10) + 1); } }
public static float InOut(float k) { if (k == 0f) { return(0f); } if (k == 1f) { return(1f); } if ((k *= 2f) < 1f) { return(0.5f * Mathf.Pow(1024f, k - 1f)); } return(0.5f * (-Mathf.Pow(2f, -10f * (k - 1f)) + 2f)); }
private static void GetAbsFloatSmallerThan1From1Byte(byte byteVal, ref float floatVal, sbyte maxBitIndex) { for (sbyte bitCount = maxBitIndex; bitCount >= 0; bitCount--) { byte bitValue = (byte)Mathf.Pow(2, bitCount); short newByteVal = (short)(byteVal - bitValue); if (newByteVal < 0) { continue; } float addVal = Mathf.Pow(2f, bitCount - (maxBitIndex + 1)); floatVal += addVal; byteVal = (byte)newByteVal; } }
private float GetUnsignedFloatSmallerThan512FromUShort(ushort ushortVal) { float floatVal = 0; for (sbyte bitIndex = 15; bitIndex >= 0; bitIndex--) { ushort takeAway = (ushort)Mathf.Pow(2f, bitIndex); int newUShortVal = ushortVal - takeAway; if (newUShortVal < 0) { continue; } float addVal = Mathf.Pow(2f, bitIndex - 7); floatVal += addVal; ushortVal = (ushort)newUShortVal; } return(floatVal); }
private static void GetByteFromAbsFloatSmallerThan1(float valAbs, ref byte byteVal, sbyte maxBitIndex) { for (sbyte bitCount = maxBitIndex; bitCount >= 0; bitCount--) { float takeAway = Mathf.Pow(2f, bitCount - (maxBitIndex + 1)); float newVal = valAbs - takeAway; if (newVal < 0) { continue; } byte bitValue = (byte)Mathf.Pow(2, bitCount); byteVal += bitValue; //if (newVal == 0) // break; valAbs = newVal; } }
public static float Quad_EaseOut(float a, float b, float t, int power = 1) { if (t > 1.0F) { t = 1.0F; } if (t < 0.0F) { t = 0.0F; } float x = .0F; if (power <= 1) { x = 1.0F - (1.0F + t * t - 2.0F * t); // F(x) = 1-(1-x)^2 for x in (0,1) } else { x = 1.0F - (float)(Math.Pow(1.0F - t, power)); } return(a + x * (b - a)); }
public static float Expo_EaseInOut(float a, float b, float t, int power = 1) { if (t > 1.0F) { t = 1.0F; } if (t < 0.0F) { t = 0.0F; } float x = t; if (t <= 0.5f) { x = 0.5F * (float)Math.Pow(2, power * 10 * (t * 2 - 1.0F)); // x <= 0,5: F(x) = 0.5*(2^(10 * (x*2-1)) in (0, 0.5) } else { x = 0.5F * ((float)-Math.Pow(2, power * -10 * (t * 2 - 1.0F)) + 2.0F); // x > 0,5: F(x) = 0.5*(-2^(-10 * (x*2-1))+2) in (0.5, 1) } return(a + x * (b - a)); }
/// <summary> /// Modeled after the damped sine wave y = sin(13pi/2*x)*Math.Pow(2, 10 * (x - 1)) /// </summary> static public float ElasticEaseIn(float p) { return(Math.Sin(13.0f * HALFPI * p) * Math.Pow(2.0f, 10.0f * (p - 1.0f))); }
/// <summary> /// Modeled after the damped sine wave y = sin(13pi/2*x)*Math.Pow(2, 10 * (x - 1)) /// </summary> static public float ElasticEaseIn(float p) { return(Math.Sin(13 * HALFPI * p) * Math.Pow(2, 10 * (p - 1))); }
/// <summary> /// Modeled after the exponential function y = 2^(10(x - 1)) /// </summary> static public float ExponentialEaseIn(float p) { return((p == 0.0f) ? p : Math.Pow(2, 10 * (p - 1))); }
/// <summary> /// Modeled after the exponential function y = -2^(-10x) + 1 /// </summary> static public float ExponentialEaseOut(float p) { return((p == 1.0f) ? p : 1 - Math.Pow(2, -10 * p)); }
private ItemEffect GenerateEffect(Item item) { Random rnd = new Random(); float itemPriceMax = 2 * PriceMax - item.Class.Price; float manaMax = item.Class.Material.MagicVolume * item.Class.Class.MagicVolume - item.ManaUsage; // note: this will not work correctly if SlotsWarrior or SlotsMage values for a slot are not sorted by ascending order. // parameters that appear first will "override" parameters with the same weight appearing later. int lastValue; Templates.TplModifier lastModifier = TemplateLoader.Templates.Modifiers[TemplateLoader.Templates.Modifiers.Count - 1]; if ((item.Class.Option.SuitableFor & 1) != 0) { lastValue = lastModifier.SlotsFighter[item.Class.Option.Slot - 1]; } else { lastValue = lastModifier.SlotsMage[item.Class.Option.Slot - 1]; } int randomValue = rnd.Next(0, lastValue) + 1; Templates.TplModifier matchingModifier = null; if (item.Class.Option.SuitableFor == 2 && item.Class.Option.Slot == 1) { matchingModifier = TemplateLoader.Templates.Modifiers[(int)ItemEffect.Effects.CastSpell]; } else { for (int i = 1; i < TemplateLoader.Templates.Modifiers.Count; i++) { Templates.TplModifier prevModifier = TemplateLoader.Templates.Modifiers[i - 1]; Templates.TplModifier modifier = TemplateLoader.Templates.Modifiers[i]; int prevValue; int value; if ((item.Class.Option.SuitableFor & 1) != 0) { prevValue = prevModifier.SlotsFighter[item.Class.Option.Slot - 1]; value = modifier.SlotsFighter[item.Class.Option.Slot - 1]; } else { prevValue = prevModifier.SlotsMage[item.Class.Option.Slot - 1]; value = modifier.SlotsMage[item.Class.Option.Slot - 1]; } if (prevValue < randomValue && randomValue <= value) { matchingModifier = modifier; break; } } } if (matchingModifier == null) { // parameter not found. weird, but happens. return(null); } if ((matchingModifier.UsableBy & item.Class.Option.SuitableFor) == 0) { // parameter for class not found in the item. return(null); } // parameter found. calculate max possible power ItemEffect effect = new ItemEffect(); effect.Type1 = (ItemEffect.Effects)matchingModifier.Index; float maxPower; float absoluteMax = manaMax / matchingModifier.ManaCost; if (matchingModifier.Index == (int)ItemEffect.Effects.CastSpell) { // select spell to cast. // if for fighter, choose between fighter-specific spells. // if for mage, choose between mage-specific spells. Spell.Spells[] spells; if ((item.Class.Option.SuitableFor & 1) != 0) { spells = new Spell.Spells[] { Spell.Spells.Stone_Curse, Spell.Spells.Drain_Life } } ; else { spells = new Spell.Spells[] { Spell.Spells.Fire_Arrow, Spell.Spells.Lightning, Spell.Spells.Prismatic_Spray, Spell.Spells.Stone_Curse, Spell.Spells.Drain_Life, Spell.Spells.Ice_Missile, Spell.Spells.Diamond_Dust } }; // choose random spell Spell.Spells spell = spells[rnd.Next(0, spells.Length)]; effect.Value1 = (int)spell; // calculate max power Templates.TplSpell spellTemplate = TemplateLoader.Templates.Spells[effect.Value1]; maxPower = Mathf.Log(itemPriceMax / (spellTemplate.ScrollCost * 10f)) / Mathf.Log(2); if (!float.IsNaN(maxPower) && maxPower > 0) { maxPower = (Mathf.Pow(1.2f, maxPower) - 1) * 30; } else { return(null); } maxPower = Mathf.Min(maxPower, absoluteMax); maxPower = Mathf.Min(maxPower, 100); } else { maxPower = Mathf.Log(itemPriceMax / (manaMax * 50) - 1) / Mathf.Log(1.5f) * 70f / matchingModifier.ManaCost; if (float.IsNaN(maxPower)) { return(null); } maxPower = Mathf.Min(maxPower, absoluteMax); maxPower = Mathf.Min(maxPower, matchingModifier.AffectMax); if (maxPower < matchingModifier.AffectMin) { return(null); } } if (maxPower <= 1) { // either some limit hit, or something else return(null); } // max parameter power found. randomize values switch (effect.Type1) { case ItemEffect.Effects.CastSpell: effect.Value2 = rnd.Next(1, (int)maxPower + 1); break; case ItemEffect.Effects.DamageFire: case ItemEffect.Effects.DamageWater: case ItemEffect.Effects.DamageAir: case ItemEffect.Effects.DamageEarth: case ItemEffect.Effects.DamageAstral: effect.Value1 = rnd.Next(1, (int)maxPower + 1); effect.Value2 = rnd.Next(1, (int)(maxPower / 2) + 1); break; default: effect.Value1 = (int)Mathf.Max(matchingModifier.AffectMin, rnd.Next(1, (int)maxPower + 1)); break; } return(effect); }
public List <Vector3> SmoothOffsetSimple(List <Vector3> path) { if (path.Count <= 2 || iterations <= 0) { return(path); } if (iterations > 12) { Debug.LogWarning("A very high iteration count was passed, won't let this one through"); return(path); } int maxLength = (path.Count - 2) * (int)Mathf.Pow(2, iterations) + 2; List <Vector3> subdivided = ListPool <Vector3> .Claim(maxLength); List <Vector3> subdivided2 = ListPool <Vector3> .Claim(maxLength); for (int i = 0; i < maxLength; i++) { subdivided.Add(Vector3.zero); subdivided2.Add(Vector3.zero); } for (int i = 0; i < path.Count; i++) { subdivided[i] = path[i]; } for (int iteration = 0; iteration < iterations; iteration++) { int currentPathLength = (path.Count - 2) * (int)Mathf.Pow(2, iteration) + 2; //Switch the arrays List <Vector3> tmp = subdivided; subdivided = subdivided2; subdivided2 = tmp; const float nextMultiplier = 1F; for (int i = 0; i < currentPathLength - 1; i++) { Vector3 current = subdivided2[i]; Vector3 next = subdivided2[i + 1]; Vector3 normal = Vector3.Cross(next - current, Vector3.up); normal = normal.normalized; bool firstRight = false; bool secondRight = false; bool setFirst = false; bool setSecond = false; if (i != 0 && !VectorMath.IsColinearXZ(current, next, subdivided2[i - 1])) { setFirst = true; firstRight = VectorMath.RightOrColinearXZ(current, next, subdivided2[i - 1]); } if (i < currentPathLength - 1 && !VectorMath.IsColinearXZ(current, next, subdivided2[i + 2])) { setSecond = true; secondRight = VectorMath.RightOrColinearXZ(current, next, subdivided2[i + 2]); } if (setFirst) { subdivided[i * 2] = current + (firstRight ? normal * offset * nextMultiplier : -normal * offset * nextMultiplier); } else { subdivided[i * 2] = current; } if (setSecond) { subdivided[i * 2 + 1] = next + (secondRight ? normal * offset * nextMultiplier : -normal * offset * nextMultiplier); } else { subdivided[i * 2 + 1] = next; } } subdivided[(path.Count - 2) * (int)Mathf.Pow(2, iteration + 1) + 2 - 1] = subdivided2[currentPathLength - 1]; } ListPool <Vector3> .Release(ref subdivided2); return(subdivided); }
public static float Power(float value, float power) { return((float)Math.Pow(value, power)); }
public static float Out(float k) { return(k == 1f ? 1f : 1f - Mathf.Pow(2f, -10f * k)); }
/// <summary> /// Modeled after the damped sine wave y = sin(-13pi/2*(x + 1))*Math.Pow(2, -10x) + 1 /// </summary> static public float ElasticEaseOut(float p) { return(Math.Sin(-13 * HALFPI * (p + 1)) * Math.Pow(2, -10 * p) + 1); }
/// <summary> /// Modeled after the damped sine wave y = sin(-13pi/2*(x + 1))*Math.Pow(2, -10x) + 1 /// </summary> static public float ElasticEaseOut(float p) { return(Math.Sin(-13.0f * HALFPI * (p + 1.0f)) * Math.Pow(2.0f, -10.0f * p) + 1.0f); }
public static float In(float k) { return(k == 0f ? 0f : Mathf.Pow(1024f, k - 1f)); }