[SOLVED] Aligning the spriteBatch to the 3D Projection/View

I’m trying to draw graphs onto some sprites.
So i want to align the 3D Camera of SpriteBatch and the 3D Camera of my Graphs to be the same but i dont get it to work i tried it another time before and searched the web and some threads on this forum for information but something was always missing and i dont understand till this day how to do this.

So what i want is that Vector3(x,y,0)==Vector2(x,y) on screen.

I tried these methods:
community.monogame.net/t/solved-aligning-2d-and-3d-coordinate-systems/8363 <- bu - Pastebin.com
…[List goes on with stuff that didnt work out]

Maybe any other solutions?

My current Code:
using System;using Microsoft.Xna.Framework;using Microsoft.Xna.Framework.Gra - Pastebin.com

The important part:

var cameraPosition = new Vector3(350, 350, 350);
var cameraLookAtVector = new Vector3(350, 350, 0);
var cameraUpVector = Vector3.UnitZ;
basicEffect.View = Matrix.CreateLookAt(
                cameraPosition, cameraLookAtVector, cameraUpVector);
basicEffect.Projection = Matrix.CreateOrthographicOffCenter(new Rectangle(0, 0, 700, 700), 0.1f, 1000);

My screen size in the project is currently 700x700

1 Like

Projection:

Matrix.CreateOrthographicOffCenter(0f, 700f, 700f, 0f, 0f, -1000f);

View (for the Camera):

Matrix.CreateTranslation(-position) * Matrix.CreateTranslation(-origin) * Matrix.CreateRotationZ(-rotation) * Matrix.CreateScale(zoom) * Matrix.CreateTranslation(origin);

World (for an Entity):

Matrix.CreateTranslation(-origin) * Matrix.CreateScale(scale) * Matrix.CreateFromQuaternion(rotation) * Matrix.CreateTranslation(origin) * Matrix.CreateTranslation(position);
1 Like

this works greatly thanks :slight_smile:
My resolved code looks like this:

basicEffect.View = Matrix.CreateTranslation(-Vector3.Zero) *
Matrix.CreateTranslation(-Vector3.Zero) *
Matrix.CreateRotationZ(-0) *
Matrix.CreateScale(1) *
Matrix.CreateTranslation(Vector3.Zero); ;

basicEffect.World= Matrix.CreateTranslation(-Vector3.Zero) * 
Matrix.CreateScale(1) * 
Matrix.CreateFromQuaternion(new Quaternion(Vector4.Zero)) *
Matrix.CreateTranslation(Vector3.Zero) *
Matrix.CreateTranslation(Vector3.Zero);

basicEffect.Projection = Matrix.CreateOrthographicOffCenter(0f, 700f, 700f, 0f, 0f, -1000f);

giving me this output on my testvertices:


Thanks alot :smiley:

These all create an identity matrix, so the whole thing is equal to Matrix.Identity. Saves you a few lines :slight_smile:

1 Like

Whaat so i finally know the secrets of the identity of the matrix. Nice. Didn’t knew that before xD
This is so nice to know, this explains really a lot why everything didn’t work out before when i always tried to use some function for World and View.

2 Likes