]> git.tdb.fi Git - libs/gl.git/blob - source/projection.cpp
Add projection functions
[libs/gl.git] / source / projection.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <cmath>
9 #include <GL/gl.h>
10 #include "projection.h"
11
12 namespace Msp {
13 namespace GL {
14
15 void ortho(double left, double right, double bottom, double top, double near, double far)
16 {
17         glOrtho(left, right, bottom, top, near, far);
18 }
19
20 void ortho_centered(double width, double height)
21 {
22         ortho(-width/2, width/2, -height/2, height/2, 0, 1);
23 }
24
25 void ortho_bottomleft(double width, double height)
26 {
27         ortho(0, width, 0, height, 0, 1);
28 }
29
30 void ortho_topleft(double width, double height)
31 {
32         ortho(0, width, -height, 0, 0, 1);
33 }
34
35 void frustum(double left, double right, double bottom, double top, double near, double far)
36 {
37         glFrustum(left, right, bottom, top, near, far);
38 }
39
40 void frustum_centered(double width, double height, double near, double far)
41 {
42         glFrustum(-width/2, width/2, -height/2, height/2, near, far);
43 }
44
45 void perspective(double fov_y, double aspect, double near, double far)
46 {
47         double hh=tan(fov_y*M_PI/360)*near;
48         frustum(-hh*aspect, hh*aspect, -hh, hh, near, far);
49 }
50
51 } // namespace GL
52 } // namespace Msp