Hi all! I’m new here and new to OpenGL, hope this is the right place to post.
I am drawing 2d sprites by using an orthographic projection but I also want to be able to rotate them with perspective-correct texture behavior.
How do I go about positioning and scaling my sprites in 3d space to get them pixel perfect with a perspective projection?
Edit: I seem to have hacked together something that works but I don’t understand how it works:
float aspect = ClientRectangle.Width / (float)ClientRectangle.Height;
Matrix4 p = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspect, 0.01f, 10000f);
float z = ClientRectangle.Height * 1.208f;
p = Matrix4.Identity;
p *= Matrix4.CreateTranslation(-ClientRectangle.Width / 2f, -ClientRectangle.Height / 2f, 0);
p *= Matrix4.LookAt(new Vector3(0, 0, z), new Vector3(0, 0, -1), Vector3.UnitY);
p *= Matrix4.Scale(1f,-1f,1f);
Can someone explain what the magic number 1.208 means and where it comes from? I calculated it from literaly sticking in random z values until it ‘looked about right’. After two sets of screen height and z values I worked out that number and it’s somehow giving me pixel perfect results.