Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 643569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:17:50+00:00 2026-05-13T21:17:50+00:00

What I am looking to do is to be able to push and pop

  • 0

What I am looking to do is to be able to push and pop transform matrices into SpriteBatch. I have 2 sprites, parent and child, and the child should be scaled, rotated, translated relative to the parent.

I currently have an implementation using textured quads but I think this should be possible using the built in SpriteBatch class and using Matrix.Decompose(). I’m not sure how to pass the decomposed values to SpriteBatch once I’ve decomposed them though.

I understand how to keep the matrix stack, I’m just looking for an example of using values coming from Matrix.Decompose() in conjunction with SpriteBatch.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:17:50+00:00Added an answer on May 13, 2026 at 9:17 pm

    Figured this one out myself finally. Most of the credit belongs to this blog post though.

    You can use this method to decompose your matrix:

    private void DecomposeMatrix(ref Matrix matrix, out Vector2 position, out float rotation, out Vector2 scale)
    {
        Vector3 position3, scale3;
        Quaternion rotationQ;
    
        matrix.Decompose(out scale3, out rotationQ, out position3);
    
        Vector2 direction = Vector2.Transform(Vector2.UnitX, rotationQ);
        rotation = (float)Math.Atan2((double)(direction.Y), (double)(direction.X));
        position = new Vector2(position3.X, position3.Y);
        scale = new Vector2(scale3.X, scale3.Y);
    }
    

    You can then build a transform matrix your leaf sprites like so:

    Matrix transform = 
        Matrix.CreateScale(new Vector3(this.Scale, 1.0f)) *
        Matrix.CreateRotationZ(this.Rotation) *
        Matrix.CreateTranslation(new Vector3(this.Position, 0));
    

    For your parent sprites, include the origin:

    Matrix transform = 
        Matrix.CreateTranslation(new Vector3(-this.Origin, 0)) *
        Matrix.CreateScale(new Vector3(this.Scale, 1.0f)) *
        Matrix.CreateRotationZ(this.Rotation) *
        Matrix.CreateTranslation(new Vector3(this.position, 0));
    

    Multiply by all the matrices in the stack in reverse order.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a thread pool library in .NET I should able to push
Rather than have everything in one big dialog, I'm looking at being able to
I am looking for a way to be able to have a list of
I have some code below. This code is a basic push/pop stack class that
Looking for some direction here as I'm running into some migration problems. We have
I'm looking to be able to reference certain state/objects through anywhere in my application.
I'm looking to be able to produce a nicely formatted table with rows and
I'm looking to be able to basically change ports that my express app is
I am looking to be able to create two functions, BaseFunction and CallbackFunction where
I'm looking for a tool that will be able to build a parser (in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.