Skip to main content
deleted 145 characters in body
Source Link
Blau
  • 3.4k
  • 18
  • 19

This transform is done this way because Xna is Left Handled and OpneGl is Right Handled, so matrix multiplication should be in inverse order.

This is my code for this 2d bone editor:

This transform is done this way because Xna is Left Handled and OpneGl is Right Handled, so matrix multiplication should be in inverse order.

This is my code for this 2d bone editor:

This is my code for this 2d bone editor:

added 2281 characters in body
Source Link
Blau
  • 3.4k
  • 18
  • 19

I'm not sure how is your 3D input data works, but I think your local matrix should be:

 //-----------------------------------------------------------------------------------------------------------------------
        public void UpdateLocal( )
        {  
            Vector2 traslation = Translator.GetValue();
            float rotation = Rotator.GetValue();
            Vector2 scale = Scalator.GetValue();

            Matrix mTraslation, mRotation, mScale;
            Matrix.CreateTranslation( traslation.X, traslation.Y, 0, out mTraslation );
            Matrix.CreateRotationZ( rotation, out mRotation );
            Matrix.CreateScale(scale.X, scale.Y, 1 , out mScale );
            Matrix.Multiply( ref mScale, ref mRotation, out Local );
            Matrix.Multiply( ref Local, ref mTraslation, out Local );  
        }

        //-----------------------------------------------------------------------------------------------------------------------
        public virtual void UpdateTransformTopToDown( )
        {
            global_counter++;
            SpecialUpdateTransformTopToDown( );
        }

        //-----------------------------------------------------------------------------------------------------------------------
        protected virtual void SpecialUpdateTransformTopToDown( )
        {
            if ( counter == global_counter ) return;
            
            counter = global_counter;

            UpdateLocal( );

            if ( Parent != null )
            {
                 Matrix.Multiply( ref Local, ref (Parent as BoneData).Absolute, out Absolute );
            }
            else
            {
                Absolute = Local;
            }

            foreach ( BoneData child in _children.OfType<BoneData>() )
            {
                child.SpecialUpdateTransformTopToDown( );
            }
        }

And this is my code to animate Warcraft3 models, (based in MagosX War3ModelEditor code):

public void BuildTransformMatrix(Intervalo Time, Camara Camara)
    {
        
        Vector3 TranslationVector;
        Vector4 RotationVector;
        Vector3 ScalingVector;

        TranslationVector = Translation.GetValue(Time);
        RotationVector = Rotation.GetValue(Time);
        ScalingVector = Scaling.GetValue(Time);

        Matrix mPivotPoint = Matrix.CreateTranslation(PivotPoint);
        Matrix mScaling = Matrix.CreateScale(ScalingVector);
        Matrix mRotation = Matrix.CreateFromQuaternion(RotationVector.ToQuaternion());
        Matrix mTranslation = Matrix.CreateTranslation(TranslationVector);

        Matrix mPivotPointInverse = Matrix.Invert(mPivotPoint);


        Transform = mPivotPointInverse * mScaling * mRotation * mPivotPoint * mTranslation;           

        if (Parent != null && Parent.NodeId != -1)
        {
            Transform = Matrix.Multiply(Transform, Parent.Transform);
        }

        foreach (BaseNode child in Children)
        {
            child.BuildTransformMatrix(Time, Camara);
        }
    }
        

