I'm currently struggling with finding the offset for my original camera translation after I have applied a rotation for it.

transform = Matrix.CreateScale(new Vector3(1, 0.75f, 1)) 
            * Matrix.CreateTranslation(-playerpos.X+dash, -playerpos.Y, 1);

rotation = Matrix.CreateRotationX(MathHelper.ToRadians(valuex)) 
            * Matrix.CreateRotationY(MathHelper.ToRadians(valuey));

transform2 = rotation 
            * Matrix.CreateScale(new Vector3(1, 0.75f, 0)) 
            * Matrix.CreateTranslation(-playerpos.X + dash, -playerpos.Y, 0);

My original transform matrix is for the camera that follows the player, I use transform2 for sprites I want to rotate.

spriteBatch.Begin( SpriteSortMode.Immediate, BlendState.AlphaBlend, null, 
                   null, null, null, camera.transform);

spriteBatch.Begin( SpriteSortMode.Immediate, BlendState.AlphaBlend, null, 
                   null, null, null, camera.transform2);


for (int i = 0; i < 3; i++)
  spriteBatch.Draw( world.mcircle[i], 
                    new Vector2(5320, 1200), 
                    (world.finishtime * 5) / (i + 1), 
                    new Vector2(50, 50), 

So I pass two different transformations based on whether I want stuff to rotate or not.

But I just can't seem to find the correct offset in position for the rotated sprites, they seem to gravitate towards (0, 0)? as the rotational value increases.

I'd be really glad if someone could help me out with this.

Edit: I think I'd only need a proper origin for the sprite position, because currently it goes towards (0, 0) and I'm unsure how to incorporate one in this state.


Tried several origin points for transform2, but when I input the object's coordinates as source, it just displaces it by that amount, and when I set the object's position to (0,0) it still has the same effect as if having the original origin point.

transform2 = Matrix.CreateTranslation(0, 0, 0)
             * (rotation * Matrix.CreateScale(new Vector3(1, 0.75f, 0)) 
             * Matrix.CreateTranslation((-playerpos.X + dash), -playerpos.Y, 0)); //just an example currently
  • \$\begingroup\$ For what purpose are you using the negative value of the player's X and Y position? Also watch your multiplication ordering on your matrices. Multiplying the scale after the rotation can have undesired effects. \$\endgroup\$
    – Jason H
    Aug 17, 2015 at 7:33
  • \$\begingroup\$ That gives me the view matrix translation which follows the player, otherwise any coordinates I give are off, and currently for some odd reason the only way my rotated texture shows properly if I do it in this order. I'll update my OP with some new code which I think might help narrow the solution. \$\endgroup\$
    – Razeal
    Aug 17, 2015 at 12:56
  • \$\begingroup\$ Please remember to reserve edits for substantial changes only, it's not to be used to "bump" a question. Thanks. \$\endgroup\$
    – House
    Aug 19, 2015 at 13:25

1 Answer 1


Okay so the answer was rather simple, should've thought about it earlier, in order to give a correct origin you'll need to get the world coordinates for it through your original view matrix's transformation.

transform2 = 
Matrix.CreateTranslation(0, 0, 0) 
* (rotation * Matrix.CreateScale(new Vector3(1, 0.75f, 0)) 
* Matrix.CreateTranslation(Vector2.Transform(new Vector2(5320, 1200), transform).X, Vector2.Transform(new Vector2(5320, 1200), transform).Y, 0));

The vector2 (5320,1200) is just an example that I wanted my object at.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .