]> git.tdb.fi Git - libs/gl.git/blob - source/projection.cpp
Drop Id tags and copyright notices from files
[libs/gl.git] / source / projection.cpp
1 #include <cmath>
2 #include "matrix.h"
3 #include "projection.h"
4
5 namespace Msp {
6 namespace GL {
7
8 extern MatrixStack *active_stack;
9
10 void ortho(double left, double right, double bottom, double top, double nearr, double farr)
11 {
12         *active_stack *= Matrix::ortho(left, right, bottom, top, nearr, farr);
13 }
14
15 void ortho_centered(double width, double height)
16 {
17         ortho(-width/2, width/2, -height/2, height/2, 0, 1);
18 }
19
20 void ortho_bottomleft(double width, double height)
21 {
22         ortho(0, width, 0, height, 0, 1);
23 }
24
25 void ortho_topleft(double width, double height)
26 {
27         ortho(0, width, height, 0, 0, 1);
28 }
29
30 void frustum(double left, double right, double bottom, double top, double nearr, double farr)
31 {
32         *active_stack *= Matrix::frustum(left, right, bottom, top, nearr, farr);
33 }
34
35 void frustum_centered(double width, double height, double nearr, double farr)
36 {
37         frustum(-width/2, width/2, -height/2, height/2, nearr, farr);
38 }
39
40 void perspective(double fov_y, double aspect, double nearr, double farr)
41 {
42         double hh = tan(fov_y*M_PI/360)*nearr;
43         frustum(-hh*aspect, hh*aspect, -hh, hh, nearr, farr);
44 }
45
46 } // namespace GL
47 } // namespace Msp