Exemple #1
0
 public void Update(FrameArgs e)
 {
     if (_isRunning)
     {
         this.Apply(e.Time - _startTime);
     }
 }
Exemple #2
0
        void IHandler <Start> .Handle(FrameArgs frame, Start e)
        {
            // orthographic camera covering screen
            _cam1 = new Camera2D(e.Size, 1000f, Camera2DOrigin.Center);

            // perspective camera with 45deg vertical FOV
            // aspect ratio matches window
            _cam2 = new Camera();
            _cam2.SetTransforms(
                Matrix4.LookAt(new Vector3(0, 0, 4f),
                               Vector3.Zero,
                               Vector3.UnitY),
                Matrix4.CreatePerspectiveFieldOfView(
                    MathHelper.DegreesToRadians(45f),
                    e.Size.X / e.Size.Y, 0.1f, 100f)
                );

            // we'll use a solid red material
            _mat = new SpriteMaterial(new SolidColorShader(), null)
            {
                Color = new Vector4(1, 0, 0, 1)
            };

            // create a quad with an origin at the center and unit size
            _quad = new Quad(_mat, new Vector4(-0.5f, -0.5f, 0.5f, 0.5f),
                             Vector4.One);
        }
Exemple #3
0
        void IHandler <Start> .Handle(FrameArgs frame, Start e)
        {
            // basic orthographic camera will do
            // model has a really small scale, so "zoom in"
            _cam = new Camera2D(e.Size / 15000, 1000, Camera2DOrigin.Center);

            // basic lighting with a single directional light
            _lights = new Lighting(
                new DirectionalLight(
                    -Vector3.UnitY,                 // direction
                    new Vector3(.2f, .2f, .2f),     // ambient
                    Vector3.One,                    // diffuse
                    Vector3.One                     // specular
                    ),
                new PointLight(
                    new Vector3(-.05f, -0.03f, 0f), // position
                    Vector3.Zero,                   // ambient
                    new Vector3(1, 0.4f, 0.4f),     // diffuse
                    Vector3.One,                    // specular
                    Vector3.One                     // attenuation
                    ),
                new PointLight(
                    new Vector3(.05f, -0.03f, 0f),  // position
                    Vector3.Zero,                   // ambient
                    new Vector3(0.4f, 1, 0.4f),     // diffuse
                    Vector3.One,                    // specular
                    Vector3.One                     // attenuation
                    )
                );

            // load our model
            // adding it to the scene disposes it automatically later
            _model = new Model("sphere.model");
            this.Add(_model);
        }
Exemple #4
0
 void IUpdater.Update(FrameArgs e)
 {
     // rotate the model slowly and center in front of camera
     _rot  += Mathf.PiOver2 * e.DeltaTime;
     _world = Matrix4.Scale(200f) * Matrix4.CreateRotationY(_rot)
              * Matrix4.CreateTranslation(0, -200f, 300f);
 }
Exemple #5
0
 void IHandler <Start> .Handle(FrameArgs frame, Start e)
 {
     _cam     = new Camera2D(e.Size, 1000f, Camera2DOrigin.LowerLeft);
     _sprites = new Atlas("sprites.atlas");
     _batch   = new Batch();
     _sz      = e.Size;
 }
Exemple #6
0
 void IHandler <KeyEvent> .Handle(FrameArgs frame, KeyEvent e)
 {
     if (e.State == KeyState.Down || e.Symbol == ' ')
     {
         _markers.Clear();
     }
 }
Exemple #7
0
 void IHandler <Touch> .Handle(FrameArgs frame, Touch e)
 {
     if (e.State == TouchState.Start)
     {
         _fader.FadeTo(new Scene1(this.View, _fader), 0.5f);
     }
 }
Exemple #8
0
        void IHandler <Start> .Handle(FrameArgs frame, Start e)
        {
            _cam = new Camera2D(e.Size, 1000f, Camera2DOrigin.Center);

            // we'll use a solid red material
            _mat = new SpriteMaterial(new SolidColorShader(), null)
            {
                Color = new Vector4(1, 0, 0, 1)
            };

            // create a quad with an origin at the center and unit size
            _quad = new Quad(_mat, new Vector4(-0.5f, -0.5f, 0.5f, 0.5f),
                             Vector4.One);

            _pos = new Vector3(-200, 0, 0);

            // create a controller for the position
            // adding controllers to the scene allows them to update their values
            // automatically, but we could also pump them manually in Update
            var posctl = new Controller <float>(-200, Tween.EaseInOutCubic,
                                                v => _pos.X = v, ReversePos);

            posctl.To(200, 1);
            this.Add(posctl);

            // similar controller for rotation
            var rotctl = new Controller <float>(0, Tween.Lerp, v => _rot = v, ReverseRot);

            rotctl.To(-MathHelper.Pi, 1);
            this.Add(rotctl);
        }
