Skip to content

Commit

Permalink
[core.matrix] added matrix_persp and matrix_persp_nofar. no they have…
Browse files Browse the repository at this point in the history
…nt been tested and could easily be wrong
  • Loading branch information
harrand committed Nov 1, 2024
1 parent 93c31e7 commit 74f07a0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/tz/core/trs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace tz
tz::m4f matrix_translate(tz::v3f translate);
tz::m4f matrix_scale(tz::v3f scale);
tz::m4f matrix_ortho(float left, float right, float top, float bottom, float near, float far);
tz::m4f matrix_persp(float fov, float aspect_ratio, float near, float far);
tz::m4f matrix_persp_nofar(float fov, float aspect_ratio, float near);

struct trs
{
Expand Down
27 changes: 27 additions & 0 deletions src/tz/core/trs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,33 @@ namespace tz
return ret;
}

tz::m4f matrix_persp(float fov, float aspect_ratio, float near, float far)
{
tz::m4f ret = tz::m4f::iden();
const float thf = std::tan(fov / 2.0f);
ret(0, 0) = 1.0f / (aspect_ratio * thf);
ret(1, 1) = 1.0f / thf;

ret(2, 2) = (far + near) / (near - far);
ret(2, 3) = -1.0f;

ret(3, 2) = (2.0f * far * near) / (near - far);
ret(3, 3) = 0.0f;
return ret;
}

tz::m4f matrix_persp_nofar(float fov, float aspect_ratio, float near)
{
tz::m4f ret = tz::m4f::iden();
ret(0, 0) = fov / aspect_ratio;
ret(1, 1) = fov;
ret(2, 2) = 0.0f;
ret(3, 2) = -near;
ret(2, 3) = -1.0f;
ret(3, 3) = 0.0f;
return ret;
}

trs trs::lerp(const trs& rhs, float factor) const
{
trs ret;
Expand Down

0 comments on commit 74f07a0

Please sign in to comment.