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);
Edit:
for (int i = 0; i < 3; i++)
{
spriteBatch.Draw( world.mcircle[i],
new Vector2(5320, 1200),
null,
Color.White,
(world.finishtime * 5) / (i + 1),
new Vector2(50, 50),
3f,
SpriteEffects.None,
0);
}
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.
Edit:
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