🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Monogame: can't figure out the Matrix functions

Started by
1 comment, last by CirdanValen 9 years, 1 month ago

My ultimate goal is to get 0,0 to be in the top left of the window, with +y going down and +x going right

Current results: http://i.imgur.com/86DJOXg.png

If I use


Matrix.CreateOrthographic(1280.0F, 720.0F, -1.0F, 1.0F);

I get the result from the first 1/3 of the image above. My squares are centered, but is inverted/mirrored on the y axis.

If I use





Matrix.CreateOrthographicOffCenter(0.0F, 1280.0F, 720F, 0F, 0F, 1.0F);





I get the result from the last 1/3 of the image above. No matter how I translate it via view or world matrix translations, my vertex buffer is never visible on screen. The Matrices do seem to be calculate correctly (if I manually type in the numbers matching the orthographic formula into a calculator, the numbers match), so something else weird is happening.

CreateOrthographic matrix: http://i.imgur.com/Dke62yU.png

CreateOrthographicOffCenter: http://i.imgur.com/35Bky94.png (nothing changes if I remove the fragment offset. it simply shifts by -0.5F)

Vertices of the first square: http://i.imgur.com/N1TAang.png

Code snippet: http://pastebin.com/1cENgaS0

Advertisement

You will want to use Matrix.CreateOrthographicOffCenter(0.0F, 1280.0F, 720F, 0F, 0F, 1.0F)

I'm guessing you have back face culling on which is why you aren't seeing anything when you use the second method. In 2D, when you mirror the x or y axis you need to either reverse your culling or just turn it off.

Documentation for cull mode

https://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.renderstate.cullmode%28v=xnagamestudio.31%29.aspx

My current game project Platform RPG

Yep, that was the problem. Thanks for the help!

This topic is closed to new replies.

Advertisement