Example #1
0
        private static void Main()
        {
            var window = new ExampleWindow(debug: true);

            var camera = window.GameWindow.CreateFirstPersonCameraController(1f, new Vector3(36f, 0.1f, 30f), 70f, 0.01f, 300f);

            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.GameWindow.KeyDown += (s, a) => { if (a.Key == OpenTK.Input.Key.Tab)
                                                     {
                                                         visual.Wireframe = !visual.Wireframe;
                                                     }
            };

            var         sampleSeries = new ExponentialSmoothing(0.01);
            QueryObject timeQuery    = new QueryObject();

            window.Render += () =>
            {
                timeQuery.Activate(QueryTarget.TimeElapsed);
                visual.Draw(camera);
                timeQuery.Deactivate();
                var timerQueryResult = timeQuery.ResultLong * 1e-6;
                sampleSeries.NewSample(timerQueryResult);
                window.GameWindow.Title = $"{sampleSeries.SmoothedValue:F0}ms";
            };
            window.Resize += visual.Resize;
            window.Resize += (w, h) => sampleSeries.Clear();
            window.Run();
        }
        private static void Main()
        {
            var window = new ExampleWindow();
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            window.GameWindow.AddWindowAspectHandling(visual.Camera.Projection);
            var movementState = window.GameWindow.AddFirstPersonCameraEvents(visual.Camera.View);

            window.Update += (dt) => visual.Camera.View.ApplyRotatedMovement(movementState.movement * 30 * dt);
            var         sampleSeries = new ExponentialSmoothing(0.01);
            QueryObject timeQuery    = new QueryObject();

            window.Render += () =>
            {
                timeQuery.Activate(QueryTarget.TimeElapsed);
                visual.Draw();
                timeQuery.Deactivate();
                var timerQueryResult = timeQuery.ResultLong * 1e-6;
                sampleSeries.NewSample(timerQueryResult);
                window.GameWindow.Title = $"{sampleSeries.SmoothedValue:F0}ms";
            };
            window.Resize += visual.Resize;
            window.Resize += (w, h) => sampleSeries.Clear();
            window.Run();
        }
Example #3
0
        private static void Main()
        {
            var window = new ExampleWindow();

            var camera = window.GameWindow.CreateOrbitingCameraController(0.3f, 70, 0.01f, 30f);

            camera.View.Elevation = 15;
            var visual = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);

            var         sampleSeries = new ExponentialSmoothing(0.01);
            QueryObject timeQuery    = new QueryObject();

            window.Render += () =>
            {
                var timerQueryResult = timeQuery.ResultLong * 1e-6;
                sampleSeries.NewSample(timerQueryResult);
                window.GameWindow.Title = $"{sampleSeries.SmoothedValue:F0}ms";
                timeQuery.Activate(QueryTarget.TimeElapsed);
                visual.Draw(camera);
                timeQuery.Deactivate();
            };
            window.Resize += visual.Resize;
            window.Resize += (w, h) => sampleSeries.Clear();
            window.Run();
        }
 public void SmoothedValueConstant()
 {
     for (var value = -1.0; value < 2.0; value += 0.1)
     {
         var smoothing = new ExponentialSmoothing(0.1);
         smoothing.NewSample(value);
         Assert.AreEqual(value, smoothing.SmoothedValue);
         smoothing.NewSample(value);
         Assert.AreEqual(value, smoothing.SmoothedValue);
     }
 }
Example #5
0
        private void UpdateDistance(double?absoluteDistance, double?newRelativeDistance)
        {
            if (absoluteDistance.HasValue)
            {
                _rawDistance = ExponentialSmoothing.Smooth(_rawDistance, absoluteDistance.Value, SMOOTHING_ALPHA);
                Distance     = Math.Round(_rawDistance / 10);
            }

            if (newRelativeDistance.HasValue)
            {
                RelativeDistance     = Math.Min(Math.Max(ExponentialSmoothing.Smooth(RelativeDistance, newRelativeDistance.Value, SMOOTHING_ALPHA), MinRelativeDistance), MaxRelativeDistance);
                ShowRelativeDistance = true;
            }
        }
        public void SmoothedValueRnd()
        {
            var rnd     = new Random();
            var samples = 1000;

            for (var j = 0; j < 100; ++j)
            {
                var smoothing = new ExponentialSmoothing(10.0 / samples);
                for (int i = 0; i < samples; ++i)
                {
                    var value = rnd.NextDouble();
                    smoothing.NewSample(value);
                }
                Assert.AreEqual(0.5, smoothing.SmoothedValue, 0.1);
            }
        }
        private static void Main()
        {
            var window = new ExampleWindow();
            var model  = new Model();
            var time   = new Stopwatch();

            time.Start();

            var sampleSeries = new ExponentialSmoothing(0.01);
            var bruteForce   = false;

            window.Update += (t) =>
            {
                model.UpdateMovements(t);

                var isSpaceDown = Keyboard.GetState().IsKeyDown(Key.Space);
                if (isSpaceDown != bruteForce)
                {
                    sampleSeries.Clear();
                    bruteForce = isSpaceDown;
                }

                var t1 = time.ElapsedTicks;                 //get time before collision detection
                if (bruteForce)
                {
                    //model.GridCollisionCenter(); //TODO: some collisions are not detected
                    model.BruteForceCollision();
                }
                else
                {
                    model.GridCollision();
                }
                var t2        = time.ElapsedTicks;          //get time after collision detection
                var deltaTime = (t2 - t1) / (double)Stopwatch.Frequency;
                sampleSeries.NewSample(deltaTime);
                window.GameWindow.Title = $"{sampleSeries.SmoothedValue * 1e3:F2}ms";

                //sampleSeries.NewSample(model.CollisionCount);
                //window.GameWindow.Title = $"{sampleSeries.SmoothedValue:F0} collisions detected";
            };

            var view = new View(window.RenderContext.RenderState);

            window.Render += () => view.Render(model.Colliders);
            window.Run();
        }
Example #8
0
        private static void Main()
        {
            var window = new ExampleWindow();
            var camera = window.GameWindow.CreateOrbitingCameraController(3, 70, 0.1f, 20);

            camera.View.Elevation = 35;
            camera.View.Azimuth   = 60;
            var visual     = new MainVisual(window.RenderContext.RenderState, window.ContentLoader);
            var time       = new GameTime();
            var timeSeries = new ExponentialSmoothing(0.01);

            window.Render += () =>
            {
                time.NewFrame();
                var deltaTime = visual.Render(time.DeltaTime, camera);
                timeSeries.NewSample(deltaTime);
                window.GameWindow.Title = $"{timeSeries.SmoothedValue:F2}msec";
            };
            window.Resize += visual.Resize;
            window.Run();
        }