I'm not sure how is your input data, but I think your local matrix should be:

 //-----------------------------------------------------------------------------------------------------------------------
        public void UpdateLocal( )
        {  
            Vector2 traslation = Translator.GetValue();
            float rotation = Rotator.GetValue();
            Vector2 scale = Scalator.GetValue();

            Matrix mTraslation, mRotation, mScale;
            Matrix.CreateTranslation( traslation.X, traslation.Y, 0, out mTraslation );
            Matrix.CreateRotationZ( rotation, out mRotation );
            Matrix.CreateScale(scale.X, scale.Y, 1 , out mScale );
            Matrix.Multiply( ref mScale, ref mRotation, out Local );
            Matrix.Multiply( ref Local, ref mTraslation, out Local );  
        }

        //-----------------------------------------------------------------------------------------------------------------------
        public virtual void UpdateTransformTopToDown( )
        {
            global_counter++;
            SpecialUpdateTransformTopToDown( );
        }

        //-----------------------------------------------------------------------------------------------------------------------
        protected virtual void SpecialUpdateTransformTopToDown( )
        {
            if ( counter == global_counter ) return;
            
            counter = global_counter;

            UpdateLocal( );

            if ( Parent != null )
            {
                 Matrix.Multiply( ref Local, ref (Parent as BoneData).Absolute, out Absolute );
            }
            else
            {
                Absolute = Local;
            }

            foreach ( BoneData child in _children.OfType<BoneData>() )
            {
                child.SpecialUpdateTransformTopToDown( );
            }
        }


        

I'm not sure how your 3D input data works, but I think your local matrix should be:

 //-----------------------------------------------------------------------------------------------------------------------
        public void UpdateLocal( )
        {  
            Vector2 traslation = Translator.GetValue();
            float rotation = Rotator.GetValue();
            Vector2 scale = Scalator.GetValue();

            Matrix mTraslation, mRotation, mScale;
            Matrix.CreateTranslation( traslation.X, traslation.Y, 0, out mTraslation );
            Matrix.CreateRotationZ( rotation, out mRotation );
            Matrix.CreateScale(scale.X, scale.Y, 1 , out mScale );
            Matrix.Multiply( ref mScale, ref mRotation, out Local );
            Matrix.Multiply( ref Local, ref mTraslation, out Local );  
        }

        //-----------------------------------------------------------------------------------------------------------------------
        public virtual void UpdateTransformTopToDown( )
        {
            global_counter++;
            SpecialUpdateTransformTopToDown( );
        }

        //-----------------------------------------------------------------------------------------------------------------------
        protected virtual void SpecialUpdateTransformTopToDown( )
        {
            if ( counter == global_counter ) return;
            
            counter = global_counter;

            UpdateLocal( );

            if ( Parent != null )
            {
                 Matrix.Multiply( ref Local, ref (Parent as BoneData).Absolute, out Absolute );
            }
            else
            {
                Absolute = Local;
            }

            foreach ( BoneData child in _children.OfType<BoneData>() )
            {
                child.SpecialUpdateTransformTopToDown( );
            }
        }

And this is my code to animate Warcraft3 models, (based in MagosX War3ModelEditor code):

public void BuildTransformMatrix(Intervalo Time, Camara Camara)
    {
        
        Vector3 TranslationVector;
        Vector4 RotationVector;
        Vector3 ScalingVector;

        TranslationVector = Translation.GetValue(Time);
        RotationVector = Rotation.GetValue(Time);
        ScalingVector = Scaling.GetValue(Time);

        Matrix mPivotPoint = Matrix.CreateTranslation(PivotPoint);
        Matrix mScaling = Matrix.CreateScale(ScalingVector);
        Matrix mRotation = Matrix.CreateFromQuaternion(RotationVector.ToQuaternion());
        Matrix mTranslation = Matrix.CreateTranslation(TranslationVector);

        Matrix mPivotPointInverse = Matrix.Invert(mPivotPoint);


        Transform = mPivotPointInverse * mScaling * mRotation * mPivotPoint * mTranslation;           

        if (Parent != null && Parent.NodeId != -1)
        {
            Transform = Matrix.Multiply(Transform, Parent.Transform);
        }

        foreach (BaseNode child in Children)
        {
            child.BuildTransformMatrix(Time, Camara);
        }
    }
        
added 2281 characters in body
Source Link
Blau
  • 3.4k
  • 18
  • 19

I'm not sure how is your input data, but I think your local matrix should be:

 b.localTransform = Matrix.CreateRotationZ(MathHelper.ToRadians(b.z)) * Matrix.CreateRotationY(MathHelper.ToRadians(b.y)) * Matrix.CreateRotationX(MathHelper.ToRadians(b.x)) * Matrix.CreateTranslation(b.Offset);

