Esempio n. 1
0
        private static bool CheckValidBlockRotation(Matrix localMatrix, MyBlockDirection blockDirection, MyBlockRotation blockRotation)
        {
            Vector3I forward = Vector3I.Round(localMatrix.Forward);
            Vector3I up = Vector3I.Round(localMatrix.Up);

            int forwardDot = Vector3I.Dot(ref forward, ref forward);
            int upDot = Vector3I.Dot(ref up, ref up);

            // Matrix is not aligned to snap directions.
            if (forwardDot > 1 || upDot > 1)
            {
                if (blockDirection == MyBlockDirection.Both)
                    return true;
                return false;
            }

            if (blockDirection == MyBlockDirection.Horizontal)
            {
                if (forward == Vector3I.Up || forward == -Vector3I.Up)
                    return false;

                if (blockRotation == MyBlockRotation.Vertical && up != Vector3I.Up)
                    return false;
            }

            return true;
        }
Esempio n. 2
0
        internal bool CalculateBlockRotation(int index, int sign, ref MatrixD currentMatrix, out MatrixD rotatedMatrix, float angle,
            MyBlockDirection blockDirection = MyBlockDirection.Both, MyBlockRotation blockRotation = MyBlockRotation.Both)
        {
            Matrix rotation = Matrix.Identity;
            rotatedMatrix = Matrix.Identity;

            //because Z axis is negative
            if (index == 2)
                sign *= -1;

            switch (index)
            {
                case 0:   //X
                    rotation = Matrix.CreateFromAxisAngle(currentMatrix.Right, sign * angle);
                    break;

                case 1: //Y
                    rotation = Matrix.CreateFromAxisAngle(currentMatrix.Up, sign * angle);
                    break;

                case 2: //Z
                    rotation = Matrix.CreateFromAxisAngle(currentMatrix.Forward, sign * angle);
                    break;

                default:
                    System.Diagnostics.Debug.Assert(false);
                    break;
            }

            rotatedMatrix = currentMatrix;
            rotatedMatrix *= rotation;

            return CheckValidBlockRotation(rotatedMatrix, blockDirection, blockRotation);
        }
Esempio n. 3
0
        public static bool CalculateBlockRotation(int index, int sign, ref MatrixD currentMatrix, out MatrixD rotatedMatrix, float angle,
            MyBlockDirection blockDirection = MyBlockDirection.Both, MyBlockRotation blockRotation = MyBlockRotation.Both)
        {
            Matrix rotation = Matrix.Identity;

            //because Z axis is negative
            if (index == 2)
                sign *= -1;

            Vector3D tmpRotationAnimation = Vector3D.Zero;

            switch (index)
            {
                case 0: //X
                    tmpRotationAnimation.X += sign * angle;
                    rotation = Matrix.CreateFromAxisAngle(currentMatrix.Right, sign * angle);
                    break;

                case 1: //Y
                    tmpRotationAnimation.Y += sign * angle;
                    rotation = Matrix.CreateFromAxisAngle(currentMatrix.Up, sign * angle);
                    break;

                case 2: //Z
                    tmpRotationAnimation.Z += sign * angle;
                    rotation = Matrix.CreateFromAxisAngle(currentMatrix.Forward, sign * angle);
                    break;

                default:
                    System.Diagnostics.Debug.Assert(false);
                    break;
            }

            rotatedMatrix = currentMatrix;
            rotatedMatrix *= rotation;

            bool isValid = CheckValidBlockRotation(rotatedMatrix, blockDirection, blockRotation);
            if (isValid && MySandboxGame.Config.AnimatedRotation)
                if (!Static.DynamicMode)
                    if (!Static.m_animationLock)
                        Static.m_animationLock = true;
                    else
                        isValid = !isValid;

            return isValid;
        }