]> git.tdb.fi Git - libs/gl.git/blobdiff - source/projection.cpp
Add projection functions
[libs/gl.git] / source / projection.cpp
diff --git a/source/projection.cpp b/source/projection.cpp
new file mode 100644 (file)
index 0000000..1b7fa61
--- /dev/null
@@ -0,0 +1,52 @@
+/* $Id$
+
+This file is part of libmspgl
+Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include <cmath>
+#include <GL/gl.h>
+#include "projection.h"
+
+namespace Msp {
+namespace GL {
+
+void ortho(double left, double right, double bottom, double top, double near, double far)
+{
+       glOrtho(left, right, bottom, top, near, far);
+}
+
+void ortho_centered(double width, double height)
+{
+       ortho(-width/2, width/2, -height/2, height/2, 0, 1);
+}
+
+void ortho_bottomleft(double width, double height)
+{
+       ortho(0, width, 0, height, 0, 1);
+}
+
+void ortho_topleft(double width, double height)
+{
+       ortho(0, width, -height, 0, 0, 1);
+}
+
+void frustum(double left, double right, double bottom, double top, double near, double far)
+{
+       glFrustum(left, right, bottom, top, near, far);
+}
+
+void frustum_centered(double width, double height, double near, double far)
+{
+       glFrustum(-width/2, width/2, -height/2, height/2, near, far);
+}
+
+void perspective(double fov_y, double aspect, double near, double far)
+{
+       double hh=tan(fov_y*M_PI/360)*near;
+       frustum(-hh*aspect, hh*aspect, -hh, hh, near, far);
+}
+
+} // namespace GL
+} // namespace Msp