Example #1
0
        void Recalculate()
        {
            FractionTransform2D rotate        = FractionTransform2D.Identity;
            FractionTransform2D inverseRotate = FractionTransform2D.Identity;

            // Setup projection matrix and client size
            switch (orientation)
            {
            case UIInterfaceOrientation.Portrait:
                projection = Matrix.Identity;
                // rotation matrix is identity
                ClientSize = deviceSize;
                break;

            case UIInterfaceOrientation.PortraitUpsideDown:
                projection = Matrix.CreateRotationZ(MathHelper.Pi);
                rotate     = inverseRotate = FractionTransform2D.CreateRotation(-1, 0);
                ClientSize = deviceSize;
                break;

            case UIInterfaceOrientation.LandscapeLeft:
                projection    = Matrix.CreateRotationZ(MathHelper.PiOver2);
                rotate        = FractionTransform2D.CreateRotation(0, 1);
                inverseRotate = FractionTransform2D.CreateRotation(0, -1);
                ClientSize    = new Point(deviceSize.Y, deviceSize.X);
                break;

            case UIInterfaceOrientation.LandscapeRight:
                projection    = Matrix.CreateRotationZ(3 * MathHelper.PiOver2);
                rotate        = FractionTransform2D.CreateRotation(0, -1);
                inverseRotate = FractionTransform2D.CreateRotation(0, 1);
                ClientSize    = new Point(deviceSize.Y, deviceSize.X);
                break;
            }

            // Setup transformation matrices:
            // Orthographic projection into projection space, use orientation projection matrix,
            // inverse orthographic project back to new client space
            logicalToRender = FractionTransform2D.CreateOrthographic(0, ClientSize.X, ClientSize.Y, 0)
                              * rotate * FractionTransform2D.CreateOrthographicInverse(0, renderbufferSize.X, 0, renderbufferSize.Y);
            touchToLogical = FractionTransform2D.CreateOrthographic(0, deviceSize.X, deviceSize.Y, 0)
                             * inverseRotate * FractionTransform2D.CreateOrthographicInverse(0, ClientSize.X, ClientSize.Y, 0);

            // Setup asset load scale
            float deviceScale = Math.Max((float)renderbufferSize.X / (float)deviceSize.X, (float)renderbufferSize.Y / (float)deviceSize.Y);

            AssetLoadScale = deviceScale > 1.5f ? 2 : 1;

            if (Changed != null)
            {
                Changed();
            }
        }
Example #2
0
        void Recalculate()
        {
            FractionTransform2D rotate = FractionTransform2D.Identity;
            FractionTransform2D inverseRotate = FractionTransform2D.Identity;

            if(!systemHandlesOrientationItself)
            {
                // Setup projection matrix and client size
                switch(orientation)
                {
                    case ExEnInterfaceOrientation.Portrait:
                        projection = Matrix.Identity;
                        // rotation matrix is identity
                        ClientSize = deviceSize;
                        break;

                    case ExEnInterfaceOrientation.PortraitUpsideDown:
                        projection = Matrix.CreateRotationZ(MathHelper.Pi);
                        rotate = inverseRotate = FractionTransform2D.CreateRotation(-1, 0);
                        ClientSize = deviceSize;
                        break;

                    case ExEnInterfaceOrientation.LandscapeLeft:
                        projection = Matrix.CreateRotationZ(MathHelper.PiOver2);
                        rotate = FractionTransform2D.CreateRotation(0, 1);
                        inverseRotate = FractionTransform2D.CreateRotation(0, -1);
                        ClientSize = new Point(deviceSize.Y, deviceSize.X);
                        break;

                    case ExEnInterfaceOrientation.LandscapeRight:
                        projection = Matrix.CreateRotationZ(3 * MathHelper.PiOver2);
                        rotate = FractionTransform2D.CreateRotation(0, -1);
                        inverseRotate = FractionTransform2D.CreateRotation(0, 1);
                        ClientSize = new Point(deviceSize.Y, deviceSize.X);
                        break;
                }
            }
            else
            {
                projection = Matrix.Identity;
                ClientSize = deviceSize;
            }

            // Setup transformation matrices:
            // Orthographic projection into projection space, use orientation projection matrix,
            // inverse orthographic project back to new client space
            logicalToRender = FractionTransform2D.CreateOrthographic(0, ClientSize.X, ClientSize.Y, 0)
                    * rotate * FractionTransform2D.CreateOrthographicInverse(0, renderbufferSize.X, 0, renderbufferSize.Y);
            touchToLogical = FractionTransform2D.CreateOrthographic(0, deviceSize.X, deviceSize.Y, 0)
                    * inverseRotate * FractionTransform2D.CreateOrthographicInverse(0, ClientSize.X, ClientSize.Y, 0);

            // Setup asset load scale
            float deviceScale = Math.Max((float)renderbufferSize.X / (float)deviceSize.X, (float)renderbufferSize.Y / (float)deviceSize.Y);
            AssetLoadScale = deviceScale > 1.5f ? 2 : 1;

            if(Changed != null)
                Changed();
        }