This transform is done this way because Xna is Left Handled and OpneGl is Right Handled, so matrix multiplication should be in inverse order.

This is my code for this 2d bone editor:

 //-----------------------------------------------------------------------------------------------------------------------
        public void UpdateLocal( )
        {  
            Vector2 traslation = Translator.GetValue();
            float rotation = Rotator.GetValue();
            Vector2 scale = Scalator.GetValue();

            Matrix mTraslation, mRotation, mScale;
            Matrix.CreateTranslation( traslation.X, traslation.Y, 0, out mTraslation );
            Matrix.CreateRotationZ( rotation, out mRotation );
            Matrix.CreateScale(scale.X, scale.Y, 1 , out mScale );
            Matrix.Multiply( ref mScale, ref mRotation, out Local );
            Matrix.Multiply( ref Local, ref mTraslation, out Local );  
        }

        //-----------------------------------------------------------------------------------------------------------------------
        public virtual void UpdateTransformTopToDown( )
        {
            global_counter++;
            SpecialUpdateTransformTopToDown( );
        }

        //-----------------------------------------------------------------------------------------------------------------------
        protected virtual void SpecialUpdateTransformTopToDown( )
        {
            if ( counter == global_counter ) return;
            
            counter = global_counter;

            UpdateLocal( );

            if ( Parent != null )
            {
                 Matrix.Multiply( ref Local, ref (Parent as BoneData).Absolute, out Absolute );
            }
            else
            {
                Absolute = Local;
            }

            foreach ( BoneData child in _children.OfType<BoneData>() )
            {
                child.SpecialUpdateTransformTopToDown( );
            }
        }


        

I think your local matrix should be:

 b.localTransform = Matrix.CreateRotationZ(MathHelper.ToRadians(b.z)) * Matrix.CreateRotationY(MathHelper.ToRadians(b.y)) * Matrix.CreateRotationX(MathHelper.ToRadians(b.x)) * Matrix.CreateTranslation(b.Offset);


        

I'm not sure how is your input data, but I think your local matrix should be:

 b.localTransform = Matrix.CreateRotationZ(MathHelper.ToRadians(b.z)) * Matrix.CreateRotationY(MathHelper.ToRadians(b.y)) * Matrix.CreateRotationX(MathHelper.ToRadians(b.x)) * Matrix.CreateTranslation(b.Offset);

This transform is done this way because Xna is Left Handled and OpneGl is Right Handled, so matrix multiplication should be in inverse order.

This is my code for this 2d bone editor:

 //-----------------------------------------------------------------------------------------------------------------------
        public void UpdateLocal( )
        {  
            Vector2 traslation = Translator.GetValue();
            float rotation = Rotator.GetValue();
            Vector2 scale = Scalator.GetValue();

            Matrix mTraslation, mRotation, mScale;
            Matrix.CreateTranslation( traslation.X, traslation.Y, 0, out mTraslation );
            Matrix.CreateRotationZ( rotation, out mRotation );
            Matrix.CreateScale(scale.X, scale.Y, 1 , out mScale );
            Matrix.Multiply( ref mScale, ref mRotation, out Local );
            Matrix.Multiply( ref Local, ref mTraslation, out Local );  
        }

        //-----------------------------------------------------------------------------------------------------------------------
        public virtual void UpdateTransformTopToDown( )
        {
            global_counter++;
            SpecialUpdateTransformTopToDown( );
        }

        //-----------------------------------------------------------------------------------------------------------------------
        protected virtual void SpecialUpdateTransformTopToDown( )
        {
            if ( counter == global_counter ) return;
            
            counter = global_counter;

            UpdateLocal( );

            if ( Parent != null )
            {
                 Matrix.Multiply( ref Local, ref (Parent as BoneData).Absolute, out Absolute );
            }
            else
            {
                Absolute = Local;
            }

            foreach ( BoneData child in _children.OfType<BoneData>() )
            {
                child.SpecialUpdateTransformTopToDown( );
            }
        }


        
Source Link
Blau
  • 3.4k
  • 18
  • 19
Loading