Exemple #9
0
        protected override void OnDraw(FrameArgs e)
        {
            base.OnDraw(e);

            // the first stage draws the sprite to the frame buffer with
            // a horizontal blur
            using (_fbcam.Begin()) {             // using the camera...
                using (_fb.Begin()) {            // ...and drawing to buffer...
                    using (_matHblur.Begin()) {  // ...and blur mat...
                        // since a material was put in scope, it overrides
                        // the sprite's built-in material
                        _sprites["star"].Draw(Matrix4.Identity);
                    }
                }
            }

            // the second stage draws the sprite with a vertical blur
            // to the screen. normal sprites are drawn last to create
            // a glow effect on the rightmost sprite.
            using (_cam.Begin()) {
                using (_matVblur.Begin()) {
                    // draw blurred sprite in middle
                    _quad.Draw(Matrix4.Identity);
                    // draw blurred sprighte on right
                    _quad.Draw(Matrix4.CreateTranslation(128, 0, 0));
                }
                // draw sprite on left
                _sprites["star"].Draw(Matrix4.CreateTranslation(-128, 0, 1));
                // draw sprite on right on top of blurred sprite
                _sprites["star"].Draw(Matrix4.CreateTranslation(128, 0, 1));
            }
        }
Exemple #10
0
 void IHandler <Resume> .Handle(FrameArgs frame, Resume e)
 {
     if (_wasPlaying)
     {
         _music.Play();
     }
 }
Exemple #11
0
        void IHandler <Start> .Handle(FrameArgs frame, Start e)
        {
            _cam = new Camera2D(e.Size, 1000f, Camera2DOrigin.LowerLeft);

            // create our UI root. adding it to the scene allows events
            // like touch and resize to filter through the UI hierarchy.
            // it also automatically disposes the hierarchy.
            _root = new RootView(e.Size, 0f);
            this.Add(_root);

            // create our custom progress bar to stretch across most
            // of the screen
            _bar = new ProgressBarView(new LayoutSpec {
                Top    = p => (e.Size.Y - 30f) / 2f,
                Height = p => 30f,
                Left   = p => 50,
                Right  = p => 50
            });
            _root.AddView(_bar);

            // spin up a coroutine to animate the progress bar
            // keeping a reference to the coroutine list allows us to
            // access frame args from within coroutines
            _co = new CoroutineList <FrameArgs>();
            this.Add(_co);
            _co.Start(this.CoAnimateBar());
        }
Exemple #12
0
 public void Update(FrameArgs e)
 {
     this.OnUpdate(e);
     foreach (var view in _children)
     {
         view.Update(e);
     }
 }
Exemple #13
0
        void IHandler <Start> .Handle(FrameArgs frame, Start e)
        {
            _cam  = new Camera2D(e.Size, 1000f);
            _root = new RootView(e.Size, 0f);

            _root.AddView(new MyView());
            this.Add(_root);
        }
Exemple #14
0
        protected override void OnDraw(FrameArgs e)
        {
            base.OnDraw(e);

            using (_cam.Begin()) {
                _root.Draw();
            }
        }
Exemple #15
0
        void IHandler <Start> .Handle(FrameArgs frame, Start e)
        {
            _cam = new Camera2D(e.Size, 1000f, Camera2DOrigin.Center);

            // load the atlas
            _numbers  = new Atlas("numbers.atlas");
            _numWidth = _numbers["0"].Size.X;             // we know they're all the same
        }
Exemple #16
0
 void IHandler <Pause> .Handle(FrameArgs frame, Pause e)
 {
     if (_music != null && _music.IsPlaying)
     {
         _wasPlaying = true;
         _music.Pause();
     }
 }
Exemple #17
0
        protected override void OnDraw(FrameArgs e)
        {
            base.OnDraw(e);

            using (_cam.Begin()) {
                _anim.Draw(0, 0, 0);
            }
        }
