handmade.network » Forums » (Monogame /XNA / Directx) Changing Bottom up drawing to top down.
msmshazan
Shazan Shums
162 posts

Some day I will make quality software.
Programming FTW.

#11506 (Monogame /XNA / Directx) Changing Bottom up drawing to top down.
6 months, 3 weeks ago

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?

Just being curious on programming....
mmozeiko
Mārtiņš Možeiko
1485 posts
1 project
#11510 (Monogame /XNA / Directx) Changing Bottom up drawing to top down.
6 months, 3 weeks ago

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.
msmshazan
Shazan Shums
162 posts

Some day I will make quality software.
Programming FTW.

#11516 (Monogame /XNA / Directx) Changing Bottom up drawing to top down.
6 months, 3 weeks ago Edited by Shazan Shums on March 29, 2017, 11:37 a.m.

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.


Just being curious on programming....
msmshazan
Shazan Shums
162 posts

Some day I will make quality software.
Programming FTW.

#11520 (Monogame /XNA / Directx) Changing Bottom up drawing to top down.
6 months, 3 weeks ago

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;
        }

Just being curious on programming....