LeiaCalculateViews

This is the main function in the SDK, simplifying the math involved in creating the different views. To do this we give native access to leiaCalculateViews. By providing a LeiaCameraView object for each view to this function (along with some other data) the LeiaNativeSDK will populate each view with a perspective matrix to be used later in rendering. The function looks like the following:

int leiaCalculateViews(LeiaCameraData * data,
                       LeiaCameraView * out_views,
                       int len_views_in_x,
                       int len_views_in_y);

data​: A LeiaCameraData object previously filled using leiaIntializeCameraData

out_views​: A two dimensional array of LeiaCameraView objects. If the views were declared as LeiaCameraView views[1][4]​, 1 is the number of views vertically, and 4 is the number of views horizontally.

len_views_in_x​ and ​len_views_in_y​: The number of views in the x and y direction respectively. These values must match the numbers provided in leiaInitializeCameraData.

In the approved layout Leia supports, the normal set of views is 1x4, with 2 views to the left and 2 to the right of the dividing line.

All ​of the cameras will share the plane at the convergence distance, each camera will have a slightly less-wide projection plane than normal. It also means all objects which are exactly on the focal plane will appear the same to each camera. Only objects not on the plane of convergence will appear in different locations on the focal plane, which is where the effect for depth comes from.

Now a perspective matrix exists; we have to use these new matrices. It is very common for games to have a view matrix for the camera, which handles positioning, while the projection for the camera is a different matrix. In this case, the matrices provided by the LeiaCameraView will be the projection matrices. The LeiaCameraView member ​perspective_matrix contains​ the projection matrix as a float array with 16 values. In order to handle the multiplication correctly, it is important to know how the values are laid out in memory, so below gives a mapping (though the description below is not how we compute the final matrix): {(1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (transX, transY, transZ, 1)}.

Multiplying the view matrix with the perspective matrix inside the LeiaCameraView object will provide the correct final matrix, which can be accessed like below:

Mat4 perspective = Mat4(view.perspective_matrix);
mat_vp = perspective * mat_v;

Last updated

Copyright © 2023 Leia Inc. All Rights Reserved