how can I make vector3 y axis from 0 not to 0 ?

how can I make vector3 y-axis from 0, not to 0?
It’s a bit annoying when working with vertices :slight_smile: or just deal with it ?

Edit:

I personally don’t recommend fliping the coordinate system its a pain in the ass to get spritebatch to work like this and any examples you see or use will have to be altered.
Further even this example is incomplete you will also need to use the full spritebatch overloads and use spriteEffects.FlipVertical on all your draw calls.
Or write a pixel shader to do it and use it in all your pixel shaders.

anyways…

You will need to create a BasicEffect to change the projection matrix to do this.
Besides turning on the regular stuff like vertex coloring = true ect… and passing it to SpriteBatch.Begin(,); There will be a few things you need to do.

You will need the following in relation to the projection matrix specifically.

You need to make a bottom up projection matrix i believe you would want to flip the y as well with a scalar.

Viewport viewport = GraphicsDevice.Viewport;
basicEffect.Projection = Matrix.CreateScale(1, -1, 1) * Matrix.CreateOrthographicOffCenter(0, viewport.Width, 0, viewport.Height, 0, 1);

After you clear you’re graphics device or in or after you call begin you will also need to set the culling to none.

GraphicsDevice.RasterizerState = RasterizerState.CullNone;

It was hard to explain it all or to be sure it was right without double checking.
So i just wrote out a example. It’s probably easier to just look it over.

The example
Create a new project.
Copy paste this game1’s text over the new projects game1 text.
Change the namespace to your own projects namespace.
Run it.

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace YourNamespace
{
    public class Game1: Game
    {
        public static GraphicsDeviceManager graphics;
        public static SpriteBatch spriteBatch;
        public static BasicEffect basicEffect;
        public static Texture2D generatedTexture;

        public static Vector3 camScrollPosition = new Vector3(0, 0, 0);
        public static Vector3 camLookAt = new Vector3(0, 0, 1);
        public static float camRotationZ = 0f;
        public static Vector3 camUp = Vector3.Up;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            graphics.GraphicsProfile = GraphicsProfile.HiDef;
        }

        protected override void Initialize()
        {
            graphics.PreferredBackBufferWidth = 500;
            graphics.PreferredBackBufferHeight = 500;
            graphics.ApplyChanges();

            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            basicEffect = new BasicEffect(this.GraphicsDevice);
            generatedTexture = GenerateTexture2DWithTopLeftDiscoloration();
            SetUpBasicEffect();
        }

        public Texture2D GenerateTexture2DWithTopLeftDiscoloration()
        {
            Texture2D t = new Texture2D(this.GraphicsDevice, 250, 250);
            var cdata = new Color[250 * 250];
            for (int i = 0; i < 250; i++)
            {
                for (int j = 0; j < 250; j++)
                {
                    if (i < 50 && j < 50)
                        cdata[i * 250 + j] = new Color(120, 100, 100, 250);
                    else
                        cdata[i * 250 + j] = Color.White;
                }
            }
            t.SetData(cdata);
            return t;
        }

        protected override void UnloadContent()
        {
            generatedTexture.Dispose();
        }

        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();
            base.Update(gameTime);
        }


        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, RasterizerState.CullNone, basicEffect, null);

            spriteBatch.Draw(generatedTexture, new Rectangle(000, 000, 200, 200), Color.Beige);
            spriteBatch.Draw(generatedTexture, new Rectangle(100, 100, 200, 200), Color.Green);

            spriteBatch.End();

            base.Draw(gameTime);
        }

        public void SetUpBasicEffect()
        {
            // Set up basic effects globals
            basicEffect.VertexColorEnabled = true;
            basicEffect.TextureEnabled = true;
            // Set up our matrices.
            Viewport viewport = GraphicsDevice.Viewport;
            basicEffect.Projection = Matrix.CreateScale(1, -1, 1) * Matrix.CreateOrthographicOffCenter(0, viewport.Width, 0, viewport.Height, 0, 1);
            basicEffect.World = Matrix.Identity;
            SetCameraRotation(camRotationZ);
        }

        public void SetCameraPosition2D(int x, int y)
        {
            camScrollPosition.X = x;
            camScrollPosition.Y = y;
            camScrollPosition.Z = 0;
            camLookAt.X = x;
            camLookAt.Y = y;
            camLookAt.Z = 1;
            UpdateViewMatrix();
        }
        public void SetCameraRotation(float rotation)
        {
            // 3d methods work for 2d as you can see, refer to SetCameraPosition2D(...)
            camRotationZ = rotation;
            camUp = Vector3.Transform(new Vector3(0, -1, 0), Matrix.CreateRotationZ(camRotationZ));
            UpdateViewMatrix();
        }
        public void UpdateViewMatrix()
        {
            basicEffect.View = Matrix.CreateLookAt(camScrollPosition, camLookAt, camUp);
        }
    }
}

Eh. I will just keep classic xna way then.

Ya i would stay with the regular coordinate system.
Doing this isn’t so bad with custom vertices because you can just realign the vertices and do it all yourself. You can’t do that to spritebatch internally unless you rebuild it from source there is no way to get at the vertice ordering.

Unless someone knows a more proper way to deal with the vertice flip.
I don’t think its worth it under spritebatch.