Exemplo n.º 1
0
 public virtual void Initialize(DeviceManager deviceManager)
 {
     sceneColorBrush = new SolidColorBrush(deviceManager.ContextDirect2D, Colors.White);
     textFormat = new TextFormat(deviceManager.FactoryDirectWrite, "Calibri", 20) { TextAlignment = TextAlignment.Leading, ParagraphAlignment = ParagraphAlignment.Center };
     clock = Stopwatch.StartNew();
     deviceManager.ContextDirect2D.TextAntialiasMode = TextAntialiasMode.Grayscale;
 }
Exemplo n.º 2
0
        public virtual void Initialize(DeviceManager deviceManager)
        {

            sceneColorBrush = new SolidColorBrush(deviceManager.ContextDirect2D, Colors.White);

            clock = Stopwatch.StartNew();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            d2dDragHandler = new DragHandler(d2dCanvas) { CursorOver = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.SizeAll, 1) };

            d2dBrush = new ImageBrush();
            d2dRectangle.Fill = d2dBrush;

            effectRenderer = new EffectRenderer(d2dRectangle, root);
            
            deviceManager = new DeviceManager();
            
            int pixelWidth = (int)(d2dRectangle.Width * DisplayProperties.LogicalDpi / 96.0);
            int pixelHeight = (int)(d2dRectangle.Height * DisplayProperties.LogicalDpi / 96.0);

            d2dTarget = new SurfaceImageSourceTarget(pixelWidth, pixelHeight);
            d2dBrush.ImageSource = d2dTarget.ImageSource;
            d2dTarget.OnRender += effectRenderer.Render;
            
            deviceManager.OnInitialize += d2dTarget.Initialize;
            deviceManager.OnInitialize += effectRenderer.Initialize;
            deviceManager.Initialize(DisplayProperties.LogicalDpi);


            // Setup rendering callback
            CompositionTarget.Rendering += CompositionTarget_Rendering;
        }
Exemplo n.º 4
0
        public virtual void Initialize(DeviceManager deviceManager)
        {
            lock (lockObject)
            {
                // Startup MediaManager
                MediaManager.Startup();

                // Setup multithread on the Direct3D11 device
                var multithread = deviceManager.DeviceDirect3D.QueryInterface<SharpDX.Direct3D.DeviceMultithread>();
                multithread.SetMultithreadProtected(true);

                // Create a DXGI Device Manager
                dxgiDeviceManager = new DXGIDeviceManager();
                dxgiDeviceManager.ResetDevice(deviceManager.DeviceDirect3D);

                // Setup Media Engine attributes
                var attributes = new MediaEngineAttributes
                                     {
                                         DxgiManager = dxgiDeviceManager,
                                         VideoOutputFormat = (int) SharpDX.DXGI.Format.B8G8R8A8_UNorm
                                     };

                using (var factory = new MediaEngineClassFactory())
                    mediaEngine = new MediaEngine(factory, attributes, MediaEngineCreateFlags.WaitForStableState, OnMediaEngineEvent);                
                mediaEngineEx = mediaEngine.QueryInterface<MediaEngineEx>();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            _D3dBrush = new Windows.UI.Xaml.Media.ImageBrush();
            this.RenderTarget.Fill = _D3dBrush;

            _DeviceManager = new DeviceManager();            
        }
Exemplo n.º 6
0
            /// <inheritdoc/>
            public void SetWindow(CoreWindow window)
            {
                this.window = window;

                // Safely dispose any previous instance
                RemoveAndDispose(ref deviceManager);
                RemoveAndDispose(ref target);
                RemoveAndDispose(ref cubeRenderer);

                // Creates a new DeviceManager (Direct3D, Direct2D, DirectWrite, WIC)
                deviceManager = ToDispose(new DeviceManager());

                // Use CoreWindowTarget as the rendering target (Initialize SwapChain, RenderTargetView, DepthStencilView, BitmapTarget)
                target = ToDispose(new CoreWindowTarget(window));

                // New CubeRenderer
                cubeRenderer = ToDispose(new CubeRenderer());
                var fpsRenderer = new FpsRenderer();

                // Add Initializer to device manager
                deviceManager.OnInitialize += target.Initialize;
                deviceManager.OnInitialize += cubeRenderer.Initialize;
                deviceManager.OnInitialize += fpsRenderer.Initialize;

                // Render the cube within the CoreWindow
                target.OnRender += cubeRenderer.Render;
                target.OnRender += fpsRenderer.Render;

                // Initialize the device manager and all registered deviceManager.OnInitialize 
                deviceManager.Initialize(DisplayProperties.LogicalDpi);
            }
Exemplo n.º 7
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            d2dDragHandler = new DragHandler(d2dCanvas) { CursorOver = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.SizeAll, 1) };

            d2dBrush = new ImageBrush();
            d2dRectangle.Fill = d2dBrush;

            effectRenderer = new EffectRenderer();

            deviceManager = new DeviceManager();

            int pixelWidth = (int)(d2dRectangle.Width * DisplayProperties.LogicalDpi / 96.0);
            int pixelHeight = (int)(d2dRectangle.Height * DisplayProperties.LogicalDpi / 96.0);

            d2dTarget = new SurfaceImageSourceTarget(pixelWidth, pixelHeight);
            d2dBrush.ImageSource = d2dTarget.ImageSource;
            d2dTarget.OnRender += effectRenderer.Render;

            deviceManager.OnInitialize += d2dTarget.Initialize;
            deviceManager.OnInitialize += effectRenderer.Initialize;
            deviceManager.Initialize(DisplayProperties.LogicalDpi);

            var window = CoreWindow.GetForCurrentThread();
            if (window.Visible)
                BindRenderingEvents();

            window.VisibilityChanged += (_, args) =>
                                        {
                                            if (args.Visible)
                                                BindRenderingEvents();
                                            else
                                                UnbindRenderingEvents();
                                        };
        }
