private void Start() { // Initialize our rng _random = new Random(Environment.TickCount + SeedAddition); if (SpawnInitial) { // Spawn in a bunch of instances initially var retryCount = 0; while (_instances.Count < Count) { var pos = _random.NextVector2D(TargetCamera.position.Xyn(0), Distance); // Make sure the instance can be spawned here if (!IsValidSpawnPosition(pos)) { retryCount++; if (retryCount > 10) { Debug.LogWarning("Had to early-bail on spawning."); break; } continue; } // Actually spawn the instance var obj = Instantiate(Prefab); obj.transform.position = pos; obj.transform.parent = gameObject.transform; _instances.Add(obj); } } }
public void Transform1D() { // Transform forward and inverse and compare with initial values. var random = new Random(1234567); var s = new Vector2D[16]; var t = new Vector2D[16]; for (int i = 0; i < s.Length; i++) { s[i] = random.NextVector2D(-10, 10); t[i] = s[i]; } FastFourierTransformD.Transform1D(t, true); FastFourierTransformD.Transform1D(t, false); for (int i = 0; i < s.Length; i++) Assert.IsTrue(Vector2D.AreNumericallyEqual(s[i], t[i])); }
public void Transform1DAs2DColumn() { // Result of 2D with one row/column must be the same as 1D. var fft = new FastFourierTransformD(16); var random = new Random(1234567); var s1D = new Vector2D[16]; var s2D = new Vector2D[16, 1]; for (int i = 0; i < s1D.Length; i++) { s1D[i] = random.NextVector2D(-10, 10); s2D[i, 0] = s1D[i]; } FastFourierTransformD.Transform1D(s1D, true); fft.Transform2D(s2D, true); for (int i = 0; i < s1D.Length; i++) Assert.AreEqual(s1D[i], s2D[i, 0]); }
private void Update() { // Trim any unneeded instances for (var i = 0; i < _instances.Count; i++) { // Check if we can keep this instance var instance = _instances[i]; if (instance != null && InstanceIsInRange(instance)) { continue; } // We can't, remove it Destroy(_instances[i]); _instances.RemoveAt(i); i--; } // Check how many times we're allowed to spawn this frame var allowedSpawns = 0; if (Math.Abs(SpawnDelay) > 0.01f) { _spawnDelayTimer += Time.deltaTime; while (_spawnDelayTimer >= SpawnDelay) { _spawnDelayTimer -= SpawnDelay; allowedSpawns++; } } else { allowedSpawns = 9999; } // Add new instances if we have to var retryCount = 0; while (_instances.Count < Count && allowedSpawns > 0) { allowedSpawns -= 1; // Make sure the cloud's at one of the edges var otherPos = TargetCamera.position; var pos = _random.NextVector2D(otherPos.Xyn(0), Distance); var axis = _random.Next(2); pos[axis] = _random.Next(2) == 1 ? otherPos[axis] + Distance : otherPos[axis] - Distance; // Make sure the instance can be spawned here if (!IsValidSpawnPosition(pos)) { retryCount++; if (retryCount > 10) { Debug.LogWarning("Had to early-bail on spawning."); break; } continue; } // Create and add the cloud var obj = Instantiate(Prefab); obj.transform.position = pos; obj.transform.parent = gameObject.transform; _instances.Add(obj); } }
public void Transform2D() { // Transform forward and inverse and compare with initial values. var random = new Random(1234567); var s = new Vector2D[16, 8]; var t = new Vector2D[16, 8]; for (int i = 0; i < s.GetLength(0); i++) { for (int j = 0; j < s.GetLength(1); j++) { s[i, j] = random.NextVector2D(-10, 10); t[i, j] = s[i, j]; } } var fft = new FastFourierTransformD(16); fft.Transform2D(t, true); Assert.IsFalse(Vector2D.AreNumericallyEqual(s[0, 0], t[0, 0])); fft.Transform2D(t, false); for (int i = 0; i < s.GetLength(0); i++) for (int j = 0; j < s.GetLength(1); j++) Assert.IsTrue(Vector2D.AreNumericallyEqual(s[i, j], t[i, j])); }