Skip to content

Commit

Permalink
simplified case
Browse files Browse the repository at this point in the history
  • Loading branch information
t-weber committed Aug 23, 2021
1 parent 530ad15 commit a666b6e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
31 changes: 31 additions & 0 deletions libs/math_algos.h
Expand Up @@ -3398,6 +3398,37 @@ requires is_mat<t_mat>
}


/**
* parallel projection matrix (homogeneous 4x4)
* set bZ01=false for gl (near and far planes at -1 and +1), and bZ01=true for vk (planes at 0 and 1)
* @see https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glOrtho.xml
* @see https://github.com/PacktPublishing/Vulkan-Cookbook/blob/master/Library/Source%20Files/10%20Helper%20Recipes/05%20Preparing%20an%20orthographic%20projection%20matrix.cpp
*/
template<class t_mat>
t_mat hom_parallel_sym(
typename t_mat::value_type n = 0.01, typename t_mat::value_type f = 100.,
typename t_mat::value_type w = 4, typename t_mat::value_type h = 4.,
bool bInvZ = false, bool bZ01 = false, bool bInvY = false)
requires is_mat<t_mat>
{
using T = typename t_mat::value_type;

const T d = n - f;

const T sc = bZ01 ? T(1) : T(2);
const T f0 = bZ01 ? T(0) : f;
const T ys = bInvY ? T(-1) : T(1);
const T zs = bInvZ ? T(-1) : T(1);

return create<t_mat>({
T(2)/w, 0., 0., 0.,
0, T(2)*ys/h, 0., 0.,
0., 0., sc*zs/d, zs*(n+f0)/d,
0., 0., 0., 1.
});
}


/**
* viewport matrix (homogeneous 4x4)
* @see https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glViewport.xml
Expand Down
4 changes: 2 additions & 2 deletions qt/vk-4-phys/qttst.cpp
Expand Up @@ -1206,8 +1206,8 @@ void VkRenderer::UpdatePerspective()
// orthogonal projection
else
{
m_matPerspective = m::hom_parallel<t_mat>(
0.01, 100., -4., 4., -4, 4., false, true, true);
m_matPerspective = m::hom_parallel_sym<t_mat>(
0.01, 100., 4., 4., false, true, true);
}

std::tie(m_matPerspective_inv, std::ignore) = m::inv<t_mat, t_vec>(m_matPerspective);
Expand Down

0 comments on commit a666b6e

Please sign in to comment.