Jump to content

Which aspect ration shoud I use for the multiplication of m00 when setting the projection matrix?


photo

Recommended Posts

Hi,

 

In stereo.h when a projection matrix is calculated the frustum() fuction from MathLib.cpp is used.

The matrix calculation in this function is completely as expected (according the theory).

But before the projections matrix is set (using setProjection()) the m00 element of the matrix is multiplied

by the screen aspect ratio (width/height) as below.

 

mat4 projection = frustum(points[0].x,points[1].x,points[0].y,points[2].y,-points[0].z,-points[4].z);

projection.m00 *= aspect;

 

It is not clear to my why this is done. If I do not do that in my own code, the rendered objects appear verticaly streched on the screen.

I would like to know why this is done, because I wrote my own stereo.h equivalent with headtracking support.

 

The question is which aspect ration should I use in my case.

The problem is that I calculate the frustum using physical screen dimensions. So you may think I should multiply by the

screenWidth/screenHeigth (using physical dimensions).

But at many places where the projection matrix is used, the m00 element is divided by the aspect expressed in number of

pixels (e.g. aspect = float(engine.app.getWidth()) / engine.app.getHeight()).

In many cases the pixels are square so that it does not matter. But pixels need not to be square.

 

So which aspect ration shoud I use for the multiplication of m00 when setting the projection matrix?

 

I hope somebody can help me on this.

Link to comment

Unigine renderer takes a square projection matrix that does not depend on the viewport aspect. When rendering onto the screen, it transforms the matrix according to the dimensions of the app window it needs to be rendered into. Such approach is more transparent when handling players and the magic is all inside the black box - until it comes to multi-monitor apps. In this case the steps to calculate custom projection matrices are as follows:

  1. Calculate all matrices as you need them according to your custom viewport aspect.
  2. Adjust projection matrices to be square ones. For that, you simply need to divide them by the app window aspect.
  3. The renderer will automatically stretch the image to be rectangular and you will get proper proportions on the screen.

I hope that clears the situation up.

Link to comment
×
×
  • Create New...