Exemplo n.º 1
0
        private void PerformDraggingObjectControl()
        {
            Cursor cursor = GuiManager.Cursor;

            if (mObjectGrabbed == null || cursor.WindowOver != null)
            {
                return;
            }

            #region Move

            if (GuiData.ToolsWindow.MoveButton.IsPressed)
            {
                PositionedObjectMover.MouseMoveObject(mObjectGrabbed);
            }

            #endregion

            #region Scale

            else if (GuiData.ToolsWindow.ScaleButton.IsPressed && mObjectGrabbed is IScalable)
            {
                cursor.StaticPosition = true;

                IScalable asIScalable = mObjectGrabbed as IScalable;

                asIScalable.ScaleX *= 1 + cursor.XVelocity / 100.0f;
                asIScalable.ScaleY *= 1 + cursor.YVelocity / 100.0f;
            }

            #endregion

            #region Rotate

            else if (GuiData.ToolsWindow.RotateButton.IsPressed && mObjectGrabbed is IRotatable)
            {
                cursor.StaticPosition = true;

                IRotatable asiRotatable = mObjectGrabbed as IRotatable;

                asiRotatable.RotationZ += cursor.YVelocity * SpriteManager.Camera.Z / 100.0f;

                if (mObjectGrabbed.Parent != null)
                {
                    mObjectGrabbed.SetRelativeFromAbsolute();
                }
            }

            #endregion
        }
Exemplo n.º 2
0
        public static void MouseRotateObject <T>(T objectToMove, MovementStyle movementStyle) where T : IRotatable
        {
            Cursor cursor = GuiManager.Cursor;

            if (cursor.YVelocity != 0)
            {
                cursor.StaticPosition = true;
            }

            float movementAmount = cursor.YVelocity / 8.0f;

            switch (movementStyle)
            {
            case MovementStyle.Group:
                objectToMove.RotationZ += movementAmount;
                break;

            case MovementStyle.Hierarchy:
                objectToMove.RotationZ += movementAmount;

                if (objectToMove is PositionedObject && (objectToMove as PositionedObject).Parent != null)
                {
                    (objectToMove as PositionedObject).SetRelativeFromAbsolute();
                }
                break;

            case MovementStyle.IgnoreAttachments:
                objectToMove.RotationZ += movementAmount;

                if (objectToMove is PositionedObject)
                {
                    PositionedObject asPositionedObject = objectToMove as PositionedObject;
                    if (asPositionedObject.Parent != null)
                    {
                        asPositionedObject.SetRelativeFromAbsolute();
                    }
                    foreach (PositionedObject child in asPositionedObject.Children)
                    {
                        //child.Position -= movementVector;
                        if (mObjectsToIgnore.Contains(child) == false)
                        {
                            child.SetRelativeFromAbsolute();
                        }
                    }
                }
                break;
            }
        }
Exemplo n.º 3
0
        void RotatePrivateSpritesAboutAxis(Vector3 axisVector, Cursor cursor)
        {
            if (CurrentObject != null)
            {
                PositionedObject s = CurrentObject;

                #region no parent
                if (s.Parent == null && !spritesAlreadyChanged.Contains(s))
                {
                    spritesAlreadyChanged.AddOneWay(s);

#if FRB_MDX
                    s.RotationMatrix *= Matrix.RotationAxis(axisVector, cursor.YVelocity / 16.0f);
#else
                    s.RotationMatrix *= Matrix.CreateFromAxisAngle(axisVector, cursor.YVelocity / 16.0f);
#endif
                    // Fixes accumulation error:
                    s.RotationZ = s.RotationZ;
                    //if (s is ISpriteEditorObject)
                    //{
                    //    float temporaryRotX = 0;
                    //    float temporaryRotY = 0;
                    //    float temporaryRotationZ = 0;

                    //    MathFunctions.ExtractRotationValuesFromMatrix(tempMatrix,
                    //        ref temporaryRotX,
                    //        ref temporaryRotY,
                    //        ref temporaryRotationZ);

                    //    (s).RotationX = temporaryRotX;
                    //    (s).RotationY = temporaryRotY;
                    //    (s).RotationZ = temporaryRotationZ;
                    //}
                    //else
                    //{
                    //}
                }
                #endregion

                #region has parent, group hierarchy is pressed (so in hierarchy (NOT GROUP) mode )
                else if (HierarchyControl)
                {
                    spritesAlreadyChanged.AddOneWay(s);

#if FRB_MDX
                    s.RotationMatrix *= Matrix.RotationAxis(axisVector, cursor.YVelocity / 16.0f);
#else
                    s.RotationMatrix *= Matrix.CreateFromAxisAngle(axisVector, cursor.YVelocity / 16.0f);
#endif
                    s.SetRelativeFromAbsolute();
                }
                #endregion

                #region rotation logic for the entire group - ONLY do on topparents
                else
                {
                    Sprite parentSprite = (Sprite)(s.TopParent);

                    spritesAlreadyChanged.AddOneWay(parentSprite);

                    Vector3 positionFromOrigin = new Vector3((float)(parentSprite.X - origin.X),
                                                             (float)(parentSprite.Y - origin.Y), (float)(parentSprite.Z - origin.Z));

#if FRB_MDX
                    Matrix rotationMatrixToUse = Matrix.RotationAxis(axisVector, cursor.YVelocity / 16.0f);
#else
                    Matrix rotationMatrixToUse = Matrix.CreateFromAxisAngle(axisVector, cursor.YVelocity / 16.0f);
#endif


                    parentSprite.RotationMatrix *= rotationMatrixToUse;

                    MathFunctions.TransformVector(ref positionFromOrigin, ref rotationMatrixToUse);

                    (parentSprite).X = (float)(positionFromOrigin.X + origin.X);
                    (parentSprite).Y = (float)(positionFromOrigin.Y + origin.Y);
                    (parentSprite).Z = (float)(positionFromOrigin.Z + origin.Z);


                    float temporaryRotX      = 0;
                    float temporaryRotY      = 0;
                    float temporaryRotationZ = 0;

                    MathFunctions.ExtractRotationValuesFromMatrix(parentSprite.RotationMatrix,
                                                                  ref temporaryRotX,
                                                                  ref temporaryRotY,
                                                                  ref temporaryRotationZ);

                    (s).RotationX = temporaryRotX;
                    (s).RotationY = temporaryRotY;
                    (s).RotationZ = temporaryRotationZ;
                }
                #endregion
            }

            //foreach (SpriteFrame sf in GameData.EditorLogic.CurrentSpriteFrames)
            //{
            //    Matrix tempMatrix = sf.RotationMatrix;
            //    tempMatrix *= Matrix.RotationAxis(axisVector, cursor.YVelocity / 16.0f);

            //    float RotationX = 0;
            //    float RotationY = 0;
            //    float RotationZ = 0;

            //    MathFunctions.ExtractRotationValuesFromMatrix(tempMatrix, ref RotationX,
            //        ref RotationY,
            //        ref RotationZ);

            //    sf.RotationX = RotationX;
            //    sf.RotationY = RotationY;
            //    sf.RotationZ = RotationZ;


            //}
        }
        public static void MouseMoveObject <T>(T objectToMove, MovementStyle movementStyle) where T : IStaticPositionable
        {
            Cursor cursor = GuiManager.Cursor;

            if (cursor.PrimaryPush)
            {
                return;
            }

            if (GuiManager.Cursor.ActualXVelocityAt(objectToMove.Z) == 0 &&
                GuiManager.Cursor.ActualYVelocityAt(objectToMove.Z) == 0)
            {
                return;
            }
            #region Store the movement in the movementVector
            Vector3 movementVector = new Vector3();

            #region If doing shift movement, then consider original position

#if FRB_MDX
            bool isShiftDown =
                InputManager.Keyboard.KeyDown(Microsoft.DirectX.DirectInput.Key.LeftShift) ||
                InputManager.Keyboard.KeyDown(Microsoft.DirectX.DirectInput.Key.RightShift);
#elif FRB_XNA
            bool isShiftDown =
                InputManager.Keyboard.KeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift) ||
                InputManager.Keyboard.KeyDown(Microsoft.Xna.Framework.Input.Keys.RightShift);
