private void SetupCameraControl()
        {
            if (_cameraControl != null)
            {
                SizeChanged -= OnSizeChanged;
            }

            _cameraControl = (CameraControl)GetTemplateChild(CAMERACONTROL_NAME);

            if (_cameraControl != null)
            {
                _compositor = _cameraControl.CompositionCamera.CameraVisual.Compositor;

                SizeChanged += OnSizeChanged;

                // World root
                var worldRoot = SetupWorldRoot();

                // Camera setup
                _cameraControl.ViewportSize = RenderSize.ToVector2();
                _cameraControl.Position     = new Vector3(0, 0, 1000);
                _cameraControl.SetAsPerspective(RenderSize.ToVector2());
                _cameraControl.PerspectiveDistance = (float)(RenderSize.Height + RenderSize.Width) / 3;

                // ImageLoader
                _surfaceFactory = SurfaceFactory.GetSharedSurfaceFactoryForCompositor(_compositor);

                // Skybox
                var halfSkyboxSize         = _skyboxSize / 2;
                var negativeHalfSkyboxSize = -_skyboxSize / 2;

                _skyboxContainer              = _compositor.CreateContainerVisual();
                _skyboxContainer.CenterPoint  = new Vector3(halfSkyboxSize, halfSkyboxSize, halfSkyboxSize);
                _skyboxContainer.AnchorPoint  = new Vector2(halfSkyboxSize, halfSkyboxSize);
                _skyboxContainer.Offset       = new Vector3(negativeHalfSkyboxSize, negativeHalfSkyboxSize, negativeHalfSkyboxSize);
                _skyboxContainer.RotationAxis = _rotationAxisY;
                _skyboxContainer.BorderMode   = CompositionBorderMode.Hard;
                _skyboxContainer.Comment      = "Skybox";

                SetupSkyboxSide(ref _skyboxTop, new Vector3(0, 0, _skyboxSize), new Uri("ms-appx:///Assets/Skybox/Clouds/CloudsTop.jpg"), "SkyboxTop");
                SetupSkyboxSide(ref _skyboxLeft, new Vector3(0, 0, _skyboxSize), new Uri("ms-appx:///Assets/Skybox/Clouds/CloudsLeft.jpg"), "SkyboxLeft");
                SetupSkyboxSide(ref _skyboxRight, new Vector3(_skyboxSize, 0, 0), new Uri("ms-appx:///Assets/Skybox/Clouds/CloudsRight.jpg"), "SkyboxRight");
                SetupSkyboxSide(ref _skyboxBottom, new Vector3(0, _skyboxSize, 0), new Uri("ms-appx:///Assets/Skybox/Clouds/CloudsBottom.jpg"), "SkyboxBottom");
                SetupSkyboxSide(ref _skyboxFront, new Vector3(0, 0, 0), new Uri("ms-appx:///Assets/Skybox/Clouds/CloudsFront.jpg"), "SkyboxFront");
                SetupSkyboxSide(ref _skyboxBack, new Vector3(0, 0, _skyboxSize), new Uri("ms-appx:///Assets/Skybox/Clouds/CloudsBack.jpg"), "SkyboxBack");

                _skyboxTop.RotationAxis    = _rotationAxisX;
                _skyboxLeft.RotationAxis   = _rotationAxisY;
                _skyboxRight.RotationAxis  = _rotationAxisY;
                _skyboxBottom.RotationAxis = _rotationAxisX;

                _skyboxTop.RotationAngleInDegrees    = -90;
                _skyboxLeft.RotationAngleInDegrees   = 90;
                _skyboxRight.RotationAngleInDegrees  = -90;
                _skyboxBottom.RotationAngleInDegrees = 90;

                // Set up items in visual tree
                worldRoot.Children.InsertAtTop(_skyboxContainer);
            }
        }
        private void SetupCameraControl()
        {
            // Unregister
            if (_cameraControl != null)
            {
                SizeChanged -= OnSizeChanged;
            }

            // Get template part
            _cameraControl = (CameraControl)GetTemplateChild(CAMERACONTROL_NAME);

            // Bail if missing
            if (_cameraControl == null)
            {
                return;
            }

            SizeChanged += OnSizeChanged;

            // Camera setup
            _cameraControl.SetAsPerspective(RenderSize.ToVector2());
            _cameraControl.Yaw   = 0;
            _cameraControl.Pitch = 0;
            _cameraControl.PerspectiveDistance = 575;
            _cameraControl.Position            = new Vector3(_stageWidth / 2, _stageBackdropHeight / 2, -1 * _stageFloorDepth / 2);

            // ImageLoader
            _compositor     = _cameraControl.CompositionCamera.CameraVisual.Compositor;
            _surfaceFactory = SurfaceFactory.GetSharedSurfaceFactoryForCompositor(_compositor);

            // Stage container
            _stageContainer              = _compositor.CreateContainerVisual();
            _stageContainer.CenterPoint  = new Vector3(_stageWidth / 2, _stageBackdropHeight / 2, _stageFloorDepth / 2);
            _stageContainer.AnchorPoint  = new Vector2(_stageWidth / 2, _stageBackdropHeight / 2);
            _stageContainer.Offset       = new Vector3(-1 * _stageWidth / 2, -1 * _stageBackdropHeight * 0.75f, -1 * _stageFloorDepth / 4);
            _stageContainer.RotationAxis = _rotationAxisY;
            _stageContainer.BorderMode   = CompositionBorderMode.Hard;
            _stageContainer.Comment      = "Stage";

            // Backdrop + Floor
            SetupStageSide(StageSide.Backdrop);
            SetupStageSide(StageSide.Floor);

            // World root
            SpriteVisual treeRoot  = _compositor.CreateSpriteVisual();
            SpriteVisual worldRoot = _compositor.CreateSpriteVisual();

            treeRoot.Comment  = "TreeRoot";
            worldRoot.Comment = "WorldRoot";

            ElementCompositionPreview.SetElementChildVisual(_cameraControl, treeRoot);
            treeRoot.Children.InsertAtTop(worldRoot);
            worldRoot.Children.InsertAtTop(_stageContainer);
        }