Exemplo n.º 8
0
 public static void CreateColors(DeviceManager deviceManager)
 {
     PlayerColor = new SolidColorBrush(deviceManager.ContextDirect2D, new Color4(0.0f, 0.8f, 0.0f, 1.0f));
     EnemyColor = new SolidColorBrush(deviceManager.ContextDirect2D, new Color4(0.8f, 0.0f, 0.0f, 1.0f));
     AdditionalColor = new SolidColorBrush(deviceManager.ContextDirect2D, new Color4(0.8f, 0.8f, 0.0f, 1.0f));
     BackgroundColor = new SolidColorBrush(deviceManager.ContextDirect2D, new Color4(0.0f, 0.0f, 0.0f, 1.0f));
     ObstaclesColor = new SolidColorBrush(deviceManager.ContextDirect2D, new Color4(1.0f, 1.0f, 1.0f, 1.0f));
 }
Exemplo n.º 9
0
        public Assets(DeviceManager deviceManager)
        {
            // Establish reference to program.
            this.deviceManager = deviceManager;

            // Initialise styles.
            styleDict[StyleType.Colored] = createColoredStyle();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var deviceManager = new DeviceManager();
            var mediaPlayer = new MediaPlayer();

            deviceManager.OnInitialize += mediaPlayer.Initialize;

            deviceManager.Initialize(DisplayProperties.LogicalDpi);

        }
Exemplo n.º 11
0
        public virtual void Initialize(DeviceManager deviceManager)
        {
            _deviceManager = deviceManager;
            sceneColorBrush = new SolidColorBrush(deviceManager.ContextDirect2D, Color.White);
            
            //GET IMAGE DATA
            _formatConverter = DecodeImage();

            //CREATE EFFECT-GRAPH USING IMAGE DATA
            UpdateEffectGraph();
        }
Exemplo n.º 12
0
        protected override void OnLaunched(LaunchActivatedEventArgs args)
        {
            if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                //TODO: Load state from previously suspended application
            }

            // Create Game Manager
            _gameManager = new GameManager();

            // Place the frame in the current Window and ensure that it is active
            _mainPage = new MainPage(_gameManager);
            Window.Current.Content = _mainPage;
            Window.Current.Activate();

            // Safely dispose any previous instance
            // Creates a new DeviceManager (Direct3D, Direct2D, DirectWrite, WIC)
            _deviceManager = new DeviceManager();

            // New CubeRenderer
            _renderer = new Renderer(_gameManager);
            //    var fpsRenderer = new FpsRenderer();

            // Use CoreWindowTarget as the rendering target (Initialize SwapChain, RenderTargetView, DepthStencilView, BitmapTarget)
            _target = new SwapChainBackgroundPanelTarget(_mainPage);

            // Add Initializer to device manager
            _deviceManager.OnInitialize += _target.Initialize;
            _deviceManager.OnInitialize += _renderer.Initialize;
             //   _deviceManager.OnInitialize += fpsRenderer.Initialize;

            // Render the cube within the CoreWindow
            _target.OnRender += _renderer.Render;
             //   _target.OnRender += fpsRenderer.Render;

            // Initialize the device manager and all registered deviceManager.OnInitialize
            _deviceManager.Initialize(DisplayProperties.LogicalDpi);

            // Setup rendering callback
            CompositionTarget.Rendering += CompositionTargetRendering;

            // Callback on DpiChanged
            DisplayProperties.LogicalDpiChanged += DisplayPropertiesLogicalDpiChanged;

            // Create colors which will be use in all games.
            GamesParams.CreateColors(_deviceManager);

            // Create Game Manager
            _gameManager.Create(_mainPage, _renderer);

            // And start first game
            _gameManager.StartSession();
        }
Exemplo n.º 13
0
        public Style(String vertexShaderFilename, String pixelShaderFilename, InputElement[] layoutElements, int floatsPerVertex, DeviceManager deviceManager)
        {
            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            // Read pre-compiled shader byte code relative to current directory
            var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\" + vertexShaderFilename);
            this.pixelShader = new PixelShader(deviceManager.DeviceDirect3D, NativeFile.ReadAllBytes(path + "\\" + pixelShaderFilename));
            this.vertexShader = new VertexShader(deviceManager.DeviceDirect3D, vertexShaderByteCode);

            // Specify the input layout for the new style
            this.layout = new InputLayout(deviceManager.DeviceDirect3D, vertexShaderByteCode, layoutElements);
            this.floatsPerVertex = floatsPerVertex;
        }
