]> git.mxchange.org Git - simgear.git/blob - Scenery/astro.c
Add xgl wrappers for debugging.
[simgear.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 #include "../XGL/xgl.h"
33
34 #include "astro.h"
35 #include "moon.h"
36 #include "orbits.h"
37 #include "planets.h"
38 #include "stars.h"
39 #include "sun.h"
40
41 #include "../Include/constants.h"
42 #include "../Include/general.h"
43
44 #include "../Main/views.h"
45 #include "../Aircraft/aircraft.h"
46 #include "../Time/fg_time.h"
47
48 static double prevUpdate = 0;
49
50
51 /* Initialize Astronomical Objects */
52 void fgAstroInit() {
53     struct fgTIME *t;
54     t = &cur_time_params;
55
56     /* Initialize the orbital elements of sun, moon and mayor planets */
57     fgSolarSystemInit(*t);
58
59     /* Initialize the Stars subsystem  */
60     fgStarsInit();             
61
62     /* Initialize the sun's position */
63     fgSunInit();       
64
65     /* Intialize the moon's position */
66     fgMoonInit(); 
67 }
68
69
70 /* Render Astronomical Objects */
71 void fgAstroRender() {
72     struct fgFLIGHT *f;
73     struct fgLIGHT *l;
74     struct fgVIEW *v;
75     struct fgTIME *t;
76     double angle;
77
78     f = &current_aircraft.flight;
79     l = &cur_light_params;
80     t = &cur_time_params;
81     v = &current_view;
82
83     /* a hack: Force sun and moon position to be updated on an hourly basis */
84     if (((t->gst - prevUpdate) > 1) || (t->gst < prevUpdate)) {
85         prevUpdate = t->gst;
86         fgSunInit();
87         fgMoonInit();
88     }
89
90     /* Disable fog effects */
91     xglDisable( GL_FOG );
92
93     /* set the sun position */
94     xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec_inv );
95
96     xglPushMatrix();
97
98     /* Translate to view position */
99     xglTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z );
100
101     /* Rotate based on gst (side real time) */
102     angle = t->gst * 15.041085; /* should be 15.041085, Curt thought it was 15*/
103 #ifdef DEBUG
104     printf("Rotating astro objects by %.2f degrees\n",angle);
105 #endif
106     xglRotatef( angle, 0.0, 0.0, -1.0 );
107
108     /* render the moon */
109     fgMoonRender();
110
111     /* render the stars */
112     fgStarsRender();
113
114     /* render the sun */
115     fgSunRender();
116
117     xglPopMatrix();
118
119     /* reenable fog effects */
120     xglEnable( GL_FOG );
121 }
122
123
124 /* $Log$
125 /* Revision 1.8  1997/12/15 23:54:57  curt
126 /* Add xgl wrappers for debugging.
127 /* Generate terrain normals on the fly.
128 /*
129  * Revision 1.7  1997/12/15 20:59:09  curt
130  * Misc. tweaks.
131  *
132  * Revision 1.6  1997/12/12 21:41:27  curt
133  * More light/material property tweaking ... still a ways off.
134  *
135  * Revision 1.5  1997/12/12 19:52:54  curt
136  * Working on lightling and material properties.
137  *
138  * Revision 1.4  1997/12/11 04:43:56  curt
139  * Fixed sun vector and lighting problems.  I thing the moon is now lit
140  * correctly.
141  *
142  * Revision 1.3  1997/12/10 22:37:49  curt
143  * Prepended "fg" on the name of all global structures that didn't have it yet.
144  * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
145  *
146  * Revision 1.2  1997/12/09 04:25:33  curt
147  * Working on adding a global lighting params structure.
148  *
149  * Revision 1.1  1997/11/25 23:20:22  curt
150  * Initial revision.
151  *
152  */