1 /**************************************************************************
2 * sky.c -- model sky with an upside down "bowl"
4 * Written by Curtis Olson, started December 1997.
6 * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
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.
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.
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.
23 * (Log is kept at end of this file)
24 **************************************************************************/
39 #include "../XGL/xgl.h"
43 #include "../Time/fg_time.h"
45 #include "../Aircraft/aircraft.h"
46 #include "../Flight/flight.h"
47 #include "../Include/constants.h"
48 #include "../Main/views.h"
50 #include "../Include/general.h"
53 /* in meters of course */
54 #define INNER_RADIUS 50000.0
55 #define INNER_ELEV 8000.0 /* was 20000 */
56 #define MIDDLE_RADIUS 70000.0
57 #define MIDDLE_ELEV 10000.0
58 #define OUTER_RADIUS 80000.0
59 #define OUTER_ELEV 0.0
62 static GLint sky; /* sky display list */
63 static float sky_center[12][3];
64 static float sky_middle[12][3];
65 static float sky_outer[12][3];
67 /* (Re)generate the display list */
70 static int dl_exists = 0;
74 l = &cur_light_params;
77 xglDeleteLists(sky, 1);
81 /* first time through, calculate sky vertices */
82 for ( i = 0; i < 12; i++ ) {
83 theta = (i * 30.0) * DEG_TO_RAD;
85 sky_center[i][0] = cos(theta) * INNER_RADIUS;
86 sky_center[i][1] = sin(theta) * INNER_RADIUS;
87 sky_center[i][2] = INNER_ELEV;
89 printf(" %.2f %.2f\n", cos(theta) * INNER_RADIUS,
90 sin(theta) * INNER_RADIUS);
92 sky_middle[i][0] = cos((double)theta) * MIDDLE_RADIUS;
93 sky_middle[i][1] = sin((double)theta) * MIDDLE_RADIUS;
94 sky_middle[i][2] = MIDDLE_ELEV;
96 sky_outer[i][0] = cos((double)theta) * OUTER_RADIUS;
97 sky_outer[i][1] = sin((double)theta) * OUTER_RADIUS;
98 sky_outer[i][2] = OUTER_ELEV;
103 printf("Creating the sky\n");
105 sky = xglGenLists(1);
106 xglNewList(sky, GL_COMPILE );
108 /* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear);
109 xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */
111 /* Draw inner section */
112 xglBegin( GL_TRIANGLE_FAN );
114 xglColor3f(0.0, 0.0, 1.0);
115 xglVertex3f(0.0, 0.0, INNER_ELEV);
117 xglColor3f(0.2, 0.2, 1.0);
118 for ( i = 0; i < 12; i++ ) {
119 xglVertex3fv( sky_center[i] );
121 xglVertex3fv( sky_center[0] );
139 f = ¤t_aircraft.flight;
142 l = &cur_light_params;
143 t = &cur_time_params;
146 /* FG_PI_2 + 0.1 is about 6 degrees after sundown and before sunrise */
148 /* t->sun_angle = 3.0; */ /* to force stars to be drawn (for testing) */
150 printf("Rendering the sky.\n");
152 xglDisable( GL_LIGHTING );
156 /* Translate to view position */
157 xglTranslatef( v->cur_zero_elev.x, v->cur_zero_elev.y, v->cur_zero_elev.z );
158 /* printf(" Translated to %.2f %.2f %.2f\n",
159 v->cur_zero_elev.x, v->cur_zero_elev.y, v->cur_zero_elev.z ); */
161 printf(" lon = %.2f lat = %.2f\n", FG_Longitude * RAD_TO_DEG,
162 FG_Latitude * RAD_TO_DEG);
163 xglRotatef( FG_Longitude * RAD_TO_DEG, 0.0, 0.0, 1.0 );
164 xglRotatef( 90.0 - FG_Latitude * RAD_TO_DEG, 0.0, 1.0, 0.0 );
170 xglEnable( GL_LIGHTING );
175 /* Revision 1.2 1997/12/18 04:07:03 curt
176 /* Worked on properly translating and positioning the sky dome.
178 * Revision 1.1 1997/12/17 23:14:30 curt
180 * Begin work on rendering the sky. (Rather than just using a clear screen.)