]> git.mxchange.org Git - flightgear.git/blob - Scenery/astro.c
8ebe0623a56381f5cc3771b72d6c71ec6243bb06
[flightgear.git] / Scenery / astro.c
1 /**************************************************************************
2  * astro.c
3  *
4  * Written by Durk Talsma. Started November 1997, for use with the flight
5  * gear project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * $Id$
22  * (Log is kept at end of this file)
23  **************************************************************************/
24
25
26 #include <math.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <time.h>
30
31 #include <GL/glut.h>
32
33 #include "astro.h"
34 #include "moon.h"
35 #include "orbits.h"
36 #include "planets.h"
37 #include "stars.h"
38 #include "sun.h"
39
40 #include "../constants.h"
41 #include "../general.h"
42
43 #include "../Main/views.h"
44 #include "../Aircraft/aircraft.h"
45 #include "../Time/fg_time.h"
46
47 static double prevUpdate = 0;
48
49
50 /* Initialize Astronomical Objects */
51 void fgAstroInit() {
52     struct fgTIME *t;
53     t = &cur_time_params;
54
55     /* Initialize the orbital elements of sun, moon and mayor planets */
56     fgSolarSystemInit(*t);
57
58     /* Intialize the moon's position */
59     fgMoonInit(); 
60
61     /* Initialize the sun's position */
62     fgSunInit();       
63
64     /* Initialize the Stars subsystem  */
65     fgStarsInit();             
66 }
67
68
69 /* Render Astronomical Objects */
70 void fgAstroRender() {
71     struct FLIGHT *f;
72     struct fgLIGHT *l;
73     struct VIEW *v;
74     struct fgTIME *t;
75     double angle;
76
77     f = &current_aircraft.flight;
78     l = &cur_light_params;
79     t = &cur_time_params;
80     v = &current_view;
81
82     /* a hack: Force sun and moon position to be updated on an hourly basis */
83     if (((t->gst - prevUpdate) > 1) || (t->gst < prevUpdate)) {
84         prevUpdate = t->gst;
85         fgSunInit();
86         fgMoonInit();
87     }
88
89     /* Disable fog effects */
90     glDisable( GL_FOG );
91
92     /* reverse light direction so the moon is displayed properly */
93     glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec_inv );
94
95     glPushMatrix();
96
97     /* Translate to view position */
98     glTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z );
99
100     /* Rotate based on gst (side real time) */
101     angle = t->gst * 15.041085; /* should be 15.041085, Curt thought it was 15*/
102 #ifdef DEBUG
103     printf("Rotating astro objects by %.2f degrees\n",angle);
104 #endif
105     glRotatef( angle, 0.0, 0.0, -1.0 );
106
107     /* render the stars */
108     fgStarsRender();
109
110     /* render the moon */
111     fgMoonRender();
112
113     /* render the sun */
114     fgSunRender();
115
116     glPopMatrix();
117
118     /* reenable fog effects */
119     glEnable( GL_FOG );
120 }
121
122
123 /* $Log$
124 /* Revision 1.2  1997/12/09 04:25:33  curt
125 /* Working on adding a global lighting params structure.
126 /*
127  * Revision 1.1  1997/11/25 23:20:22  curt
128  * Initial revision.
129  *
130  */