0
\$\begingroup\$

I'm trying to create the correct projection and model view matrix for rendering without a camera.

_orthoCamera is a camera I set up in the scene view. Using the _orthoCamera projection matrix and modelView matrix works but I don't know exactly how to recreate these. My attempt is the commented code.

    //not correct
    //var projection = Matrix4x4.Ortho(-512, 512, -512, 512, 0.3f, 1000);
    //var modelView = Matrix4x4.LookAt(new Vector3(512, 512, -5), new Vector3(512, 512, 0), Vector3.up); //inverse?

    //correct result
    var projection = _orthoCamera.projectionMatrix;
    var modelView = _orthoCamera.worldToCameraMatrix;

    GL.LoadProjectionMatrix(projection);
    GL.modelview = (modelView);

This is how I set the camera up in the scene. Camera settings in the scene

\$\endgroup\$
2
  • \$\begingroup\$ Can you explain why placing an (unused) camera in your scene and using its matrices is not an option? \$\endgroup\$
    – DMGregory
    Mar 8, 2019 at 12:46
  • \$\begingroup\$ I have to repeat this kind of process for a bunch of different positions and sizes in different scenes. Keeping track of / recreating the camera adds unnecessary state, muddying the process. \$\endgroup\$
    – David H
    Mar 8, 2019 at 13:29

1 Answer 1

1
\$\begingroup\$

Ended up going with this. Based on this documentation.

var orthoSize = 512f;
var projection = Matrix4x4.Ortho(-orthoSize, orthoSize, -orthoSize, orthoSize, 0.3f, 1000);
var offset = new Vector3(512, 512, -5);
var modelView = Matrix4x4.TRS(new Vector3(-offset.x, -offset.y, offset.z), Quaternion.identity, new Vector3(1,1,-1));
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .