private void InitializeChunkGenerators(uint chunkGeneratorCount) { _chunkGeneratorCount = chunkGeneratorCount; _nextChunkGeneratorIndex = 0; _chunkGenerators = new IChunkGenerator[_chunkGeneratorCount]; var seed = new Seed(CryptoRand.NextInt64()); for (var i = 0; i < _chunkGeneratorCount; ++i) { _chunkGenerators[i] = _chunkFactory.CreateChunkGenerator(seed); } }
void Fire() { AffectedProjectile newInst; for (int i = 0; i < instances; i++) { newInst = affectedProj.Clone() as AffectedProjectile; Vector3 dir = Vector3.Lerp(initialDirection1, initialDirection2, (float)CryptoRand.Range()).normalized; newInst.physicsTransform.AddForce(dir * initialVelocity, ForceMode.VelocityChange, Time.deltaTime); ProjectilePool.instance.FireProjectile(newInst); newInst.Initial(); //{TODO} This is dirty } }
public static IEnumerable <TSource> Shuffle <TSource>( this IEnumerable <TSource> enumerable ) { //TSource[] newArray = new TSource[enumerable.Count()]; for (int i = 0; i < enumerable.Count(); i++) { enumerable = enumerable.Swap(i, (int)CryptoRand.Range(0.0, (double)enumerable.Count())); } //for (int i = 0; i < newArray.Length; i++) // newArray[i] = enumerable.Where(n => !newArray.Contains(n)).Pick(); //Kinda slow? return(enumerable); }
public Seed() : this(CryptoRand.NextInt64()) { }
/// <summary> /// Randomly picks an element from an enumerable /// </summary> /// <typeparam name="TSource"></typeparam> /// <param name="enumerable"></param> /// <returns></returns> public static TSource Pick <TSource>( this IEnumerable <TSource> enumerable ) { return(CryptoRand.Pick(enumerable.ToArray())); }
//{TODO} Damn this method is long... protected virtual void Penetrate(TerminalBallisticsData penData, float stoppingDist) { ProjectileData projData = penData.projectile.projectileData; VirtualPhysicsTransform physicsTransform = penData.projectile.physicsTransform; float targetDensity = 1000.0f; //{TODO} Hook this up //343.0f - Temporary hardcoded value - 1 mach in air ~= 343 m/s ThicknessData objectThickness = ProjectileHelper.FindThickness( physicsTransform.PrevPosition, physicsTransform.Velocity.normalized, (rCH) => rCH.collider.gameObject == penData.hitInfo.collider.gameObject); //Only colliders on this object Debug.Log($"Thickness: {objectThickness.thickness}m"); //{TODO} Add some check to see if the object thickness was even found //If the projectile stops mid-object, de-activate it if (stoppingDist <= objectThickness.thickness) { penData.projectile.Active = false; Debug.Log($"Stopped after penetrating {stoppingDist}m"); return; } //Otherwise, see how fast we come out the other side physicsTransform.Position = objectThickness.exitPosition; //tex: //$$ v=\sqrt{-\frac{ACpx^3}{m}+u^2}$$ physicsTransform.VelocityMagnitude = Mathf.Sqrt( - ( ( projData.CrossSectionalArea * projData.GetDragCoefficient(physicsTransform.Velocity.magnitude / 343.0f) * targetDensity * objectThickness.thickness * objectThickness.thickness * objectThickness.thickness ) / projData.bulletMass ) + (physicsTransform.VelocityMagnitude * physicsTransform.VelocityMagnitude) ); //Modify the exit direction depending on the projectile velocity //{TODO} Rewrite! float range = 0.25f; physicsTransform.VelocityDirection += Vector3.Lerp( new Vector3( CryptoRand.Range(-range, range), CryptoRand.Range(-range, range), CryptoRand.Range(-range, range)), Vector3.zero, Mathf.Clamp(1 / physicsTransform.VelocityMagnitude, 0, 1) ); Debug.Log($"Stopping distance: {stoppingDist}"); Debug.Log($"Fully penetrated with an exit velocity of {physicsTransform.Velocity.magnitude}m/s"); }
public static float Range(this Vector2 v) { return(CryptoRand.Range(v.x, v.y)); }