private void GenerateTunnels(Vector2 start, float maxLength = 2000.0f, float turnStrength = 0.2f) { //1234 //12345 //498764867 //582764 var random = new FastRandom(498764867); const float step = 2.0f; var terrainHeight = _terrain.TerrainSize.Y / 2.0f; var maxSize = new Vector2(30.0f); var currentPosition = start; var currentDirection = Vector2.UnitX; var length = 0.0f; while (length < maxLength) { var currentSize = maxSize + new Vector2(Math.Max(0.0f, length + 200.0f - maxLength)) * 1.0f; var brushSize = new Vector2(random.NextFloat() * currentSize.X, random.NextFloat() * currentSize.Y); var brush = new CircleBrush( (brushSize.X + brushSize.Y) / 4.0f, currentPosition + new Vector2(random.NextRangedFloat(), random.NextRangedFloat())); _terrain.SetQuads(brush, false, true); // Add rotation. var rotationDir = random.NextRangedFloat(); // Prevent going outside terrain or going back. if (currentPosition.Y > terrainHeight - 200.0f || (currentDirection.X < 0.0f && currentDirection.Y > 0.0f)) { rotationDir = (rotationDir - 1.0f) * 0.1f; } else if (currentPosition.Y < -(terrainHeight + 200.0f) || (currentDirection.X < 0.0f && currentDirection.Y < 0.0f)) { rotationDir = (rotationDir + 1.0f) * 0.1f; } // Apply rotation. var rotation = rotationDir * turnStrength; currentDirection = new Vector2( currentDirection.X * MathCore.Cos(rotation) + -currentDirection.Y * MathCore.Sin(rotation), currentDirection.Y * MathCore.Cos(rotation) + currentDirection.X * MathCore.Sin(rotation)); currentPosition += currentDirection * step; length += step; } _terrain.Refresh(); }
private void Initialize(ICamera camera) { // Retrieve the necessary data. var vector3 = camera.SceneNode.Position; var cameraPosition = new Vector2(vector3.X, vector3.Y); var halfScreenSize = camera.ScreenSize / 2.0f; _lastCameraPosition = cameraPosition; // Use the viewport's and screen's height to determine our particle size since it's contstant. // Particle size = 2 pixels. _particleSize = camera.ScreenSize.Y / (float)camera.Viewport.Height * 2.0f; _halfParticleSize = _particleSize / 2.0f; // Initialize the particles. for (int i = 0; i < _particles.Length; ++i) { var particle = new Particle { Position = new Vector2( cameraPosition.X + halfScreenSize.X * _random.NextRangedFloat(), cameraPosition.Y + halfScreenSize.Y * _random.NextRangedFloat()), Color = new Color( 1.0f - _random.NextFloat() * 0.2f, 1.0f - _random.NextFloat() * 0.2f, 1.0f - _random.NextFloat() * 0.2f, 1.0f - _random.NextFloat() * 0.2f) }; _particles[i] = particle; RebuildPartice(i, ref particle); } _hasInitialized = true; }