c3algebra: Added ortho matrices
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>
examples/shared/libc3/src/c3algebra.c
examples/shared/libc3/src/c3algebra.h

index 7512346..c78b1fb 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 98f93bd..9118031 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___ */