Exemplo n.º 14
0
        public Direct3DUserControl()
        {
            this.InitializeComponent();

            // do not initialize D3D in design mode as it may cause designer crashes
            if(Windows.ApplicationModel.DesignMode.DesignModeEnabled)
                return;

            // Safely dispose any previous instance
            // Creates a new DeviceManager (Direct3D, Direct2D, DirectWrite, WIC)
            deviceManager = new DeviceManager();            

            // Use current control as the rendering target (Initialize SwapChain, RenderTargetView, DepthStencilView, BitmapTarget)
            target = new SwapChainPanelTarget(this);

            // Add Initializer to device manager
            deviceManager.OnInitialize += target.Initialize;

            // New CubeRenderer
            cubeRenderer = new CubeRenderer();
            cubeRenderer.ShowCube = true;
            deviceManager.OnInitialize += cubeRenderer.Initialize;
            target.OnRender += cubeRenderer.Render;

            // New ShapeRenderer
            shapeRenderer = new ShapeRenderer();
            shapeRenderer.Show = true;
            shapeRenderer.EnableClear = false;
            deviceManager.OnInitialize += shapeRenderer.Initialize;            
            target.OnRender += shapeRenderer.Render;

            // Initialize the device manager and all registered deviceManager.OnInitialize             
            try {
                deviceManager.Initialize(DisplayInformation.GetForCurrentView().LogicalDpi);
                DisplayInformation.GetForCurrentView().DpiChanged += DisplayProperties_LogicalDpiChanged;
            } catch (Exception ex) {
                //DisplayInformation.GetForCurrentView() will throw exception in designer
                deviceManager.Initialize(96.0f);
            }

            // Setup rendering callback
            CompositionTargetEx.Rendering += CompositionTarget_Rendering;

            this.LayoutUpdated += Direct3DUserControl_LayoutUpdated;
        }
Exemplo n.º 15
0
            /// <inheritdoc/>
            public void SetWindow(CoreWindow window)
            {
                this.window = window;

                // Safely dispose any previous instance
                RemoveAndDispose(ref deviceManager);
                RemoveAndDispose(ref target);
                RemoveAndDispose(ref cubeRenderer);

                // Creates a new DeviceManager (Direct3D, Direct2D, DirectWrite, WIC)
                deviceManager = ToDispose(new DeviceManager());

                // Use CoreWindowTarget as the rendering target (Initialize SwapChain, RenderTargetView, DepthStencilView, BitmapTarget)
                target = ToDispose(new CoreWindowTarget(window));

                // New CubeRenderer
                cubeRenderer = ToDispose(new CubeTextureRenderer());
            }
Exemplo n.º 16
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs args)
        {
            if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                //TODO: Load state from previously suspended application
            }

            // Safely dispose any previous instance
            // Creates a new DeviceManager (Direct3D, Direct2D, DirectWrite, WIC)
            deviceManager = new DeviceManager();

            // New CubeRenderer
            cubeRenderer = new CubeRenderer();
            cubeRenderer.ShowCube = true;
            shapeRenderer = new ShapeRenderer();
            shapeRenderer.Show = false;
            shapeRenderer.EnableClear = false;

            // Place the frame in the current Window and ensure that it is active
            var swapchainPanel = new DirectXPanelXaml(cubeRenderer, shapeRenderer);
            Window.Current.Content = swapchainPanel;
            Window.Current.Activate();

            // Use CoreWindowTarget as the rendering target (Initialize SwapChain, RenderTargetView, DepthStencilView, BitmapTarget)
            target = new SwapChainBackgroundPanelTarget(swapchainPanel);

            // Add Initializer to device manager
            deviceManager.OnInitialize += target.Initialize;
            deviceManager.OnInitialize += cubeRenderer.Initialize;
            deviceManager.OnInitialize += shapeRenderer.Initialize;

            // Render the cube within the CoreWindow
            target.OnRender += cubeRenderer.Render;
            target.OnRender += shapeRenderer.Render;

            // Initialize the device manager and all registered deviceManager.OnInitialize 
            deviceManager.Initialize(DisplayProperties.LogicalDpi);

            // Setup rendering callback
            CompositionTarget.Rendering += CompositionTarget_Rendering;

            // Callback on DpiChanged
            DisplayProperties.LogicalDpiChanged += DisplayProperties_LogicalDpiChanged;
        }
Exemplo n.º 17
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            DeviceManager = new CommonDX.DeviceManager();
            D2DBrush = new ImageBrush();
            v_renderTarget.Fill = D2DBrush;

            D2DTarget = new SurfaceImageSourceTarget((int) (v_renderTarget.Width * DisplayProperties.LogicalDpi / 96.0),
                                                     (int) (v_renderTarget.Height * DisplayProperties.LogicalDpi / 96.0));

            D2DBrush.ImageSource = D2DTarget.ImageSource;

            DeviceManager.OnInitialize += D2DTarget.Initialize;

            D2DTarget.OnRender += MainViewModel.Render;

            DeviceManager.Initialize(DisplayProperties.LogicalDpi);

            CompositionTarget.Rendering += PerformRender;
        }
