How do you create a orthographic worldviewprojection for draw

This only works with a spritebatch call using identity for view.

        private void SetCameraOrientationOrthagonal3D()
        {
            world = Matrix.Identity;
            //view = Matrix.Identity;
            view = Matrix.CreateLookAt(new Vector3(0, 0, 2), Vector3.Forward, Vector3.Up);
            projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, -1f);
            worldviewprojectionorthagonal = world * view * projection;
        }

however for this i get nothing but blue screen in gl or dx

        public void DrawTestParticleEffect(GameTime gameTime)
        {
            TestParticleEffect.Parameters["MyOffset"].SetValue(backnforth);
            //TestParticleEffect.Parameters["WorldViewProjection"].SetValue(worldviewprojection); // works
            TestParticleEffect.Parameters["WorldViewProjection"].SetValue(worldviewprojectionorthagonal); // nop
            GraphicsDevice.Clear(Color.CornflowerBlue);
            foreach (EffectPass pass in TestParticleEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, 4, indices, 0, 2);
            }
        }

Why did you set your far plane to -1?

lol never mind i figured it out i just misunderstood how the scaling worked under orthographic.
It was there all along just shrunk down cause my quad was one for a regular perspective.

I can get a quad to draw with create perspective but…

Doesn’t seem to matter what i set it to, when i use CreateOrthographic under GL.
Its got me baffled.

the quads 1 in length centered on 0,0,0
set the z on my quad to .5
set it - .5
set the far plane to 2 set it to -2 set it to 500
view identity
view inverted
view aimed
cant get anything on screen.

view = Matrix.CreateLookAt(-Vector3.Zero, Vector3.Forward * 2f, Vector3.Up);
projection = Matrix.CreateOrthographic(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, -2f);

Event the output doesn’t make sense.

and wth is going on with m21 n m22 in the projection matrix.
uh oh wait a minute.
Its a lot easier to see on here i guess lol its already there just shrunk to nothingness.

output

view position:
{X:0 Y:0 Z:0}

world:
{M11:1 M12:0 M13:0 M14:0}
{M21:0 M22:1 M23:0 M24:0}
{M31:0 M32:0 M33:1 M34:0}
{M41:0 M42:0 M43:0 M44:1}

view:
{M11:1 M12:0 M13:0 M14:0}
{M21:0 M22:1 M23:0 M24:0}
{M31:0 M32:0 M33:1 M34:0}
{M41:0 M42:0 M43:0 M44:1}

projection:
{M11:0.0025 M12:0 M13:0 M14:0}
{M21:0 M22:0.004166667 M23:0 M24:0}
{M31:0 M32:0 M33:0.5 M34:0}
{M41:0 M42:0 M43:0 M44:1}

world * view * projection:
{M11:0.0025 M12:0 M13:0 M14:0}
{M21:0 M22:0.004166667 M23:0 M24:0}
{M31:0 M32:0 M33:0.5 M34:0}
{M41:0 M42:0 M43:0 M44:1}

