From: Michel Pollet Date: Wed, 13 Jun 2012 17:15:58 +0000 (+0100) Subject: c3algebra: Added ortho matrices X-Git-Tag: v1.0~82 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=7bf79ff628dc3c46445a3a5eaf70ac0aa96c927a;p=sx%2Fsimavr.git c3algebra: Added ortho matrices Including screen oriented ones Signed-off-by: Michel Pollet --- diff --git a/examples/shared/libc3/src/c3algebra.c b/examples/shared/libc3/src/c3algebra.c index 7512346..c78b1fb 100644 --- a/examples/shared/libc3/src/c3algebra.c +++ b/examples/shared/libc3/src/c3algebra.c @@ -1033,3 +1033,49 @@ c3mat4 perspective3D(c3f fov, c3f aspect, c3f zNear, c3f zFar) return frustum3D(xmin, xmax, ymin, ymax, zNear, zFar); } + +c3mat4 ortho3D( + c3f left, c3f right, c3f bottom, c3f top, + c3f near, c3f far) +{ + c3f a = 2.0f / (right - left); + c3f b = 2.0f / (top - bottom); + c3f c = -2.0f / (far - near); + + c3f tx = - (right + left)/(right - left); + c3f ty = - (top + bottom)/(top - bottom); + c3f tz = - (far + near)/(far - near); + + float ortho[16] = { + a, 0, 0, 0, + 0, b, 0, 0, + 0, 0, c, 0, + tx, ty, tz, 1 + }; + return *((c3mat4p)ortho); +} + +/* + * Same as previous, but this one is screen aligned, with 0,0 being top,left + * instead of bottom,left + */ +c3mat4 screen_ortho3D( + c3f left, c3f right, c3f bottom, c3f top, + c3f near, c3f far) +{ + c3f a = 2.0f / (right - left); + c3f b = 2.0f / (top - bottom); + c3f c = -2.0f / (far - near); + + c3f tx = - (right + left)/(right - left); + c3f ty = - (top + bottom)/(top - bottom); + c3f tz = - (far + near)/(far - near); + + float ortho[16] = { + a, 0, 0, 0, + 0, -b, 0, 0, + 0, 0, c, 0, + tx, -ty, tz, 1 + }; + return *((c3mat4p)ortho); +} diff --git a/examples/shared/libc3/src/c3algebra.h b/examples/shared/libc3/src/c3algebra.h index 98f93bd..9118031 100644 --- a/examples/shared/libc3/src/c3algebra.h +++ b/examples/shared/libc3/src/c3algebra.h @@ -216,5 +216,11 @@ c3mat4 frustum3D( c3f left, c3f right, c3f bottom, c3f top, c3f znear, c3f zfar); c3mat4 perspective3D(c3f fov, c3f aspect, c3f znear, c3f zfar); +c3mat4 ortho3D( + c3f left, c3f right, c3f bottom, c3f top, + c3f near, c3f far); +c3mat4 screen_ortho3D( + c3f left, c3f right, c3f bottom, c3f top, + c3f near, c3f far); #endif /* __C3ALGEBRA_H___ */