Handmade Network»Forums
Shazan Shums
159 posts
Some day I will make quality software. Programming FTW.
(Monogame /XNA / Directx) Changing Bottom up drawing to top down.
Is it possible like (the way casey did in handmadehero for Rendering in Top down mode by setting bi Height to negative ). In XNA/Monogame was using Spritbatcher.draw() and the bottom up coordinate system is weired. Anyways how to fix this?

Any Monogame developers can help me out?
Mārtiņš Možeiko
2562 posts / 2 projects
(Monogame /XNA / Directx) Changing Bottom up drawing to top down.
No, negative height won't work. That is GDI specific thing in Windows.

What you want is to set transform matrix for draw calls. If I'm not mistaken. SpriteBatch.Begin method has an overload that allows to pass transform matrix in argument. So create a matrix that does vertical flip (scale with -1) and it should draw everything vertically flipped.
Shazan Shums
159 posts
Some day I will make quality software. Programming FTW.
(Monogame /XNA / Directx) Changing Bottom up drawing to top down.
Edited by Shazan Shums on
But i'm currently using a 2D camera

So ,if I change this,

1
2
3
4
5
6
7
8
9
public Matrix get_transformation()
        {
            _transform =  
              Matrix.CreateTranslation(new Vector3(-_pos.X, -_pos.Y, 0)) *
                                         Matrix.CreateRotationZ(Rotation) *
                                         Matrix.CreateScale(Zoom,Zoom,Zoom)*
                                         Matrix.CreateTranslation(new Vector3(graphicsDevice.Viewport.Width * 0.5f, graphicsDevice.Viewport.Height * 0.5f, 0));
            return _transform;
        }


to this

1
2
3
4
5
6
7
8
9
public Matrix get_transformation()
        {
            _transform =  
              Matrix.CreateTranslation(new Vector3(-_pos.X, -_pos.Y, 0)) *
                                         Matrix.CreateRotationZ(Rotation) *
                                         Matrix.CreateScale(Zoom,-Zoom,Zoom)*
                                         Matrix.CreateTranslation(new Vector3(graphicsDevice.Viewport.Width * 0.5f, graphicsDevice.Viewport.Height * 0.5f, 0));
            return _transform;
        }



It still doesn't work.

And the matrix is passed to SpriteBatch.Begin method as you said.

Shazan Shums
159 posts
Some day I will make quality software. Programming FTW.
(Monogame /XNA / Directx) Changing Bottom up drawing to top down.
After some tuning and thinking and drawing diagrams here's a fixed. But if there's another method please share. Anyways here's my Solution,

This is passed to Spritebatch.begin -- Matrix param
1
2
3
4
5
6
7
8
9
 public Matrix get_transformation()
        {
            _transform =  
              Matrix.CreateTranslation(new Vector3(-_pos.X, _pos.Y, 0)) *
                                         Matrix.CreateRotationZ(Rotation) *
                                         Matrix.CreateScale(Zoom,Zoom,1.0f)*
                                         Matrix.CreateTranslation(new Vector3(graphicsDevice.Viewport.Width * 0.5f, graphicsDevice.Viewport.Height * 0.5f, 0));
            return _transform;
        }



This is passed to Spritebatch.Draw -- Vector2 position param

1
2
3
4
5
6
 public Vector2 WorldtoScreen(Vector2 In)
        {
            Vector2 Result = In;
            Result.Y = -In.Y;
            return Result;
        }