#endif


            if (isShiftDown && HasValidStartPosition)
            {
                float xDistanceFromStart = Math.Abs((cursor.WorldXAt(0) - mGrabOffset.X) - mOriginalGrabPosition.X);
                float yDistanceFromStart = Math.Abs((cursor.WorldYAt(0) - mGrabOffset.Y) - mOriginalGrabPosition.Y);

                if (xDistanceFromStart > yDistanceFromStart)
                {
                    movementVector.X = (cursor.WorldXAt(0) - mGrabOffset.X) - objectToMove.X;
                    movementVector.Y = (mOriginalGrabPosition.Y) - objectToMove.Y;
                }
                else
                {
                    movementVector.X = (mOriginalGrabPosition.X) - objectToMove.X;
                    movementVector.Y = (cursor.WorldYAt(0) - mGrabOffset.Y) - objectToMove.Y;
                }
            }

            #endregion

            #region Else, just accumulate normally
            else
            {
                if (cursor.PrimaryDown)
                {
                    movementVector.X = GuiManager.Cursor.WorldXChangeAt(objectToMove.Z);
                    movementVector.Y = GuiManager.Cursor.WorldYChangeAt(objectToMove.Z);
                }
                else if (cursor.SecondaryDown && mAllowZMovement)
                {
                    movementVector.Z      = GuiManager.Cursor.WorldYChangeAt(objectToMove.Z);
                    cursor.StaticPosition = true;
                }
            }
            #endregion

            #endregion

            #region Apply the movement vector according to the movementStyle
            switch (movementStyle)
            {
            case MovementStyle.Group:
                if (objectToMove is PositionedObject)
                {
                    PositionedObject topParent = (objectToMove as PositionedObject).TopParent;

                    topParent.X += movementVector.X;
                    topParent.Y += movementVector.Y;
                    topParent.Z += movementVector.Z;
                }
                else
                {
                    objectToMove.X += movementVector.X;
                    objectToMove.Y += movementVector.Y;
                    objectToMove.Z += movementVector.Z;
                }
                break;

            case MovementStyle.Hierarchy:
                objectToMove.X += movementVector.X;
                objectToMove.Y += movementVector.Y;
                objectToMove.Z += movementVector.Z;

                if (objectToMove is PositionedObject && (objectToMove as PositionedObject).Parent != null)
                {
                    (objectToMove as PositionedObject).SetRelativeFromAbsolute();
                }
                break;

            case MovementStyle.IgnoreAttachments:
                objectToMove.X += movementVector.X;
                objectToMove.Y += movementVector.Y;
                objectToMove.Z += movementVector.Z;

                if (objectToMove is PositionedObject)
                {
                    PositionedObject asPositionedObject = objectToMove as PositionedObject;
                    if (asPositionedObject.Parent != null)
                    {
                        asPositionedObject.SetRelativeFromAbsolute();
                    }
                    foreach (PositionedObject child in asPositionedObject.Children)
                    {
                        //child.Position -= movementVector;
                        if (mObjectsToIgnore.Contains(child) == false)
                        {
                            child.SetRelativeFromAbsolute();
                        }
                    }
                }
                break;
            }

            #endregion
        }