Hey,
i know there have been several posts about this already, and i really didn’t want to post, but i just cant get it to work. Tinkering around for days now.
I want to align a spritebatch draw like this:
spriteBatch.Begin(transformMatrix: camera.worldViewProjSpriteBatch);
spriteBatch.Draw(texture, position, null, Color.White, 0, new(texture.Width / 2f, texture.Height / 2f), scale, SpriteEffects.None, layer);
spriteBatch.End();
with a quad i’ve drawn with a vertexbuffer:
float4 position = float4(vertexInput.Position.xy * textureSize + instanceInput.Position.xy, 0.0, 1.0);
output.Position = mul(position, worldViewProjGPU);
and these are my matrices for the cameras:
// SpriteBatch
var transformMatrix = Matrix.CreateTranslation(-player.position.X, -player.position.Y, 0);
transformMatrix *= Matrix.CreateScale(distance, distance, 1); // Scale by zoom
transformMatrix *= Matrix.CreateTranslation(windowSize.X * 0.5f, windowSize.Y * 0.5f, 0);
worldViewProjSpriteBatch = transformMatrix;
// GPU Instance
Matrix viewMatrixGPU = Matrix.CreateLookAt(V(player.position, 10), V(player.position, 0), Vector3.Up);
Matrix projectionMatrixGPU = Matrix.CreateOrthographicOffCenter(0, windowSize.X, windowSize.Y, 0, nearPlane, farPlane);
projectionMatrixGPU *= Matrix.CreateScale(distance, distance, 1);
worldViewProjGPU = viewMatrixGPU * projectionMatrixGPU;
V = Vector, distance is the zoom. And this kinda works, but the sprite’s scale and position dont align with the quad ones. And i’m just not getting something fundamentally. Like one is in screenspace and one in worldspace or something. If somebody could make me understand this, i would be really appreciative!