0
$\begingroup$

I did some math with orthographic projection matrix to compute viewing direction vectors in screen space.

I thought all viewing direction vectors should be parallel in orthographic projection because, in orthographic projection, eye sight lines will be always parallel.

However, the math doesn't show the parallel directions.

    QMatrix4x4 proj;
    proj.ortho(-100, 100, -100, 100, 1, 1001);
    qDebug() << "projection matrix:" << proj;
    auto inv = proj.inverted();
    qDebug() << "inverse projection matrix:" << inv;
    qDebug() << "viewing direction at bottom left corner:" << inv.map(QVector3D(-1, -1, 0)).normalized();
    qDebug() << "viewing direction at top right corner  :" << inv.map(QVector3D(1, 1, 0)).normalized();

This is small code to compute what I mentioned and the results are:

projection matrix: QMatrix4x4(type:Translation,Scale
      0.01         0         0         0         
         0      0.01         0         0         
         0         0    -0.002    -1.002         
         0         0         0         1         
)
inverse projection matrix: QMatrix4x4(type:Translation,Scale
       100         0         0         0         
         0       100         0         0         
         0         0      -500      -501         
         0         0         0         1         
)
viewing direction at bottom left corner: QVector3D(-0.192094, -0.192094, -0.962393)
viewing direction at top right corner  : QVector3D(0.192094, 0.192094, -0.962393)

Here, viewing direction vectors at opposite corners don't look parallel.

Did I do something wrong here? Or, did I misunderstand orthographic projection? Why can't I get parallel rays here?

$\endgroup$

1 Answer 1

1
$\begingroup$

You only transferred a single point from projection space to view space.

But you are interested in directions, so you need to convert two points to be able to see the view direction.

//check view direction of lower left corner 
vec4 p0_0 = vec4(-1,-1,0,1);
vec4 p0_1 = vec4(-1,-1,1,1);

//check view direction of upper right corner
vec4 p1_0 = vec4(1,1,0,1);
vec4 p1_1 = vec4(1,1,1,1);

Vec4 ip0_0 = inverprojection * p0_0
Vec4 ip0_1 = inverprojection * p0_1
Vec4 ip1_0 = inverprojection * p1_0
Vec4 ip1_1 = inverprojection * p1_1

So we have two points per view direction test.

Vec4 viewDir0 = ip0_0 - ip0_1
Vec4 viewDir1 = ip1_0 - ip1_1

Last step is to compare viewDir0 with viewDir1

$\endgroup$
1
  • $\begingroup$ You can do exactly the same with perspective projections... But then you need to divide the outcomming vectors by their 4th component... $\endgroup$
    – Thomas
    Commented Dec 1, 2023 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.