Exemplo n.º 18
0
        public MPSCBP()
        {
            this.InitializeComponent();

            effectRenderer = new EffectRenderer(root, root);
            var fpsRenderer = new FpsRenderer();

            d2dTarget = new SwapChainPanelTarget(root);
            d2dTarget.OnRender += effectRenderer.Render;
            d2dTarget.OnRender += fpsRenderer.Render;

            deviceManager = new DeviceManager();
            deviceManager.OnInitialize += d2dTarget.Initialize;
            deviceManager.OnInitialize += effectRenderer.Initialize;
            deviceManager.OnInitialize += fpsRenderer.Initialize;

            deviceManager.Initialize(DisplayProperties.LogicalDpi);

            // Setup rendering callback
            CompositionTarget.Rendering += CompositionTarget_Rendering;
        }
Exemplo n.º 19
0
        public virtual void Update(DeviceContext context, TargetBase target, DeviceManager deviceManager, Point screenSize, float dt, float elapsedTime)
        {
            context.DrawRectangle(screenSize.ApplyTo(GamesParams.Margin0.ToRectangleWith(GamesParams.Margin1)), GamesParams.ObstaclesColor, 2);

            _gameTime += dt;

            if (!_gameManager.IsTraining)
            {
                const float u = 1.00f;
                if (_gameTime < u && !AfterStartFreeze)
                {
                    var op = 1 - _gameTime / u;
                    var hideBrush = new SolidColorBrush(deviceManager.ContextDirect2D, Colors.White,
                                                        new BrushProperties { Opacity = op });
                    context.FillRectangle(screenSize.ApplyTo(new RectangleF(0, 0, 1, 1)), hideBrush);
                }
                else
                {
                    AfterStartFreeze = true;
                }

                if (_gameTime > _gameMaxTime - u)
                {
                    var op = 1 - (_gameMaxTime - _gameTime) / u;
                    var hideBrush = new SolidColorBrush(deviceManager.ContextDirect2D, Colors.White,
                                                        new BrushProperties { Opacity = op });
                    context.FillRectangle(screenSize.ApplyTo(new RectangleF(0, 0, 1, 1)), hideBrush);
                }

                float bar;
                bar = _gameManager.IsTraining ? 1 : _gameTime / _gameMaxTime;
                _gameManager.Page.SetTimeRectangleWidth(bar);
                _gameManager.RedrawPointsAndLifes();

                if (_gameTime > _gameMaxTime)
                    _gameManager.Win(100);
            }
        }
Exemplo n.º 20
0
        private void Init()
        {
            // Safely dispose any previous instance
            // Creates a new DeviceManager (Direct3D, Direct2D, DirectWrite, WIC)
            deviceManager = new DeviceManager();

            // New CubeRenderer
            cubeRenderer = new CubeRenderer();
            cubeRenderer.ShowCube = true;
            shapeRenderer = new ShapeRenderer();
            shapeRenderer.Show = false;
            shapeRenderer.EnableClear = false;


            // Use CoreWindowTarget as the rendering target (Initialize SwapChain, RenderTargetView, DepthStencilView, BitmapTarget)
            target = new SwapChainPanelTarget(scpMain);

            // Add Initializer to device manager
            deviceManager.OnInitialize += target.Initialize;
            deviceManager.OnInitialize += cubeRenderer.Initialize;
            deviceManager.OnInitialize += shapeRenderer.Initialize;

            // Render the cube within the CoreWindow
            target.OnRender += cubeRenderer.Render;
            target.OnRender += shapeRenderer.Render;

            // Initialize the device manager and all registered deviceManager.OnInitialize 
            deviceManager.Initialize(DisplayProperties.LogicalDpi);

            // Setup rendering callback
            CompositionTarget.Rendering += CompositionTarget_Rendering;

            // Callback on DpiChanged
            DisplayProperties.LogicalDpiChanged += DisplayProperties_LogicalDpiChanged;

            
        }
Exemplo n.º 21
0
 /// <inveritdoc/>
 public override void Initialize(DeviceManager deviceManager)
 {
     base.Initialize(deviceManager);
     surfaceImageSourceNative.Device = DeviceManager.DeviceDirect3D.QueryInterface <SharpDX.DXGI.Device>();
 }
