1 /*
2 OpenUniverse 1.0
3 Copyright (C) 2000 Raul Alonso <amil@las.es>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include "ou.h"
21
22
SunBillBoard(double size)23 void SunBillBoard(double size)
24 {
25 double p1[3], p2[3], p3[3], p4[3];
26 double alfa, beta, cosalfa, cosbeta, sinalfa, sinbeta;
27 double x, y, z;
28
29 /* this macro by Sebastien Metrot */
30 #define ROTATE(V) \
31 do { \
32 y = V[Y]*cosbeta + V[Z]*sinbeta; \
33 z = -V[Y]*sinbeta + V[Z]*cosbeta; \
34 x = V[X]*cosalfa - z*sinalfa; \
35 z = V[X]*sinalfa + z*cosalfa; \
36 V[X]=x; V[Y]=y; V[Z]=z; \
37 } while (0);
38
39
40 p1[X] = p4[X] = p1[Y] = p2[Y] = size;
41 p2[X] = p3[X] = p3[Y] = p4[Y] = -size;
42 p1[Z] = p2[Z] = p3[Z] = p4[Z] = 0.0;
43
44 /* BILLBOARDING effect, rotates sun tile so it shows always the same face and
45 angle to camera */
46 alfa = atan2(campos[Z], campos[X]) - M_PI / 2.0;
47 beta =
48 atan2(campos[Y],
49 sqrt(campos[X] * campos[X] + campos[Z] * campos[Z]));
50
51 cosalfa = cos(alfa);
52 cosbeta = cos(beta);
53 sinalfa = sin(alfa);
54 sinbeta = sin(beta);
55
56 ROTATE(p1);
57 ROTATE(p2);
58 ROTATE(p3);
59 ROTATE(p4);
60
61 glEnable(GL_BLEND);
62 glDepthMask(GL_FALSE);
63 glBlendFunc(GL_ONE, GL_ONE);
64 glBegin(GL_QUADS);
65 glTexCoord2f(0.0, 0.0);
66 glVertex3f(p1[X], p1[Y], p1[Z]);
67 glTexCoord2f(0.0, 1.0);
68 glVertex3f(p2[X], p2[Y], p2[Z]);
69 glTexCoord2f(1.0, 1.0);
70 glVertex3f(p3[X], p3[Y], p3[Z]);
71 glTexCoord2f(1.0, 0.0);
72 glVertex3f(p4[X], p4[Y], p4[Z]);
73 glEnd();
74 glDisable(GL_BLEND);
75 glDepthMask(GL_TRUE);
76 }
77