]> git.tdb.fi Git - libs/gl.git/blob - source/projection.cpp
dc690f49f8d65376e7d858f84a0a38488c4b446f
[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 "matrix.h"
10 #include "projection.h"
11
12 namespace Msp {
13 namespace GL {
14
15 extern MatrixStack *active_stack;
16
17 void ortho(double left, double right, double bottom, double top, double nearr, double farr)
18 {
19         *active_stack *= Matrix::ortho(left, right, bottom, top, nearr, farr);
20 }
21
22 void ortho_centered(double width, double height)
23 {
24         ortho(-width/2, width/2, -height/2, height/2, 0, 1);
25 }
26
27 void ortho_bottomleft(double width, double height)
28 {
29         ortho(0, width, 0, height, 0, 1);
30 }
31
32 void ortho_topleft(double width, double height)
33 {
34         ortho(0, width, height, 0, 0, 1);
35 }
36
37 void frustum(double left, double right, double bottom, double top, double nearr, double farr)
38 {
39         *active_stack *= Matrix::frustum(left, right, bottom, top, nearr, farr);
40 }
41
42 void frustum_centered(double width, double height, double nearr, double farr)
43 {
44         frustum(-width/2, width/2, -height/2, height/2, nearr, farr);
45 }
46
47 void perspective(double fov_y, double aspect, double nearr, double farr)
48 {
49         double hh = tan(fov_y*M_PI/360)*nearr;
50         frustum(-hh*aspect, hh*aspect, -hh, hh, nearr, farr);
51 }
52
53 } // namespace GL
54 } // namespace Msp