예제 #1
0
 public void CreateEnvironment()
 {
     LastWindowPos = new PointF(Left, Top);
     RenderThread = new Thread(new ThreadStart(Render));
     SimulationThread = new Thread(new ThreadStart(Simulate));
     Paused = false;
     FrameAdvance = false;
     FrameCounter = new FramerateMeter();
     Size CSize = Canvas.Bounds.Size;
     EnvironmentBounds = new Bounds(new PointF(0, 0), new PointF(CSize.Width, CSize.Height));
     Particles = new List<Particle>();
     for (int i = 0; i < ParticleCount; i++)
         Particles.Add(new Particle(30, RandomPointFInBounds(EnvironmentBounds), RandomInUnitCircle().Times(1000)));
 }
예제 #2
0
 public static PointF RandomPointFInBounds(Bounds Bound)
 {
     return RandomPointF().Times(Bound.Range).Plus(Bound.Lower);
 }
예제 #3
0
 private void RemoveFromOutOfBounds(Bounds EnvironmentBounds)
 {
     if (PrePosition.X < EnvironmentBounds.Lower.X + Radius)
         PrePosition.X = EnvironmentBounds.Lower.X + Radius + 1;
     if (PrePosition.X > EnvironmentBounds.Upper.X - Radius)
         PrePosition.X = EnvironmentBounds.Upper.X - Radius - 1;
     if (PrePosition.Y < EnvironmentBounds.Lower.Y + Radius)
         PrePosition.Y = EnvironmentBounds.Lower.Y + Radius + 1;
     if (PrePosition.Y > EnvironmentBounds.Upper.Y - Radius)
         PrePosition.Y = EnvironmentBounds.Upper.Y - Radius - 1;
 }
예제 #4
0
 public void SimulateNextFrame(float DeltaTime, Bounds EnvironmentBounds, List<Particle> Particles)
 {
     PreVelocity = Velocity;
     PrePosition = SimulateLinearAcceleration(DeltaTime);
     TestForWallCollision(DeltaTime, EnvironmentBounds);
     TestForParticleCollision(DeltaTime, Particles);
     SimulateGravity(DeltaTime);
     PrePosition = SimulateLinearAcceleration(DeltaTime);
     RemoveFromOtherParticles(Particles);
     RemoveFromOutOfBounds(EnvironmentBounds);
 }
예제 #5
0
 private void TestForWallCollision(float DeltaTime, Bounds EnvironmentBounds)
 {
     if (PrePosition.X < EnvironmentBounds.Lower.X + Radius
         || PrePosition.X > EnvironmentBounds.Upper.X - Radius)
     {
         PreVelocity.X = -PreVelocity.X;
     }
     if (PrePosition.Y < EnvironmentBounds.Lower.Y + Radius
         || PrePosition.Y > EnvironmentBounds.Upper.Y - Radius)
     {
         PreVelocity.Y = -PreVelocity.Y;
     }
 }