Exemplo n.º 1
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;


            //}
        }