]> git.mxchange.org Git - simgear.git/blob - Scenery/sky.c
First stab at sky dome actually starting to look reasonable. :-)
[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 "../Aircraft/aircraft.h"
46 #include "../Flight/flight.h"
47 #include "../Include/constants.h"
48 #include "../Main/views.h"
49 #include "../Math/fg_random.h"
50 /*
51 #include "../Include/general.h"
52 */
53
54 /* in meters of course */
55 #define INNER_RADIUS  50000.0
56 #define INNER_ELEV    20000.0
57 #define MIDDLE_RADIUS 70000.0
58 #define MIDDLE_ELEV    4000.0
59 #define OUTER_RADIUS  80000.0
60 #define OUTER_ELEV        0.0
61
62
63 static float sky_center[12][3];
64 static float sky_middle[12][3];
65 static float sky_outer[12][3];
66
67 /* (Re)generate the display list */
68 void fgSkyInit() {
69     struct fgLIGHT *l;
70     float theta;
71     int i;
72
73     l = &cur_light_params;
74
75     printf("Generating the sky dome vertices.\n");
76
77     for ( i = 0; i < 12; i++ ) {
78         theta = (i * 30.0) * DEG_TO_RAD;
79         
80         sky_center[i][0] = cos(theta) * INNER_RADIUS;
81         sky_center[i][1] = sin(theta) * INNER_RADIUS;
82         sky_center[i][2] = INNER_ELEV;
83         
84         printf(" %.2f %.2f\n", cos(theta) * INNER_RADIUS, 
85                sin(theta) * INNER_RADIUS);
86
87         sky_middle[i][0] = cos((double)theta) * MIDDLE_RADIUS;
88         sky_middle[i][1] = sin((double)theta) * MIDDLE_RADIUS;
89         sky_middle[i][2] = MIDDLE_ELEV;
90             
91         sky_outer[i][0] = cos((double)theta) * OUTER_RADIUS;
92         sky_outer[i][1] = sin((double)theta) * OUTER_RADIUS;
93         sky_outer[i][2] = OUTER_ELEV;
94             
95     }
96 }
97
98
99 /* Draw the Sky */
100 void fgSkyRender() {
101     struct fgFLIGHT *f;
102     struct fgVIEW *v;
103     int i;
104
105     f = &current_aircraft.flight;
106     v = &current_view;
107
108     printf("Rendering the sky.\n");
109
110     xglDisable( GL_LIGHTING );
111     xglDisable( GL_CULL_FACE );
112     xglShadeModel( GL_SMOOTH );
113
114     xglPushMatrix();
115
116     /* Translate to view position */
117     xglTranslatef( v->cur_zero_elev.x, v->cur_zero_elev.y, v->cur_zero_elev.z );
118     /* printf("  Translated to %.2f %.2f %.2f\n", 
119            v->cur_zero_elev.x, v->cur_zero_elev.y, v->cur_zero_elev.z ); */
120
121     /* Rotate to proper orientation */
122     printf("  lon = %.2f  lat = %.2f\n", FG_Longitude * RAD_TO_DEG,
123            FG_Latitude * RAD_TO_DEG);
124     xglRotatef( FG_Longitude * RAD_TO_DEG, 0.0, 0.0, 1.0 );
125     xglRotatef( 90.0 - FG_Latitude * RAD_TO_DEG, 0.0, 1.0, 0.0 );
126
127     /* xglMaterialfv(GL_FRONT, GL_AMBIENT, l->scene_clear);
128        xglMaterialfv(GL_FRONT, GL_DIFFUSE, moon_color); */
129
130     /* Draw inner/center section of sky*/
131     xglBegin( GL_TRIANGLE_FAN );
132     xglColor4f(0.0, 0.0, 1.0, 1.0);
133     xglVertex3f(0.0, 0.0, INNER_ELEV);
134     xglColor4f(0.2, 0.2, 0.8, 1.0);
135     for ( i = 0; i < 12; i++ ) {
136         xglVertex3fv( sky_center[i] );
137     }
138     xglVertex3fv( sky_center[0] );
139     xglEnd();
140
141     /* Draw the middle ring */
142     xglBegin( GL_TRIANGLE_STRIP );
143     for ( i = 0; i < 12; i++ ) {
144         xglVertex3fv( sky_middle[i] );
145         xglVertex3fv( sky_center[i] );
146     }
147     xglVertex3fv( sky_middle[0] );
148     xglVertex3fv( sky_center[0] );
149     xglEnd();
150
151     /* Draw the outer ring */
152     xglBegin( GL_TRIANGLE_STRIP );
153     for ( i = 0; i < 12; i++ ) {
154         xglVertex3fv( sky_outer[i] );
155         xglVertex3fv( sky_middle[i] );
156     }
157     xglVertex3fv( sky_outer[0] );
158     xglVertex3fv( sky_middle[0] );
159     xglEnd();
160
161     xglPopMatrix();
162
163     xglShadeModel( GL_FLAT ); 
164     xglEnable( GL_CULL_FACE );
165     xglEnable( GL_LIGHTING );
166 }
167
168
169 /* $Log$
170 /* Revision 1.3  1997/12/18 23:32:36  curt
171 /* First stab at sky dome actually starting to look reasonable. :-)
172 /*
173  * Revision 1.2  1997/12/18 04:07:03  curt
174  * Worked on properly translating and positioning the sky dome.
175  *
176  * Revision 1.1  1997/12/17 23:14:30  curt
177  * Initial revision.
178  * Begin work on rendering the sky. (Rather than just using a clear screen.)
179  *
180  */