Inverted textures
- by brainydexter
I'm trying to draw textures aligned with this physics body whose coordinate system's origin is at the center of the screen. (XNA)Spritebatch has its default origin set to top-left corner.
I got the textures to be positioned correctly, but I noticed my textures are vertically inverted. That is, an arrow texture pointing Up , when rendered points down. I'm not sure where I am going wrong with the math.
My approach is to convert everything in physic's meter units and draw accordingly.
Matrix proj = Matrix.CreateOrthographic(scale * graphics.GraphicsDevice.Viewport.AspectRatio, scale, 0, 1);
Matrix view = Matrix.Identity;
effect.World = Matrix.Identity;
effect.View = view;
effect.Projection = proj;
effect.TextureEnabled = true;
effect.VertexColorEnabled = true;
effect.Techniques[0].Passes[0].Apply();
SpriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, DepthStencilState.Default, RasterizerState.CullNone, effect);
m_Paddles[1].Draw(gameTime);
SpriteBatch.End();
where Paddle::Draw looks like:
SpriteBatch.Draw(paddleTexture,
mBody.Position,
null,
Color.White,
0f,
new Vector2(16f, 16f), // origin of the texture
0.1875f, SpriteEffects.None, // width of box is 3*2 = 6 meters. texture is 32 pixels wide. to make it 6 meters wide in world space: 6/32 = 0.1875f
0);
The orthographic projection matrix seem fine to me, but I am obviously doing something wrong somewhere! Can someone please help me figure out what am i doing wrong here ?
Thanks