示例#3
0
        private void RotateProcess(Vector2 p0, Vector2 p1)
        {
            Vector2 halfRenderSize = RenderSize.ToVector2() * logicScale * 0.5f;
            Vector2 pos0           = p0 * logicScale - (halfRenderSize);
            Vector2 pos1           = p1 * logicScale - (halfRenderSize);
            float   rotateR        = MathF.Atan2(pos0.X, pos0.Y) - MathF.Atan2(pos1.X, pos1.Y);

            CanvasRect.Rotation = (CanvasRect.Rotation + rotateR) % (MathF.PI * 2);
            Matrix4x4 rotateMatrixMid = Matrix4x4.CreateTranslation(new Vector3(-halfRenderSize, 0));

            rotateMatrixMid     = Matrix4x4.Multiply(rotateMatrixMid, Matrix4x4.CreateRotationZ(rotateR));
            rotateMatrixMid     = Matrix4x4.Multiply(rotateMatrixMid, Matrix4x4.CreateTranslation(new Vector3(halfRenderSize, 0)));
            CanvasRect.Position = Vector2.Transform(CanvasRect.Position, rotateMatrixMid);
        }
示例#4
0
        private void SetupCameraControl()
        {
            // Unregister
            if (_cameraControl != null)
            {
                SizeChanged -= OnSizeChanged;
            }

            // Get template part
            _cameraControl = (CameraControl)GetTemplateChild(CAMERACONTROL_NAME);

            // Bail if missing
            if (_cameraControl == null)
            {
                return;
            }

            SizeChanged += OnSizeChanged;

            // Camera setup
            _cameraControl.SetAsPerspective(RenderSize.ToVector2());
            _cameraControl.Yaw   = 0;
            _cameraControl.Pitch = 0;
            _cameraControl.PerspectiveDistance = 575;
            _cameraControl.Position            = new Vector3(1920 / 2, 1080 / 2, 0);

            // ImageLoader
            _compositor     = _cameraControl.CompositionCamera.CameraVisual.Compositor;
            _surfaceFactory = SurfaceFactory.GetSharedSurfaceFactoryForCompositor(_compositor);

            // Skybox container
            var halfSkyboxSize         = _skyboxSize / 2;
            var negativeHalfSkyboxSize = -_skyboxSize / 2;

            _skyboxContainer              = _compositor.CreateContainerVisual();
            _skyboxContainer.CenterPoint  = new Vector3(halfSkyboxSize, halfSkyboxSize, halfSkyboxSize);
            _skyboxContainer.AnchorPoint  = new Vector2(halfSkyboxSize, halfSkyboxSize);
            _skyboxContainer.Offset       = new Vector3(negativeHalfSkyboxSize, negativeHalfSkyboxSize, negativeHalfSkyboxSize);
            _skyboxContainer.RotationAxis = _rotationAxisY;
            _skyboxContainer.BorderMode   = CompositionBorderMode.Hard;
            _skyboxContainer.Comment      = "Skybox";

            // Skybox sides
            SetupSkyboxSide(SkyboxSide.Top);
            SetupSkyboxSide(SkyboxSide.Left);
            SetupSkyboxSide(SkyboxSide.Right);
            SetupSkyboxSide(SkyboxSide.Bottom);
            SetupSkyboxSide(SkyboxSide.Front);
            SetupSkyboxSide(SkyboxSide.Back);

            // World root
            SpriteVisual treeRoot  = _compositor.CreateSpriteVisual();
            SpriteVisual worldRoot = _compositor.CreateSpriteVisual();

            treeRoot.Comment  = "TreeRoot";
            worldRoot.Comment = "WorldRoot";

            ElementCompositionPreview.SetElementChildVisual(_cameraControl, treeRoot);
            treeRoot.Children.InsertAtTop(worldRoot);
            worldRoot.Children.InsertAtTop(_skyboxContainer);

            if (AutoRotate)
            {
                // Animate for fun.
                Rotate(360, 100000);
            }
        }