Exemple #18
0
        void IHandler <Touch> .Handle(FrameArgs frame, Touch e)
        {
            if (!_settled || _gameOver || _noInput)
            {
                return;
            }
            if (!_useTouch && !e.IsVirtual)
            {
                return;
            }

            int i, j;
            var point = _cam.Unproject(e.Point, 0f);

            PointToSquare(new Vector2(point.X, point.Y), out i, out j);
            if (i < 0 || j < 0)
            {
                _fromSquare = null;
                return;
            }

            switch (e.State)
            {
            case TouchState.Start:
                _fromSquare = new Tuple <int, int>(i, j);
                break;

            case TouchState.Move:
                if (_fromSquare != null && (_fromSquare.Item1 != i ^ _fromSquare.Item2 != j))
                {
                    if (i > _fromSquare.Item1)
                    {
                        i = _fromSquare.Item1 + 1;
                    }
                    else if (i < _fromSquare.Item1)
                    {
                        i = _fromSquare.Item1 - 1;
                    }
                    if (j > _fromSquare.Item2)
                    {
                        j = _fromSquare.Item2 + 1;
                    }
                    else if (j < _fromSquare.Item2)
                    {
                        j = _fromSquare.Item2 - 1;
                    }

                    TrySwap(_fromSquare.Item1, _fromSquare.Item2, i, j);
                    _fromSquare = null;
                }
                break;

            case TouchState.End:
            case TouchState.Cancel:
                _fromSquare = null;
                break;
            }
        }
Exemple #19
0
        protected override void OnDraw(FrameArgs e)
        {
            base.OnDraw(e);

            using (_cam.Begin()) {
                _quad.Draw(Matrix4.Scale(100f)
                           * Matrix4.CreateTranslation(100, 0, 0));
            }
        }
Exemple #20
0
 void IHandler <Touch> .Handle(FrameArgs frame, Touch e)
 {
     if (e.State == TouchState.Start)
     {
         Console.WriteLine(e.SurfacePoint);
         _markers.Add(new Vector3(e.SurfacePoint.X,
                                  e.SurfacePoint.Y, 0));
     }
 }
Exemple #21
0
        void IHandler <Gesture> .Handle(FrameArgs frame, Gesture e)
        {
            IGestureInput target = _focused as IGestureInput;

            if (target != null)
            {
                target.OnGesture(e);
            }
        }
Exemple #22
0
 private void TimePunchFireProjectile(FrameArgs e)
 {
     if (e.CurrentFrame == 1)
     {
         ProjectileSystem.Add(new BlueBlastProjectile(_player));
         _timeGunFireSound.Play();
         _player.ComplexAnimation.FrameChanged -= TimePunchFireProjectile;
     }
 }
Exemple #23
0
        protected override void OnDraw(FrameArgs e)
        {
            base.OnDraw(e);

            using (_cam.Begin()) {             // using the camera...
                // ... draw the quad
                _quad.Draw(ref _world);
            }
        }
Exemple #24
0
        protected override void OnDraw(FrameArgs e)
        {
            base.OnDraw(e);

            using (_cam.Begin()) {             // using the camera...
                using (_lights.Begin()) {      // ...and the lights...
                    _model.Draw(ref _world);   // ...draw the model!
                }
            }
        }
Exemple #25
0
        protected override void OnDraw(FrameArgs e)
        {
            base.OnDraw(e);

            using (_cam.Begin()) {             // using the camera...
                // ... draw the quads
                _quad1.Draw(Matrix4.CreateTranslation(-125, 0, 0));
                _quad2.Draw(Matrix4.CreateTranslation(125, 0, 0));
            }
        }