Exemplo n.º 22
0
        public void Initialize(CommonDX.DeviceManager deviceManager)
        {
            _deviceManager = deviceManager;
            _d2dContext    = deviceManager.ContextDirect2D;

            _generalGrayColor       = new SharpDX.Direct2D1.SolidColorBrush(_deviceManager.ContextDirect2D, Color.Gray);
            _generalRedColor        = new SharpDX.Direct2D1.SolidColorBrush(_deviceManager.ContextDirect2D, Color.Red);
            _generalLightGrayColor  = new SharpDX.Direct2D1.SolidColorBrush(_deviceManager.ContextDirect2D, Color.LightGray);
            _generalLightWhiteColor = new SharpDX.Direct2D1.SolidColorBrush(_deviceManager.ContextDirect2D, Color.White);

            _generalTextFormat = new SharpDX.DirectWrite.TextFormat(
                _deviceManager.FactoryDirectWrite,
                "Segoe UI",
                SharpDX.DirectWrite.FontWeight.Light,
                SharpDX.DirectWrite.FontStyle.Normal,
                SharpDX.DirectWrite.FontStretch.Normal,
                16f);

            _debugTextFormat = new SharpDX.DirectWrite.TextFormat(
                _deviceManager.FactoryDirectWrite,
                "Segoe UI",
                SharpDX.DirectWrite.FontWeight.Light,
                SharpDX.DirectWrite.FontStyle.Normal,
                SharpDX.DirectWrite.FontStretch.Normal,
                20f);

            _layoutDetail = new LayoutDetail()
            {
                Width = this.State.DrawingSurfaceWidth, Height = this.State.DrawingSurfaceHeight
            };
            _layoutDeviceScreenSize = new RectangleF(0, 0, (float)_layoutDetail.Width, (float)_layoutDetail.Height);
            _appWidth  = (float)_layoutDetail.Width + 5;
            _appHeight = (float)_layoutDetail.Height;

            _updateScaleTranslate(1.0f);


            ////_drawTiles(0);
            if (State.DefaultBackgroundUri != string.Empty)
            {
                _clearRenderTree();
                _changeBackgroundImpl(1, _appWidth, _appHeight, 0, 0, State.DefaultBackgroundFolder, State.DefaultBackgroundUri, "", Color.White, 0.7f, "", false);
            }

            //GestureService.OnGestureRaised += (o,a) => {
            //    CustomGestureArgs gestureArgs = (CustomGestureArgs)a;
            //    //NumberFramesToRender += 3;
            //    if (gestureArgs.ManipulationStartedArgs != null)
            //    {
            //        _isInertialTranslationStaging = false;
            //        _globalCameraTranslationStaging = _globalCameraTranslation;
            //    }
            //    else if (gestureArgs.ManipulationInertiaStartingArgs != null)
            //    {
            //        _isInertialTranslationStaging = true;
            //        _globalCameraTranslationStaging = _globalCameraTranslation;
            //    }
            //    else if (gestureArgs.ManipulationUpdatedArgs != null)
            //    {
            //        if(_isInertialTranslationStaging)
            //            _updateCameraTranslationStaging((float)gestureArgs.ManipulationUpdatedArgs.Velocities.Linear.X);
            //        else
            //            _updateCameraTranslationStaging((float)gestureArgs.ManipulationUpdatedArgs.Cumulative.Translation.X);
            //    }
            //    else if (gestureArgs.ManipulationCompletedArgs != null)
            //    {
            //        if (gestureArgs.ManipulationCompletedArgs.Cumulative.Scale < 1)
            //        {
            //            if (_globalScale.X != 0.9f) { _updateBackgroundTweener(1.0f, 0.9f, 1.2f); SendInformationNotification("zoom level at 90%", 3); }
            //            //_updateScaleTranslate(0.9f);
            //        }
            //        else if (gestureArgs.ManipulationCompletedArgs.Cumulative.Scale > 1)
            //        {
            //            if (_globalScale.X != 1.0f) { _updateBackgroundTweener(0.9f, 1.0f, 1.2f); SendInformationNotification("zoom level at 100%", 3); }
            //            //_updateScaleTranslate(1.0f);
            //        }

            //        _globalCameraTranslation = _globalCameraTranslation + _globalCameraTranslationStaging;
            //        _globalCameraTranslationStaging = Vector3.Zero;
            //        _isInertialTranslationStaging = false;

            //    }
            //    else if (gestureArgs.TappedEventArgs != null)
            //    {
            //        var x = gestureArgs.TappedEventArgs.Position.X - _globalCameraTranslation.X;
            //        var y = gestureArgs.TappedEventArgs.Position.Y - _globalCameraTranslation.Y;

            //        var found = _doTilesHitTest((float)x, (float)y);
            //        if (found != null && found.Count > 0)
            //        {
            //            _selectedRect = found[0];
            //        }
            //        else _selectedRect = null;
            //    }
            //};


            WindowLayoutService.OnWindowLayoutRaised += WindowLayoutService_OnWindowLayoutRaised;
        }
Exemplo n.º 23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScreenDisplay"/> class.
        /// </summary>
        public ScreenDisplay()
        {
            this.rectangle = new Rectangle();
            this.border = new Border()
            {
                Child = this.rectangle
            };

            this.border.BorderBrush = new SolidColorBrush(Colors.Black);
            this.border.BorderThickness = new Thickness(2d);
            this.border.Background = new SolidColorBrush(Colors.Black);

            this.Content = border;

            this.IsTabStop = true;
            this.IsTapEnabled = true;
            this.ManipulationMode = ManipulationModes.TranslateY | ManipulationModes.TranslateInertia;

            this.ColorTheme = ColorThemeData.CreateDefault();
            this.RecalculateFontMetrics();

            this.deviceManager = new DeviceManager();
        }
