using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Blacklight.Core.Cameras; using Azimuth; using Annulus; using Annulus.SweptCollisionDetection; namespace Annulus.Testbed { public partial class Main : Form { MicroscopeCamera camera; System.Threading.Thread GameThread; Scalar time = 0; private static volatile bool turnOnSingleStep = false; object locker = new object(); public Main() { InitializeComponent(); viewport.DrawableSurface.BackgroundColor = new Blacklight.Core.Color(0, 0.5, 1.0, 0); camera = new MicroscopeCamera(viewport.DrawableSurface); viewport.DrawableSurface.Invalidated += delegate(object sender, EventArgs e) { Draw(time); }; GameThread = new System.Threading.Thread(delegate() { while (true) { var startTime = System.Diagnostics.Stopwatch.StartNew(); if ((turnOnSingleStep || !pausedCheck.Checked)) { lock (locker) { time += 1.0 / 60.0; while (startTime.ElapsedTicks < (System.Diagnostics.Stopwatch.Frequency / 60)) { System.Threading.Thread.Sleep(0); } } } if (turnOnSingleStep) { pausedCheck.Checked = true; turnOnSingleStep = false; } System.Threading.Thread.Sleep(0); } }); GameThread.Name = "Game sim thread"; GameThread.Start(); this.Disposed += delegate(object sender, EventArgs e) { GameThread.Abort(); }; } public void Draw(Scalar time) { viewport.DrawableSurface.FrameReset(); timeLabel.Text = "Time = " + time; var polygon = new SimplePolygon(new Vector[] { new Vector(0, 0), new Vector(1, 0), new Vector(1, 1), new Vector(0, 1), }); var input = new CollidingInput { collideeFrame = new RotatingFrame { AngularVelocity = Math.PI / 2, }, pointMotion = new Motion { InitialPosition = new Vector(Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2), }, pointLeverArm = new Vector(0, 0), impactWindow = new Interval(0, 10), maxIterations = 1000, }; var scene = new Blacklight.Core.Scene(); scene.Cels.Add(new Blacklight.Core.Cel()); scene.Cels[0].AddEntity(new Blacklight.Core.Entity { drawable = new Blacklight.Core.Drawables.Polygon(polygon) { InsideColor = new Blacklight.Core.Color(1.0, 1.0, 1.0, 1), ShellColor = new Blacklight.Core.Color(1.0, 1.0, 1.0, 1), }, modelToWorld = new AffineMatrix(input.collideeFrame.OrientationAt(time), Vector.Zero), }); scene.Cels[0].AddEntity(new Blacklight.Core.Entity { drawable = new Blacklight.Core.Drawables.Ellipse { InsideColor = new Blacklight.Core.Color(1.0, 1.0, 1.0, 1), ShellColor = new Blacklight.Core.Color(1.0, 1.0, 1.0, 1), ShellPixelThickness = 4, }, modelToWorld = input.pointMotion.TransformAt(time) * new AffineMatrix(0, Vector.Zero, .01), }); viewport.DrawableSurface.DrawScene(scene, camera); viewport.DrawableSurface.SubmitDrawCalls(); } private void timer_Tick(object sender, EventArgs e) { Draw(time); } private void resetButton_Click(object sender, EventArgs e) { time = 0; Draw(time); } } }