Exemple #26
0
        void IUpdater.Update(FrameArgs e)
        {
            // update the quad's position
            _pos.X += _width * e.DeltaTime * (_reverse ? 1f : -1f);
            if (Mathf.Abs(_pos.X) >= _width / 2f - _halfSize)
            {
                _reverse = !_reverse;
            }

            _world = Matrix4.CreateTranslation(_pos);
        }
        private void Proc(Mat read, FrameArgs args)
        {
            if (!read.Empty())
            {
                realLastMs = sw.ElapsedMilliseconds;
                if (onFace)
                {
                    var scale = Math.Max(read.Height, read.Width) / 300;
                    Cv2.Resize(read, read, new Size(read.Width / scale, read.Height / scale));
                    wrap.DetectImage(read);
                    wrap.Draw(read);
                    var box = wrap.BoundaryBox;
                    Cv2.Rectangle(read, new Rect((int)box.X, (int)box.Y, (int)box.Width, (int)box.Height), Scalar.Aqua, 2);
                    DrawInfo(read, new Point2d(10, 20));
                }
                else
                {
                    Cv2.Resize(read, read, new Size(320, 240));
                    wrap.CheckFocus(read);
                    var faces = cascade.DetectMultiScale(read, 1.4, 2, HaarDetectionType.ScaleImage, new Size(read.Width * 0.2, read.Height * 0.2), read.Size());
                    foreach (var face in faces)
                    {
                        wrap.DetectROI(read, face);
                        wrap.Draw(read);
                        DrawInfo(read, face.TopLeft);
                        read.Rectangle(face, Scalar.Blue, 2, LineTypes.AntiAlias);
                    }
                }
                time = sw.ElapsedMilliseconds - realLastMs;
                read.PutText($"realfps:{1000/time}", new Point(10, 100), HersheyFonts.HersheyPlain, 1, Scalar.Lime, 1, LineTypes.AntiAlias);
                read.PutText($"fps:{1000 / (sw.ElapsedMilliseconds - lastMs)}", new Point(10, 120), HersheyFonts.HersheyPlain, 1, Scalar.Lime, 1, LineTypes.AntiAlias);
                lastMs = sw.ElapsedMilliseconds;
                Cv2.ImShow("test", read);
            }

            switch (args.LastKey)
            {
            case 'r':
                wrap.Reset();
                break;

            case 'i':
                wrap.InVideo = !wrap.InVideo;
                break;

            case 'f':
                onFace = !onFace;
                break;

            case 'q':
                args.Break = true;
                break;
            }
        }
Exemple #28
0
        protected override void OnDraw(FrameArgs e)
        {
            base.OnDraw(e);

            using (_cam.Begin()) {             // using the camera...
                // not much to do here, just draw the UI root
                // we could also apply transforms or draw the UI
                // to a frame buffer object for post effects
                _root.Draw();
            }
        }
Exemple #29
0
        protected override void OnDraw(FrameArgs e)
        {
            base.OnDraw(e);

            using (_cam.Begin()) {             // using the camera...
                using (_lights.Begin()) {      // ...and the lights...
                    // draw the model!
                    _model.Draw(Matrix4.Identity);
                }
            }
        }
Exemple #30
0
        protected override void OnDraw(FrameArgs e)
        {
            base.OnDraw(e);

            using (_cam.Begin()) {             // using the camera...
                // ... draw the quads
                foreach (var pos in _markers)
                {
                    _quad.Draw(Matrix4.CreateTranslation(pos));
                }
            }
        }
Exemple #31
0
		public SDL2GameView (string title, int width, int height, bool fullscreen = false, bool vsync = true, 
		                     int x = SDL.SDL_WINDOWPOS_CENTERED, int y = SDL.SDL_WINDOWPOS_CENTERED) {
			_refCount++;
			_width = width;
			_height = height;

			_frameArgs = new FrameArgs();
			_frameArgs.Enqueue(new Start(new Vector2(_width, _height), 1.0f));
			_frameArgs.Enqueue(new Resize(new Vector2(_width, _height), 1.0f));
			_sdlEvents = new ConcurrentQueue<SDL.SDL_Event>();

			SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, 2);
			SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, 1);
			SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, (int)SDL.SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
			SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_RED_SIZE, 8);
			SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_GREEN_SIZE, 8);
			SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_BLUE_SIZE, 8);
			SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DEPTH_SIZE, 24);
			SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_MULTISAMPLEBUFFERS, 1);
			SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_MULTISAMPLESAMPLES, 4);

			_window = SDL.SDL_CreateWindow(
				title,
				x, y,
				width, height,
				SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL
				| (fullscreen ? SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN : 0)
			);
			if (_window == IntPtr.Zero)
				throw new SDL2Exception();

			if (_alContext == null) {
				_alContext = new AudioContext();
				_alContext.MakeCurrent();
			}

			if(vsync)
				SDL.SDL_GL_SetSwapInterval(1);
			_windowId = SDL.SDL_GetWindowID(_window);
		}
Exemple #32
0
		public void Update(FrameArgs e) {
			this.OnUpdate(e);
			foreach (var view in _children)
				view.Update(e);
		}
Exemple #33
0
		protected virtual void OnUpdate(FrameArgs e) {
		}