Positions…
[0: {X:-0.5 Y:-0.5 Z:0.5}
[1: {X:-0.5 Y:0.5 Z:0.5}
[2: {X:0.5 Y:-0.5 Z:0.5}
[3: {X:0.5 Y:0.5 Z:0.5}
W Positions transformed as follows…
[0: {X:-0.5 Y:-0.5 Z:0.5}
[1: {X:-0.5 Y:0.5 Z:0.5}
[2: {X:0.5 Y:-0.5 Z:0.5}
[3: {X:0.5 Y:0.5 Z:0.5}
V
P Positions transformed as follows…
[0: {X:-0.00125 Y:-0.002083333 Z:0.25}
[1: {X:-0.00125 Y:0.002083333 Z:0.25}
[2: {X:0.00125 Y:-0.002083333 Z:0.25}
[3: {X:0.00125 Y:0.002083333 Z:0.25}
W
V*P *Positions transformed as follows…
[0: {X:-0.00125 Y:-0.002083333 Z:0.25}
[1: {X:-0.00125 Y:0.002083333 Z:0.25}
[2: {X:0.00125 Y:-0.002083333 Z:0.25}
[3: {X:0.00125 Y:0.002083333 Z:0.25}

Yes, with orthographic projection where left and top are 0, right and bottom are equal to width and height of a screen, a quad of this size will actually be just a pixel. :slight_smile:

Its still messed up though the width height is correct.

Now the image is off center by half its size extending past the upper left. Though maybe thats what orthographicoffcenter is supposed to do.

Too boot it is drawn inverted with perspective -.5 near and -1 far and a identity view matrix.

if i set the projection to positive it dissappears worse the view matrix is looking forward with a negative perspective.

While the z values of the transforms are positive.

        private void CameraPerSpriteBatchOrthographic()
        {
            view = Matrix.Identity;
            projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0f, -.5f, -1f);
        }
        protected override void Draw(GameTime gameTime)
        {
            // ...
            DrawEffectAOrtho(0, 0, 800, 480);
            //...
        }
        public void DrawEffectAOrtho(float xpos, float ypos, float width, float height)
        {
            world = Matrix.CreateTranslation(new Vector3(xpos, ypos, 1)) * Matrix.CreateScale(new Vector3(width, height, 1));
            //SetWorldPositon(xpos, ypos, zpos);
            worldviewprojection = world * view * projection;
            TestEffectA.Parameters["gworldviewprojection"].SetValue(worldviewprojection);

            ConsoleOutInfoJustOnce();

            foreach (EffectPass pass in TestEffectA.CurrentTechnique.Passes)
            {
                pass.Apply();
                GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, 4, indices, 0, 2);
            }
        }

console output …

view position:
{X:0 Y:0 Z:0}

view bering (degrees):
0

world:
{M11:800 M12:0 M13:0 M14:0} {M21:0 M22:480 M23:0 M24:0} {M31:0 M32:0 M33:1 M34:0} {M41:0 M42:0 M43:1 M44:1}

view:
{M11:1 M12:0 M13:0 M14:0} {M21:0 M22:1 M23:0 M24:0} {M31:0 M32:0 M33:1 M34:0} {M41:0 M42:0 M43:0 M44:1}

projection:
{M11:0.0025 M12:0 M13:0 M14:0} {M21:0 M22:-0.004166667 M23:0 M24:0} {M31:0 M32:0 M33:2 M34:0} {M41:-1 M42:1 M43:-1 M44:1}

world * view * projection:
{M11:2 M12:0 M13:0 M14:0} {M21:0 M22:-2 M23:0 M24:0} {M31:0 M32:0 M33:2 M34:0} {M41:-1 M42:1 M43:1 M44:1}

Positions…
[0: {X:-0.5 Y:-0.5 Z:0}
[1: {X:-0.5 Y:0.5 Z:0}
[2: {X:0.5 Y:-0.5 Z:0}
[3: {X:0.5 Y:0.5 Z:0}
W Positions transformed as follows…
[0: {X:-400 Y:-240 Z:1}
[1: {X:-400 Y:240 Z:1}
[2: {X:400 Y:-240 Z:1}
[3: {X:400 Y:240 Z:1}
V
P Positions transformed as follows…
[0: {X:-1.00125 Y:1.002083 Z:-1}
[1: {X:-1.00125 Y:0.9979166 Z:-1}
[2: {X:-0.99875 Y:1.002083 Z:-1}
[3: {X:-0.99875 Y:0.9979166 Z:-1}
W
V*P *Positions transformed as follows…
[0: {X:-2 Y:2 Z:1}
[1: {X:-2 Y:0 Z:1}
[2: {X:0 Y:2 Z:1}
[3: {X:0 Y:0 Z:1}

Ah got it.

yposition has to be added negative though.

private void CameraPerSpriteBatchOrthographic()
        {
            view = Matrix.Identity;
            projection = Matrix.CreateOrthographic(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, -.5f, -1f);
        }
public void DrawEffectAOrtho(float xpos, float ypos, float width, float height)
        {
            world = Matrix.CreateScale(new Vector3(width, height, 1f));
            world.Translation = new Vector3(xpos, -ypos, 1f);
            //SetWorldPositon(xpos, ypos, zpos);
            worldviewprojection = world * view * projection;
            TestEffectA.Parameters["gworldviewprojection"].SetValue(worldviewprojection);

            JustOnce();

            foreach (EffectPass pass in TestEffectA.CurrentTechnique.Passes)
            {
                pass.Apply();
                GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, 4, indices, 0, 2);
            }
        }

Now i just wanna get the matrixs on the gpu.
And be able to alter the vertices individually on the gpu as well in the vertex shader, which i have no idea how to do.