public static void Cleanup() { var randomizersList = new Dictionary <Type, IRandomizeble>(); randomizersList[typeof(decimal)] = new DecimalRandom(); randomizersList[typeof(string)] = new StringRandom(); randomizersList[typeof(char)] = new CharRandom(); randomizersList[typeof(int)] = new Int32Random(); randomizersList[typeof(long)] = new Int64Random(); randomizersList[typeof(bool)] = new BoolRandom(); randomizersList[typeof(byte)] = new ByteRandom(); randomizersList[typeof(sbyte)] = new SByteRandom(); randomizersList[typeof(float)] = new FloatRandom(); randomizersList[typeof(double)] = new DoubleRandom(); randomizersList[typeof(short)] = new Int16Random(); randomizersList[typeof(uint)] = new UInt32Random(); randomizersList[typeof(ushort)] = new UInt16Random(); randomizersList[typeof(ulong)] = new UInt64Random(); randomizersList[typeof(DateTime)] = new DateTimeRandom(); UniversalRandom.AddRandomizers(randomizersList); UniversalRandom.AddInterceptors(new List <IInterceptor> { new ListInterceptor(), new EnumInterceptor(), new ArrayInterceptor() }); }
public void ClearInterceptorsTest() { UniversalRandom.ClearInterceptors(); var item = _random.Randomize <int[]>(); Assert.IsNull(item); }
public void ClearRandomizersTest() { UniversalRandom.ClearRandomizers(); var item1 = _random.Randomize <int>(); var item2 = _random.Randomize <int>(); Assert.AreEqual(item1, item2); Assert.AreEqual(item1, 0); }
public void RemoveInterceptrsTest() { ICollection <IInterceptor> types = new[] { new ListInterceptor() }; UniversalRandom.RemoveInterceptors(types); var item = _random.Randomize <int[]>(); Assert.IsNull(item); }
public RaceTrackCurve(float terrainWidth, Vector3 terrainScale) { float nodecenter = 1.0f * terrainWidth / 4f; float variation = 1.0f, strength = .6f; int direction = 2 * UniversalRandom.GetInstance().Next(2) - 1; float height = .14f; //float height = (float)UniversalRandom.GetInstance().NextDouble() / 3f; //nodes.Add(new CurveNode() //{ // Position = terrainScale * new Vector3(0, height, -nodecenter), // Tangent = Vector3.Transform(terrainScale * new Vector3(nodecenter, 0, 0), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1) / 2)) //}); float step = MathHelper.TwoPi / 5f; for (float i = 0; i < MathHelper.TwoPi; i += step) { height = (float)(.15 + .2 * (UniversalRandom.GetInstance().NextDouble() - .5)); nodes.Add(new CurveNode() { Position = terrainScale * Vector3.Transform(new Vector3(nodecenter, height, 0), Matrix.CreateRotationY(direction * i)), Tangent = Vector3.Transform(terrainScale * new Vector3(0, 0, -direction * strength * nodecenter), Matrix.CreateRotationY(direction * (i + (float)(variation * UniversalRandom.GetInstance().NextDouble())))) }); } //nodes.Add(new CurveNode() //{ // Position = terrainScale * new Vector3(nodecenter, height, -nodecenter / 2), // //Tangent = Vector3.Transform(terrainScale * new Vector3(nodecenter, 0, 0), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1) / 2)) // Tangent = Vector3.Transform(terrainScale * new Vector3(variation * nodecenter/2, 0, variation * nodecenter), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1))) //}); //nodes.Add(new CurveNode() //{ // Position = terrainScale * new Vector3(nodecenter / 2, height, nodecenter), // //Tangent = Vector3.Transform(terrainScale * new Vector3(-nodecenter, 0, 0), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1) / 2)) // Tangent = Vector3.Transform(terrainScale * new Vector3(variation * -nodecenter / 2, 0, variation * nodecenter), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1))) //}); //nodes.Add(new CurveNode() //{ // Position = terrainScale * new Vector3(-nodecenter / 2, height, nodecenter), // //Tangent = Vector3.Transform(terrainScale * new Vector3(-nodecenter, 0, 0), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1) / 2)) // Tangent = Vector3.Transform(terrainScale * new Vector3(variation * -nodecenter, 0, variation * nodecenter / 2), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1))) //}); //nodes.Add(new CurveNode() //{ // Position = terrainScale * new Vector3(-nodecenter, height, -nodecenter / 2), // //Tangent = Vector3.Transform(terrainScale * new Vector3(nodecenter, 0, 0), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1) / 2)) // Tangent = Vector3.Transform(terrainScale * new Vector3(0, 0, variation * -nodecenter), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1))) //}); }
public override void AdvanceTime(float time) { alpha += 0.0014f * (2.0f * (float)UniversalRandom.NextDouble() - 1.0f); Vector3 wind = new Vector3(1.530f * (float)Math.Cos(alpha), 1.530f, 1.530f * (float)Math.Sin(alpha)); // Vector3 g = new Vector3(0.0f, -0.9f, 0.0306f); this.zcr.AdvanceTime(time); this.rc.AdvanceTime(time, g, wind); this.ti.AdvanceTime(time); }
public ZertzRingRenderer(ZertzGame game, HexLocation hexLocation, Vector3 tileVector, Vector3 tileEscape, float time) { register(); this.tt = new Vector3((float)UniversalRandom.NextDouble(), (float)UniversalRandom.NextDouble(), 0.0f); this.hexLocation = hexLocation; this.boardLocation = Maths.HexVector(hexLocation, 2.0f * OUTER_RADIUS + SPACING, 0.5f * THICKNESS); this.tileVector = tileVector; this.RenderMover = RenderMoveManager.GenerateWaitMover(time, this.tileVector, RenderMoveManager.GenerateMoveMover(this.tileVector, tileEscape, 2.0f, RenderMoveManager.GenerateHopMover(tileEscape, this.boardLocation, 1.5f, null))); //this.RenderMover = RenderMoveManager.GenerateStaticMover(this.tileVector); }
public void RemoveRandomizersTest() { ICollection <Type> types = new[] { typeof(int) }; UniversalRandom.RemoveRandomizers(types); var item1 = _random.Randomize <int>(); var item2 = _random.Randomize <int>(); Assert.AreEqual(item1, item2); Assert.AreEqual(item1, 0); }
private void InitGradients() { for (int i = 0; i < GradientSizeTable; i++) { float z = 1f - 2f * (float)UniversalRandom.GetInstance().NextDouble(); float r = (float)Math.Sqrt(1f - z * z); float theta = 2 * (float)Math.PI * (float)UniversalRandom.GetInstance().NextDouble(); _gradients[i * 3] = r * (float)Math.Cos(theta); _gradients[i * 3 + 1] = r * (float)Math.Sin(theta); _gradients[i * 3 + 2] = z; } }
/// <summary> /// Adds a new particle to the system. /// </summary> public void AddParticle(Vector3 position, Vector3 velocity) { // Figure out where in the circular queue to allocate the new particle. int nextFreeParticle = firstFreeParticle + 1; if (nextFreeParticle >= settings.MaxParticles) { nextFreeParticle = 0; } // If there are no free particles, we just have to give up. if (nextFreeParticle == firstRetiredParticle) { return; } // Adjust the input velocity based on how much // this particle system wants to be affected by it. velocity *= settings.EmitterVelocitySensitivity; // Add in some random amount of horizontal velocity. float horizontalVelocity = MathHelper.Lerp(settings.MinHorizontalVelocity, settings.MaxHorizontalVelocity, (float)UniversalRandom.GetInstance().NextDouble()); double horizontalAngle = UniversalRandom.GetInstance().NextDouble() * MathHelper.TwoPi; velocity.X += horizontalVelocity * (float)Math.Cos(horizontalAngle); velocity.Z += horizontalVelocity * (float)Math.Sin(horizontalAngle); // Add in some random amount of vertical velocity. velocity.Y += MathHelper.Lerp(settings.MinVerticalVelocity, settings.MaxVerticalVelocity, (float)UniversalRandom.GetInstance().NextDouble()); // Choose four random control values. These will be used by the vertex // shader to give each particle a different size, rotation, and color. Color randomValues = new Color((byte)UniversalRandom.GetInstance().Next(255), (byte)UniversalRandom.GetInstance().Next(255), (byte)UniversalRandom.GetInstance().Next(255), (byte)UniversalRandom.GetInstance().Next(255)); // Fill in the particle vertex structure. for (int i = 0; i < 4; i++) { particles[firstFreeParticle * 4 + i].Position = position; particles[firstFreeParticle * 4 + i].Velocity = velocity; particles[firstFreeParticle * 4 + i].Random = randomValues; particles[firstFreeParticle * 4 + i].Time = currentTime; } firstFreeParticle = nextFreeParticle; }
public void AddRandomizersTest() { var randomizers = new Dictionary <Type, IRandomizeble> { { typeof(int), new Int32RandomCustom() } }; UniversalRandom.AddRandomizers(randomizers); var item1 = _random.Randomize <int>(); var item2 = _random.Randomize <int>(); Assert.AreEqual(item1, item2); Assert.AreEqual(item1, Int32RandomCustom.FakeRandom); }
public void AddInterceptorsTest() { var interceptors = new List <IInterceptor> { new FakeInterceptor() }; UniversalRandom.AddInterceptors(interceptors); var item1 = _random.Randomize <int>(); var item2 = _random.Randomize <int>(); Assert.AreEqual(item1, item2); Assert.AreEqual(item1, FakeInterceptor.Fake); }
public void RandomizersThreadSafe() { var hasExceptions = false; for (int i = 0; i < 5000; i++) { ThreadPool.QueueUserWorkItem(delegate { try { UniversalRandom.AddRandomizers( new Dictionary <Type, IRandomizeble> { { typeof(int), new Int32Random() } }); } catch (Exception) { hasExceptions = true; } }); ThreadPool.QueueUserWorkItem(delegate { try { UniversalRandom.RemoveRandomizers(new List <Type> { typeof(int) }); } catch (Exception) { hasExceptions = true; } }); ThreadPool.QueueUserWorkItem(delegate { try { UniversalRandom.ClearRandomizers(); } catch (Exception) { hasExceptions = true; } }); } Thread.Sleep(2000); Assert.IsFalse(hasExceptions); }
private void init() { this.xv[0x00] = new Vector3(0.0f, 0.0f, 0.0f); int i = 0x01; for (; i < n;) { this.xv[i++] = new Vector3(0.5f * ropeLength * (float)UniversalRandom.NextSignedDouble(), 0.5f * ropeLength * (float)UniversalRandom.NextSignedDouble(), 0.5f * ropeLength * (float)UniversalRandom.NextSignedDouble()); } for (; i < xv.Length;) { this.xv[i++] = new Vector3(0.0f, 0.0f, 0.0f); } }
public void InterceptorsThreadSafe() { var hasExceptions = false; for (int i = 0; i < 5000; i++) { ThreadPool.QueueUserWorkItem(delegate { try { UniversalRandom.AddInterceptors(new List <IInterceptor> { new ArrayInterceptor() }); } catch (Exception) { hasExceptions = true; } }); ThreadPool.QueueUserWorkItem(delegate { try { UniversalRandom.RemoveInterceptors(new List <IInterceptor> { new ArrayInterceptor() }); } catch (Exception) { hasExceptions = true; } }); ThreadPool.QueueUserWorkItem(delegate { try { UniversalRandom.ClearInterceptors(); } catch (Exception) { hasExceptions = true; } }); } Thread.Sleep(2000); Assert.IsFalse(hasExceptions); }
public Stone(GameManager game) : base() { this.game = game; Model = stoneVariants[UniversalRandom.GetInstance().Next(stoneVariants.Count)]; }
public BirdCurve() { float nodecenter = 1000; float variation = .8f; nodes.Add(new CurveNode() { Position = new Vector3(0, 5000f, -nodecenter), Tangent = Vector3.Transform(new Vector3(variation * nodecenter, 0, 0), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1))) }); nodes.Add(new CurveNode() { Position = new Vector3(nodecenter, 5000f, 0), Tangent = Vector3.Transform(new Vector3(0, 0, variation * nodecenter), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1))) }); nodes.Add(new CurveNode() { Position = new Vector3(0, 5000f, nodecenter), Tangent = Vector3.Transform(new Vector3(variation * -nodecenter, 0, 0), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1))) }); nodes.Add(new CurveNode() { Position = new Vector3(-nodecenter, 5000f, 0), Tangent = Vector3.Transform(new Vector3(0, 0, variation * -nodecenter), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1))) }); }
public override void Update(GameTime gameTime) { if (spawn) { spawn = false; flash = 1; Game.GetService <CameraComponent>().CurrentCamera.Shake(); List <SubBolt> branches = new List <SubBolt>(); branches.Add(new SubBolt() { position = startPosition + new Vector3( 5000 * ((float)UniversalRandom.GetInstance().NextDouble() - .5f), 0, 5000 * ((float)UniversalRandom.GetInstance().NextDouble() - .5f)), target = endPosition + new Vector3( 20000 * ((float)UniversalRandom.GetInstance().NextDouble() - .5f), 0, 20000 * ((float)UniversalRandom.GetInstance().NextDouble() - .5f)) }); while (branches.Count > 0) { for (int i = 0; i < branches.Count; i++) { Vector3 dTarget = branches[i].target - branches[i].position; float distance = dTarget.Length(); // Remove if (distance < 150) { branches.RemoveAt(i--); continue; } // Add if (UniversalRandom.GetInstance().NextDouble() < .002 && i == 0) { var newBolt = branches[i].Clone(); newBolt.target = newBolt.position + Vector3.Transform(dTarget, Matrix.CreateFromYawPitchRoll( rotationSeed * ((float)UniversalRandom.GetInstance().NextDouble() - .5f), rotationSeed * ((float)UniversalRandom.GetInstance().NextDouble() - .5f), rotationSeed * ((float)UniversalRandom.GetInstance().NextDouble() - .5f))); newBolt.target = Vector3.Lerp(newBolt.target, branches[0].target, .4f); branches.Add(newBolt); } branches[i].minDist = distance; dTarget.Normalize(); // Offset dTarget Vector3 offset = Vector3.Transform(2f * dTarget, Matrix.CreateFromYawPitchRoll( rotationSeed * ((float)UniversalRandom.GetInstance().NextDouble() - .5f), rotationSeed * ((float)UniversalRandom.GetInstance().NextDouble() - .5f), rotationSeed * ((float)UniversalRandom.GetInstance().NextDouble() - .5f))); for (int j = 0; j < 2; j++) { particleSystem.AddParticle(branches[i].position, Vector3.Zero); branches[i].position += 10 * j * offset; } } } } if (flash > 0) { flash = Math.Max(flash - .01f, 0); } Game.GetService <DirectionalLight>().Ambient = flash * flashColor; base.Update(gameTime); }
public BirchTree(GameManager game) : base() { this.game = game; Model = birchTreesVariants[UniversalRandom.GetInstance().Next(birchTreesVariants.Count)]; }