]> git.mxchange.org Git - simgear.git/blob - Scenery/sky.c
Initial revision.
[simgear.git] / Scenery / sky.c
1 /**************************************************************************
2  * sky.c -- model sky with an upside down "bowl"
3  *
4  * Written by Curtis Olson, started December 1997.
5  *
6  * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  * $Id$
23  * (Log is kept at end of this file)
24  **************************************************************************/
25
26
27 #ifdef WIN32
28 #  include <windows.h>
29 #endif
30
31 #include <math.h>
32 /*
33 #include <stdio.h>
34 #include <string.h>
35 #include <time.h>
36 */
37
38 #include <GL/glut.h>
39 #include "../XGL/xgl.h"
40
41 #include "sky.h"
42
43 #include "../Time/fg_time.h"
44
45 #include "../Include/constants.h"
46 #include "../Main/views.h"
47 /*
48 #include "../Include/general.h"
49 #include "../Aircraft/aircraft.h"
50 */
51
52 /* in meters of course */
53 #define INNER_RADIUS  50000.0
54 #define INNER_ELEV    20000.0
55 #define MIDDLE_RADIUS 70000.0
56 #define MIDDLE_ELEV   10000.0
57 #define OUTER_RADIUS  80000.0
58 #define OUTER_ELEV        0.0
59
60
61 static GLint sky;  /* sky display list */
62 static float sky_center[12][3];
63 static float sky_middle[12][3];
64 static float sky_outer[12][3];
65
66 /* (Re)generate the display list */
67 void fgSkyInit() {
68     struct fgLIGHT *l;
69     static int dl_exists = 0;
70     float theta;
71     int i;
72
73     l = &cur_light_params;
74
75     if ( dl_exists ) {
76         xglDeleteLists(sky, 1);
77     } else {
78         dl_exists = 1;
79
80         /* first time through, calculate sky vertices */
81         for ( i = 0; i < 12; i++ ) {
82             theta = (i * 30.0) * DEG_TO_RAD;
83
84             sky_center[i][0] = cos(theta) * INNER_RADIUS;
85             sky_center[i][1] = sin(theta) * INNER_RADIUS;
86             sky_center[i][2] = INNER_ELEV;
87             
88             printf(" %.2f %.2f\n", cos(theta) * INNER_RADIUS, 
89                    sin(theta) * INNER_RADIUS);
90
91             sky_middle[i][0] = cos((double)theta) * MIDDLE_RADIUS;
92             sky_middle[i][1] = sin((double)theta) * MIDDLE_RADIUS;
93             sky_middle[i][2] = MIDDLE_ELEV;
94             
95             sky_outer[i][0] = cos((double)theta) * OUTER_RADIUS;
96             sky_outer[i][1] = sin((double)theta) * OUTER_RADIUS;
97             sky_outer[i][2] = OUTER_ELEV;
98             
99         }
100     }
101
102     printf("Creating the sky\n");
103
104     sky = xglGenLists(1);
105     xglNewList(sky, GL_COMPILE );
106
107     /* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear);
108        xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */
109
110     /* Draw inner section */
111     xglBegin( GL_TRIANGLE_FAN );
112
113     xglVertex3f(0.0, 0.0, INNER_ELEV);
114
115     for ( i = 0; i < 12; i++ ) {
116         xglVertex3fv( sky_center[i] );
117     }
118
119     xglEnd();
120
121     xglEndList();
122 }
123
124
125 /* Draw the Sky */
126 void fgSkyRender() {
127     struct fgVIEW *v;
128     /*
129     struct fgFLIGHT *f;
130     struct fgLIGHT *l;
131     struct fgTIME *t;
132     int i;
133     */
134
135     v = &current_view;
136     /*
137     f = &current_aircraft.flight;
138     l = &cur_light_params;
139     t = &cur_time_params;
140     */
141
142     /* FG_PI_2 + 0.1 is about 6 degrees after sundown and before sunrise */
143
144     /* t->sun_angle = 3.0; */ /* to force stars to be drawn (for testing) */
145
146     printf("Rendering the sky.\n");
147
148     xglDisable( GL_LIGHTING );
149
150     xglPushMatrix();
151
152     /* Translate to view position */
153     xglTranslatef( v->cur_zero_elev.x, v->cur_zero_elev.y, v->cur_zero_elev.z );
154
155     xglCallList( sky );
156
157     xglPopMatrix();
158
159     xglEnable( GL_LIGHTING );
160 }
161
162
163 /* $Log$
164 /* Revision 1.1  1997/12/17 23:14:30  curt
165 /* Initial revision.
166 /* Begin work on rendering the sky. (Rather than just using a clear screen.)
167 /*
168  */