Commit 7bf79ff628dc3c46445a3a5eaf70ac0aa96c927a
authorMichel Pollet <buserror@gmail.com>
Wed, 13 Jun 2012 17:15:58 +0000 (18:15 +0100)
committerMichel Pollet <buserror@gmail.com>
Wed, 13 Jun 2012 17:15:58 +0000 (18:15 +0100)
Including screen oriented ones

Signed-off-by: Michel Pollet <buserror@gmail.com>
2 files changed:
examples/shared/libc3/src/c3algebra.c
examples/shared/libc3/src/c3algebra.h

index 7512346ddc88b2272be9d748370cec1a9866d876..c78b1fb4791e4f2143fe47e944e3994977ef77e5 100644 (file)
@@ -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);
+}
index 98f93bd4a207490d8a66fb045bf71657d595505a..9118031baa614af8fd67bffd9764e170ba8bc79d 100644 (file)
@@ -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___ */