]> git.jsancho.org Git - lugaru.git/blob - Dependencies/GLU/util.c
CMake: Purge all the bundled dependencies
[lugaru.git] / Dependencies / GLU / util.c
1 // These are just the bits of GLU we use so we can ditch the external
2 //  dependency (since it turns out to be complicated, as it depends on libGL,
3 //  which we load dynamically, etc). This is from SGI's open source version.
4
5 /*
6  * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
7  * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the "Software"),
11  * to deal in the Software without restriction, including without limitation
12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  * and/or sell copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice including the dates of first publication and
17  * either this permission notice or a reference to
18  * http://oss.sgi.com/projects/FreeB/
19  * shall be included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
26  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE.
28  *
29  * Except as contained in this notice, the name of Silicon Graphics, Inc.
30  * shall not be used in advertising or otherwise to promote the sale, use or
31  * other dealings in this Software without prior written authorization from
32  * Silicon Graphics, Inc.
33  */
34
35 #include <stdio.h>
36 #include <math.h>
37 #include "GL/gl.h"
38 #include "GL/glu.h"
39
40 /*
41 ** Make m an identity matrix
42 */
43 static void __gluMakeIdentityd(GLdouble m[16])
44 {
45     m[0+4*0] = 1; m[0+4*1] = 0; m[0+4*2] = 0; m[0+4*3] = 0;
46     m[1+4*0] = 0; m[1+4*1] = 1; m[1+4*2] = 0; m[1+4*3] = 0;
47     m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0;
48     m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1;
49 }
50
51 static void __gluMakeIdentityf(GLfloat m[16])
52 {
53     m[0+4*0] = 1; m[0+4*1] = 0; m[0+4*2] = 0; m[0+4*3] = 0;
54     m[1+4*0] = 0; m[1+4*1] = 1; m[1+4*2] = 0; m[1+4*3] = 0;
55     m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0;
56     m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1;
57 }
58
59 void GLAPIENTRY
60 gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top)
61 {
62     glOrtho(left, right, bottom, top, -1, 1);
63 }
64
65 #define __glPi 3.14159265358979323846
66
67 void GLAPIENTRY
68 gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
69 {
70     GLdouble m[4][4];
71     double sine, cotangent, deltaZ;
72     double radians = fovy / 2 * __glPi / 180;
73
74     deltaZ = zFar - zNear;
75     sine = sin(radians);
76     if ((deltaZ == 0) || (sine == 0) || (aspect == 0)) {
77         return;
78     }
79     cotangent = cos(radians) / sine;
80
81     __gluMakeIdentityd(&m[0][0]);
82     m[0][0] = cotangent / aspect;
83     m[1][1] = cotangent;
84     m[2][2] = -(zFar + zNear) / deltaZ;
85     m[2][3] = -1;
86     m[3][2] = -2 * zNear * zFar / deltaZ;
87     m[3][3] = 0;
88     glMultMatrixd(&m[0][0]);
89 }
90