Exemplo n.º 24
0
        public virtual void Initialize(DeviceManager deviceManager)
        {
            _deviceManager = deviceManager;
            sceneColorBrush = new SolidColorBrush(deviceManager.ContextDirect2D, Color.White);
            
            //GET IMAGE DATA
            _formatConverter = DecodeImage();

            //DEFAULTS MAY NEED THIS DATA
            var size = deviceManager.ContextDirect2D.Size;
            int pixelWidth = (int)(size.Width * Windows.Graphics.Display.DisplayProperties.LogicalDpi / 96.0);
            int pixelHeight = (int)(size.Height * Windows.Graphics.Display.DisplayProperties.LogicalDpi / 96.0);


            //CREATE EFFECT-GRAPH USING IMAGE DATA
            Scale = new Vector2(0.8f, 0.8f);
            BlurDeviation = 0f;
            _lightPositionZ = 100f;
            PointsAt = new Vector3(pixelWidth / 2, pixelHeight / 2, 0.0f);


            UpdateEffectGraph();

        }
Exemplo n.º 25
0
 private void devices_OnDpiChanged(DeviceManager obj)
 {
     if (OnSizeChanged != null)
         OnSizeChanged(this);
 }
Exemplo n.º 26
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <param name="deviceManager">The device manager</param>
        public virtual void Initialize(DeviceManager deviceManager) {
            this.DeviceManager = deviceManager;

            // If the DPI is changed, we need to perform a OnSizeChanged event
            deviceManager.OnDpiChanged -= devices_OnDpiChanged;
            deviceManager.OnDpiChanged += devices_OnDpiChanged;
        }
Exemplo n.º 27
0
        public virtual void Initialize(DeviceManager devices)
        {
            // Remove previous buffer
            RemoveAndDispose(ref constantBuffer);

            // Setup local variables
            var d3dDevice = devices.DeviceDirect3D;
            var d3dContext = devices.ContextDirect3D;

            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            // Loads vertex shader bytecode
            var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\MiniCubeTexture_VS.fxo");
            vertexShader = new VertexShader(d3dDevice, vertexShaderByteCode);

            // Loads pixel shader bytecode
            pixelShader = new PixelShader(d3dDevice, NativeFile.ReadAllBytes(path + "\\MiniCubeTexture_PS.fxo"));

            // Layout from VertexShader input signature
            layout = new InputLayout(d3dDevice, vertexShaderByteCode, new[]
                    {
                        new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                        new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0)
                    });

            // Instantiate Vertex buiffer from vertex data
            var vertices = SharpDX.Direct3D11.Buffer.Create(d3dDevice, BindFlags.VertexBuffer, new[]
                                  {
                                      // 3D coordinates              UV Texture coordinates
                                      -1.0f, -1.0f, -1.0f, 1.0f,     0.0f, 1.0f, // Front
                                      -1.0f,  1.0f, -1.0f, 1.0f,     0.0f, 0.0f,
                                       1.0f,  1.0f, -1.0f, 1.0f,     1.0f, 0.0f,
                                      -1.0f, -1.0f, -1.0f, 1.0f,     0.0f, 1.0f,
                                       1.0f,  1.0f, -1.0f, 1.0f,     1.0f, 0.0f,
                                       1.0f, -1.0f, -1.0f, 1.0f,     1.0f, 1.0f,

                                      -1.0f, -1.0f,  1.0f, 1.0f,     1.0f, 0.0f, // BACK
                                       1.0f,  1.0f,  1.0f, 1.0f,     0.0f, 1.0f,
                                      -1.0f,  1.0f,  1.0f, 1.0f,     1.0f, 1.0f,
                                      -1.0f, -1.0f,  1.0f, 1.0f,     1.0f, 0.0f,
                                       1.0f, -1.0f,  1.0f, 1.0f,     0.0f, 0.0f,
                                       1.0f,  1.0f,  1.0f, 1.0f,     0.0f, 1.0f,

                                      -1.0f, 1.0f, -1.0f,  1.0f,     0.0f, 1.0f, // Top
                                      -1.0f, 1.0f,  1.0f,  1.0f,     0.0f, 0.0f,
                                       1.0f, 1.0f,  1.0f,  1.0f,     1.0f, 0.0f,
                                      -1.0f, 1.0f, -1.0f,  1.0f,     0.0f, 1.0f,
                                       1.0f, 1.0f,  1.0f,  1.0f,     1.0f, 0.0f,
                                       1.0f, 1.0f, -1.0f,  1.0f,     1.0f, 1.0f,

                                      -1.0f,-1.0f, -1.0f,  1.0f,     1.0f, 0.0f, // Bottom
                                       1.0f,-1.0f,  1.0f,  1.0f,     0.0f, 1.0f,
                                      -1.0f,-1.0f,  1.0f,  1.0f,     1.0f, 1.0f,
                                      -1.0f,-1.0f, -1.0f,  1.0f,     1.0f, 0.0f,
                                       1.0f,-1.0f, -1.0f,  1.0f,     0.0f, 0.0f,
                                       1.0f,-1.0f,  1.0f,  1.0f,     0.0f, 1.0f,

                                      -1.0f, -1.0f, -1.0f, 1.0f,     0.0f, 1.0f, // Left
                                      -1.0f, -1.0f,  1.0f, 1.0f,     0.0f, 0.0f,
                                      -1.0f,  1.0f,  1.0f, 1.0f,     1.0f, 0.0f,
                                      -1.0f, -1.0f, -1.0f, 1.0f,     0.0f, 1.0f,
                                      -1.0f,  1.0f,  1.0f, 1.0f,     1.0f, 0.0f,
                                      -1.0f,  1.0f, -1.0f, 1.0f,     1.0f, 1.0f,

                                       1.0f, -1.0f, -1.0f, 1.0f,     1.0f, 0.0f, // Right
                                       1.0f,  1.0f,  1.0f, 1.0f,     0.0f, 1.0f,
                                       1.0f, -1.0f,  1.0f, 1.0f,     1.0f, 1.0f,
                                       1.0f, -1.0f, -1.0f, 1.0f,     1.0f, 0.0f,
                                       1.0f,  1.0f, -1.0f, 1.0f,     0.0f, 0.0f,
                                       1.0f,  1.0f,  1.0f, 1.0f,     0.0f, 1.0f,
                            });

            vertexBufferBinding = new VertexBufferBinding(vertices, sizeof(float) * 6, 0);

            // Create Constant Buffer
            constantBuffer = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));

            // Load texture and create sampler
            using (var bitmap = TextureLoader.LoadBitmap(devices.WICFactory, "GeneticaMortarlessBlocks.jpg"))
            using (var texture2D = TextureLoader.CreateTexture2DFromBitmap(d3dDevice, bitmap))
                textureView = new ShaderResourceView(d3dDevice, texture2D);

            sampler = new SamplerState(d3dDevice, new SamplerStateDescription()
            {
                Filter = Filter.MinMagMipLinear,
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                BorderColor = Color.Black,
                ComparisonFunction = Comparison.Never,
                MaximumAnisotropy = 16,
                MipLodBias = 0,
                MinimumLod =-float.MaxValue,
                MaximumLod = float.MaxValue
            });

            clock = new Stopwatch();
            clock.Start();
        }
