void Flit(float CurrentTime, float DeltaTime) { //POrientation = MathHelper.WrapAngle(POrientation); PerlinBeat = MathHelper.Clamp(PerlinBeat + FlockTools.GetRandomFloat(-0.05f, 0.05f), -1f, 1f); float perlinR = (Noise.GetNoise(CurrentTime * 100, 0, 0)) * DeltaTime * PerlinBeat; PTheta = MathHelper.WrapAngle(PTheta + perlinR); POrientation += perlinR; }
public Agent() { AgentId = CurrentAgentId++; MaxForceSqared = MaxForce * MaxForce; MaxSpeedSquared = MaxSpeed * MaxSpeed; Position = new Vector2(FlockTools.GetRandomFloat(SirFlocksalotGame.ScreenSize.X), FlockTools.GetRandomFloat(SirFlocksalotGame.ScreenSize.Y)); float QuarterSpeed = MaxSpeed * 0.25f; Velocity = FlockTools.GetRandomVector2(-QuarterSpeed, QuarterSpeed, -QuarterSpeed, QuarterSpeed); Orientation = Velocity.Heading(); }
public FlockAgent(Texture2D AgentTexture) : base() { Texture = AgentTexture; MaxForce = 10; MaxForceSqared = MaxForce * MaxForce; FlockDistance = 80 + FlockTools.GetRandomFloat(30.0f); FlockDistanceSqared = FlockDistance * FlockDistance; FlockAngle = (float)Math.PI - FlockTools.GetRandomFloat((float)Math.PI * 0.5f); CohesionWeight = 0.3f + FlockTools.GetRandomFloat(0.3f) - 0.1f; SeparationWeight = 0.2f + FlockTools.GetRandomFloat(0.25f) - 0.1f; AlignmentWeight = 0.3f + FlockTools.GetRandomFloat(0.25f) - 0.05f; PTheta = FlockTools.GetRandomFloat(MathHelper.TwoPi); PerlinBeat = FlockTools.GetRandomFloat(-0.01f, 0.01f); }
void Wander(float CurrentTime, float DeltaTime) { Vector2 forward_target = new Vector2((float)Math.Cos(Orientation), (float)Math.Sin(Orientation)); forward_target *= WanderDistance; WanderDelta = MathHelper.Clamp(WanderDelta + FlockTools.GetRandomFloat(-1, 1), -10, 10); float value = Noise.GetNoise(CurrentTime * WanderDelta * WanderRate, 0, 0) * WanderAmp; WanderTheta += MathHelper.WrapAngle(WanderTheta + value * DeltaTime); float x = WanderRadius * (float)Math.Cos(WanderTheta) - WanderRadius * (float)Math.Sin(WanderTheta); float y = WanderRadius * (float)Math.Cos(WanderTheta) + WanderRadius * (float)Math.Sin(WanderTheta); Vector2 wander_target = new Vector2(forward_target.X + x, forward_target.Y + y); wander_target.Normalize(); Acceleration += wander_target * WanderStrength; }