Exemplo n.º 1
0
        public Matrix3D GetTransformationMatrix()
        {
            //Matrix3D scaleMatrix = new Matrix3D(_scale.X, 0, 0, 0, 0, _scale.Y, 0, 0, 0, 0, _scale.Z, 0, 0, 0, 0, 1);
            //Matrix3D xRotationMatrix = new Matrix3D(1, 0, 0, 0, 0, (float)Math.Cos(_rotation.X), (float)-Math.Sin(_rotation.X), 0, 0, (float)Math.Sin(_rotation.X), (float)Math.Cos(_rotation.X), 0, 0, 0, 0, 1);
            //Matrix3D yRotationMatrix = new Matrix3D((float)Math.Cos(_rotation.Y), 0, (float)Math.Sin(_rotation.Y), 0, 0, 1, 0, 0, (float)-Math.Sin(_rotation.Y), 0, (float)Math.Cos(_rotation.Y), 0, 0, 0, 0, 1);
            //Matrix3D zRotationMatrix = new Matrix3D((float)Math.Cos(_rotation.Z), (float)-Math.Sin(_rotation.Z), 0, 0, (float)Math.Sin(_rotation.Z), (float)Math.Cos(_rotation.Z), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
            //Matrix3D translateMatrix = new Matrix3D(1, 0, 0, _position.X, 0, 1, 0, _position.Y, 0, 0, 1, _position.Z, 0, 0, 0, 1);

            //Matrix3D transformationMatrix = scaleMatrix * xRotationMatrix * yRotationMatrix * zRotationMatrix * translateMatrix;

            //return transformationMatrix;

            Matrix3D scaleMatrix     = Matrix3D.CreateScale(_scale);
            Matrix3D xRotationMatrix = Matrix3D.CreateRotationX(MathUtility.ToRadians(_rotation.X));
            Matrix3D yRotationMatrix = Matrix3D.CreateRotationY(MathUtility.ToRadians(_rotation.Y));
            Matrix3D zRotationMatrix = Matrix3D.CreateRotationZ(MathUtility.ToRadians(_rotation.Z));
            Matrix3D translateMatrix = Matrix3D.CreateTranslation(_position.X, _position.Y, _position.Z);

            Matrix3D transformationMatrix = scaleMatrix * zRotationMatrix * yRotationMatrix * xRotationMatrix * translateMatrix;

            //Matrix3D transformationMatrix = scaleMatrix * xRotationMatrix * yRotationMatrix * zRotationMatrix * translateMatrix;
            //Matrix3D transformationMatrix = translateMatrix * zRotationMatrix * yRotationMatrix * xRotationMatrix * scaleMatrix;

            return(transformationMatrix);
        }
Exemplo n.º 2
0
        public void CanCreateScaleMatrixWithSingleScaleValue()
        {
            const float scale       = 2;
            Matrix3D    scaleMatrix = Matrix3D.CreateScale(scale);

            AssertMatricesAreEqual(Matrix.Scaling(scale, scale, scale), scaleMatrix);
        }
Exemplo n.º 3
0
        public void CanCreateScaleMatrixWithIndividualScaleValues()
        {
            const float x           = 2;
            const float y           = 3;
            const float z           = 4;
            Matrix3D    scaleMatrix = Matrix3D.CreateScale(x, y, z);

            AssertMatricesAreEqual(Matrix.Scaling(x, y, z), scaleMatrix);
        }
Exemplo n.º 4
0
        private void UpdateOpenedBookTransform(float progress)
        {
            //scale
            var openedProgress = 1 - progress;
            var openedScale    = MathUtility.Lerp(SelectedBookScale3D.X, 1, openedProgress);
            var scaleMatrix    = Matrix3D.CreateScale(openedScale);

            //rotation
            var openedBookQuaternion = Matrix3DHelper.Slerp(SelectedBookRotation3D, openedBookTargetQuaternion,
                                                            openedProgress, true);
            var rotationM3D = Matrix3D.CreateFromQuaternion(openedBookQuaternion);

            //translation
            var openedX = MathUtility.Lerp(SelectedBookTranslation3D.X, OpenedBookRect.X + (float)Book.CoverWidth,
                                           openedProgress);
            var openedY           = MathUtility.Lerp(SelectedBookTranslation3D.Y, OpenedBookRect.Y, openedProgress);
            var translationMatrix = Matrix3D.CreateTranslation(openedX, openedY, 0);

            OpenedBook.TransformMatrix3D = rotationM3D * scaleMatrix * translationMatrix;
        }
Exemplo n.º 5
0
        private void UpdateBookTransform(Book3DViewModel bookVM, int iX, int iY)
        {
            var bounds3D = bookVM.GetBounds3D();

            var margLeft   = Config.Shelf3D.ShelfMarginLeft;
            var margTop    = Config.Shelf3D.ShelfMarginTop;
            var margRight  = Config.Shelf3D.ShelfMarginRight;
            var margBottom = Config.Shelf3D.ShelfMarginBottom;

            var shelfWidth  = ActualSize.Width - margLeft - margRight;
            var shelfHeight = ActualSize.Height - margTop - margBottom;

            if (shelfWidth == 0 || shelfHeight == 0)
            {
                return;
            }

            var boardHeight = Config.Shelf3D.ShelfBoardHeight;

            double bookX      = bounds3D.Min.X;
            double bookY      = bounds3D.Min.Y;
            double bookWidth  = bounds3D.Size.X;
            double bookHeight = bounds3D.Size.Y;

            if (bookWidth > 0 && bookHeight > 0)
            {
                var bookSize = new Size(bookWidth, bookHeight);

                var frameWidth  = shelfWidth / HBS.ColumnCount;
                var frameHeight = shelfHeight / HBS.RowCount;
                frameWidth  = Math.Max(0, frameWidth);
                frameHeight = Math.Max(0, frameHeight) - boardHeight;

                var frameX    = frameWidth * iX + margLeft;
                var frameY    = (frameHeight + boardHeight) * iY + margTop;
                var frameSize = new Size(frameWidth, frameHeight);

                var bookScale = MathHelper.ScaleSize(bookSize, frameWidth, frameHeight) *
                                Config.Shelf3D.ShelfAdditionalScale;

                var scaledBookWidth  = bookWidth * bookScale;
                var scaledBookHeight = bookHeight * bookScale;

                var x = frameX + (frameWidth - scaledBookWidth) * 0.5d + bookX;
                var y = frameY + (frameHeight - scaledBookHeight) + bookY;

                var translationX = x;
                //y gets inverted here since 3d origin is bottom left not top left
                var translationY = shelfHeight - scaledBookHeight - y;

                var m3D       = Matrix3D.Identity;
                var rotY      = Matrix3D.CreateRotationY(MathUtility.ToRadians((float)Config.Shelf3D.ShelfRotationY));
                var rotX      = Matrix3D.CreateRotationX(MathUtility.ToRadians((float)Config.Shelf3D.ShelfRotationX));
                var scale     = Matrix3D.CreateScale((float)bookScale);
                var translate = Matrix3D.CreateTranslation(new Point3D((float)translationX, (float)translationY, 0f));

                var bounds2D = new Rect((float)x, (float)y, (float)scaledBookWidth, (float)scaledBookHeight);
                bookVM.Bounds2D          = bounds2D;
                bookVM.TransformMatrix3D = m3D * rotY * rotX * scale * translate;
            }
        }