Exemplo n.º 28
0
 /// <inveritdoc/>
 public override void Initialize(DeviceManager deviceManager)
 {
     base.Initialize(deviceManager);
     surfaceImageSourceNative.Device = ToDispose(DeviceManager.DeviceDirect3D.QueryInterface<SharpDX.DXGI.Device>());
 }
Exemplo n.º 29
0
 public void Initialise(IImmlElement context, DeviceManager deviceManager)
 {
     _Context = context as ImmlDocument;
 }
Exemplo n.º 30
0
        public virtual void Initialize(DeviceManager devices)
        {
            // Remove previous buffer
            RemoveAndDispose(ref constantBuffer);

            // Setup local variables
            var d3dDevice = devices.DeviceDirect3D;
            var d3dContext = devices.ContextDirect3D;

            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            // Loads vertex shader bytecode
            var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\MiniCube_VS.fxo");
            vertexShader = new VertexShader(d3dDevice, vertexShaderByteCode);

            // Loads pixel shader bytecode
            pixelShader = new PixelShader(d3dDevice, NativeFile.ReadAllBytes(path + "\\MiniCube_PS.fxo"));

            // Layout from VertexShader input signature
            layout = new InputLayout(d3dDevice, vertexShaderByteCode, new[]
                    {
                        new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                        new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
                    });

            // Instantiate Vertex buffer from vertex data
            var vertices = SharpDX.Direct3D11.Buffer.Create(d3dDevice, BindFlags.VertexBuffer, new[]
                                  {
                                      new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), // Front
                                      new Vector4(-1.0f,  1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                                      new Vector4( 1.0f,  1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                                      new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                                      new Vector4( 1.0f,  1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                                      new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),

                                      new Vector4(-1.0f, -1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), // BACK
                                      new Vector4( 1.0f,  1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                                      new Vector4(-1.0f,  1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                                      new Vector4(-1.0f, -1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                                      new Vector4( 1.0f, -1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                                      new Vector4( 1.0f,  1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),

                                      new Vector4(-1.0f, 1.0f, -1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f), // Top
                                      new Vector4(-1.0f, 1.0f,  1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                                      new Vector4( 1.0f, 1.0f,  1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                                      new Vector4(-1.0f, 1.0f, -1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                                      new Vector4( 1.0f, 1.0f,  1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                                      new Vector4( 1.0f, 1.0f, -1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),

                                      new Vector4(-1.0f,-1.0f, -1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f), // Bottom
                                      new Vector4( 1.0f,-1.0f,  1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                                      new Vector4(-1.0f,-1.0f,  1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                                      new Vector4(-1.0f,-1.0f, -1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                                      new Vector4( 1.0f,-1.0f, -1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                                      new Vector4( 1.0f,-1.0f,  1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),

                                      new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f), // Left
                                      new Vector4(-1.0f, -1.0f,  1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                                      new Vector4(-1.0f,  1.0f,  1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                                      new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                                      new Vector4(-1.0f,  1.0f,  1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                                      new Vector4(-1.0f,  1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),

                                      new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f), // Right
                                      new Vector4( 1.0f,  1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                                      new Vector4( 1.0f, -1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                                      new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                                      new Vector4( 1.0f,  1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                                      new Vector4( 1.0f,  1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                            });

            vertexBufferBinding = new VertexBufferBinding(vertices, Utilities.SizeOf<Vector4>() * 2, 0);

            // Create Constant Buffer
            constantBuffer = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));

            clock = new Stopwatch();
            clock.Start();
        }
Exemplo n.º 31
0
        /// <summary>
        /// Initializes the renderer.
        /// </summary>
        /// <param name="deviceManager">The DirectX device manager.</param>
        public virtual void Initialize(DeviceManager deviceManager)
        {
            this.physicalFontMetrics = this.screenDisplay.FontMetrics * (DisplayInformation.GetForCurrentView().LogicalDpi / 96.0f);

            //deviceManager.ContextDirect2D.TextAntialiasMode = TextAntialiasMode.Grayscale;
            deviceManager.ContextDirect2D.AntialiasMode = AntialiasMode.Aliased;
            this.textFormatNormal = new TextFormat(deviceManager.FactoryDirectWrite, this.screenDisplay.ColorTheme.FontFamily, FontWeight.Normal, FontStyle.Normal, this.physicalFontMetrics.FontSize) { TextAlignment = TextAlignment.Leading, ParagraphAlignment = ParagraphAlignment.Near, WordWrapping = WordWrapping.NoWrap };
            this.textFormatBold = new TextFormat(deviceManager.FactoryDirectWrite, this.screenDisplay.ColorTheme.FontFamily, FontWeight.Bold, FontStyle.Normal, this.physicalFontMetrics.FontSize) { TextAlignment = TextAlignment.Leading, ParagraphAlignment = ParagraphAlignment.Near, WordWrapping = WordWrapping.NoWrap };
        }
Exemplo n.º 32
0
        public override void Update(DeviceContext context, TargetBase target, DeviceManager deviceManager, Point screenSize, float dt, float elapsedTime)
        {
            if (AfterStartFreeze)
            {
                // Player moving
                _playerPos =
                    _playerPos.Add(_playerDir.Mul(_playerSpd).Mul(dt)).Clamp(GamesParams.Margin0.Add(_padSize.Half()),
                                                                             GamesParams.Margin1.Sub(_padSize.Half()));

                // Ball moving
                _ballPos = _ballPos.Add(_ballDir.Mul(_ballSpd).Mul(dt));

                // Ball collision with borders
                if (!_ballPos.IsInside(GamesParams.Margin0.Add(_ballSize.Half()),
                                       GamesParams.Margin1.Sub(_ballSize.Half())))
                {
                    _ballDir.Y = -_ballDir.Y;

                    if (_ballPos.X < GamesParams.MarginX0 + 0.001f)
                    {
                        NewGame();
                        _gameManager.Die();
                        return;
                    }

                    if (_ballPos.X > GamesParams.MarginX1 - 0.001f)
                    {
                        _gameManager.Win(500);
                        _ballPos = new Point(0.5f, 0.5f);
                        _ballDir = new Point(1.0f, 0.0f).AddNoise().Normalise();
                        return;
                    }
                }

                _ballPos = _ballPos.Clamp(GamesParams.Margin0.Add(_ballSize.Half()),
                                          GamesParams.Margin1.Sub(_ballSize.Half()));

                // Ball collision with player pad
                if (_ballPos.IsInside(_playerPos.Sub(_padSize.Half()).Sub(_ballSize.Half()),
                                      _playerPos.Add(_padSize.Half()).Add(_ballSize.Half())))
                {
                    _ballDir.X = 1;
                    _ballDir.Y = _ballPos.Sub(_playerPos).Y/_padSize.Half().Y;
                    _ballDir = _ballDir.Normalise();

                    _ballSpd += _ballSpdInc;

                    _gameManager.AddPoints(75);
                }

                // Ball collision with enemy pad
                if (_ballPos.IsInside(_enemyPos.Sub(_padSize.Half()).Sub(_ballSize.Half()),
                                      _enemyPos.Add(_padSize.Half()).Add(_ballSize.Half())))
                {
                    _ballDir.X = -1;
                    _ballDir.Y = _ballPos.Sub(_enemyPos).Y/_padSize.Half().Y;
                    _ballDir = _ballDir.Normalise();

                    _ballSpd += _ballSpdInc;
                }

                // Enemy moving
                if (Math.Abs(_ballPos.Y - _enemyPos.Y) < _padSize.Div(3).Y)
                {
                    _enemyDir.Y = 0;
                }
                else
                {
                    if (_ballPos.Y > _enemyPos.Y)
                        _enemyDir.Y = 1;
                    else
                        _enemyDir.Y = -1;

                    _enemyPos =
                        _enemyPos.Add(_enemyDir.Mul(_enemySpd).Mul(dt)).Clamp(GamesParams.Margin0.Add(_padSize.Half()),
                                                                              GamesParams.Margin1.Sub(_padSize.Half()));
                }
            }

            // Drawing
            var playerBox = _playerPos.ToBox(_padSize);
            var enemyBox = _enemyPos.ToBox(_padSize);
            var ballBox = _ballPos.ToBox(_ballSize);

            context.FillRectangle(screenSize.ApplyTo(playerBox), GamesParams.PlayerColor);
            context.FillRectangle(screenSize.ApplyTo(enemyBox), GamesParams.EnemyColor);

            context.FillRectangle(screenSize.ApplyTo(ballBox), GamesParams.AdditionalColor);

            base.Update(context, target, deviceManager, screenSize, dt, elapsedTime);
        }