X-Git-Url: https://harrygodden.com/git/?p=vg.git;a=blobdiff_plain;f=vg_m.h;fp=vg_m.h;h=3d4f53ffd53eca654a003663be5a014ea43238d3;hp=436ca63bbd5bf553cc9e39118b7e26cbcad7a1de;hb=1c305409e8eca9cf8449d681df73208956ce14df;hpb=1abb54856257b10f6a20a4980a31930c59e3d37c diff --git a/vg_m.h b/vg_m.h index 436ca63..3d4f53f 100644 --- a/vg_m.h +++ b/vg_m.h @@ -1505,6 +1505,36 @@ static inline void m4x4_inv( m4x4f a, m4x4f d ) v4_muls( d[3], det, d[3] ); } +/* + * http://www.terathon.com/lengyel/Lengyel-Oblique.pdf + */ +static void m4x4_clip_projection( m4x4f mat, v4f plane ){ + v4f c = + { + (vg_signf(plane[0]) + mat[2][0]) / mat[0][0], + (vg_signf(plane[1]) + mat[2][1]) / mat[1][1], + -1.0f, + (1.0f + mat[2][2]) / mat[3][2] + }; + + v4_muls( plane, 2.0f / v4_dot(plane,c), c ); + + mat[0][2] = c[0]; + mat[1][2] = c[1]; + mat[2][2] = c[2] + 1.0f; + mat[3][2] = c[3]; +} + +/* + * Undoes the above operation + */ +static void m4x4_reset_clipping( m4x4f mat, float ffar, float fnear ){ + mat[0][2] = 0.0f; + mat[1][2] = 0.0f; + mat[2][2] = -(ffar + fnear) / (ffar - fnear); + mat[3][2] = -2.0f * ffar * fnear / (ffar - fnear); +} + /* * ----------------------------------------------------------------------------- * Section 5.a Boxes