1 /*
2     OpenUniverse 1.0
3     Copyright (C) 2000  Raul Alonso <amil@las.es>
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <math.h>
24 
25 #ifdef WIN32
26 #include <windows.h>
27 #include <mmsystem.h>
28 #endif
29 
30 #include <GL/glut.h>
31 #ifndef PLANET
32 #include "cfgparse.tab.h"
33 #endif
34 #include "texfont.h"
35 #include "macros.h"
36 
37 
38 
39 #define NUMSTARS 3141			/* 3141 for full star catalog, decrease number for better
40 								   performance, first N brighter stars are used */
41 
42 #define FLAREINTENSITY 0.5
43 #define MAXBODIES 50
44 #define MAXMESSIER 50
45 #define MAXVERTEX 3000
46 #define MAXEVENTS 1000
47 #define AU 149597.870
48 #define UNIVERSERADIUS 10000000.0	/* Somewhere beyond Pluto */
49 #define LIGHTSPEED 299792.458	/* Km / sec */
50 #define SECS_A_DAY (24.0*60.0*60.0)	/* seconds */
51 enum { X, Y, Z };
52 enum { TEXFONT, BMAPFONT };
53 enum { LOW, MEDIUM, HIGH };
54 
55 #ifndef M_PI
56 #define M_PI 3.14159265358979323846
57 #endif
58 
59 #define DATEOFELEMENTS 2450680.5	/* In Julian days */
60 
61 
62 #ifndef WIN32
63 #define error(s) fprintf(stderr,s)
64 #define scmp strcasecmp
65 #define delay(x) usleep(x*1000)
66 #else
67 #define error(s) MessageBox(NULL,s,"ERROR", MB_OK);
68 #define scmp _stricmp
69 #define delay(x) Sleep(x)
70 #endif
71 
72 extern GLfloat LightPos[4];
73 extern GLfloat ambient[4];
74 extern GLfloat White[4];
75 extern GLfloat Black[4];
76 extern GLfloat Fog[4];
77 extern GLuint logotex;
78 extern float fogdensity;
79 extern int texture, lighting, drawstars, gravity;
80 extern int messier, milkyway, messier_texsize, milkyway_texsize;
81 extern GLenum smodel;
82 extern GLuint StarsDL, MessierDL, MilkyWayDL, EclipticDL;
83 extern int ImgWidth, ImgHeight, width, height, red, polaris;
84 extern double days;
85 extern char texturepath[100], fontpath[100], confpath[100];
86 extern int slices, stacks, NUMBODIES, num_messier, timefactor;
87 extern double campos[3], cameye[3], camup[3], camvel[3];
88 extern int camrot[3];
89 extern float fov, fps, sec, star_mag, speed, d, zoom, aratio, radarzoom;
90 extern float nearclip, farclip;
91 extern int frames, paused, cmode, currsource, currtarget, nearest,
92 	objstorender;
93 extern int demomode, bench, help, help2, plabels, slabels, init,
94 	splashbitmap, LOD;
95 extern int demostep, color_depth, tex_comp;
96 extern GLenum cd_rgb, cd_lum, cd_rgba, cd_luma;
97 extern int fullscreen, info, logo, realtime, trail, jpeg_quality,
98 	atmospheres;
99 extern char sbuf[100], game_string[20];
100 extern int joyavailable, joyactive;
101 extern int follow, smooth_transitions, dosmooth, transition, radar;
102 extern int main_window;
103 extern TexFont *txf;
104 extern int fonttype, glyphheight, glyphwidth;
105 extern FILE *logfile;
106 extern int hasPointEXT, numevents, currevent, eventrecord;
107 extern double eventrecordstart;
108 extern double eventstartcampos[3], eventstartcameye[3], eventstartcamup[3];
109 
110 typedef struct {
111 	double origin[3];
112 	double dir[3];
113 	float color[4];
114 	double dist;
115 } particle;
116 
117 typedef struct {
118 	char Name[20];
119 	double pos[3];
120 	float ascension, declination, magnitude, color[3];
121 	char type;
122 } stardata;
123 
124 typedef struct {
125 	char Name[20];
126 	double pos[3];
127 	float ascension, declination, magnitude, size;
128 	GLuint textures[1];
129 } messierdata;
130 
131 
132 typedef struct {
133 	float u, v;
134 	float r, g, b, a;
135 	float nx, ny, nz;
136 	float x, y, z;
137 } vertex_data;
138 
139 
140 typedef struct {
141 	char Name[20];
142 	int Type, TrailEnabled;
143 	int Sat, CustomFunction;
144 	GLubyte *Image;
145 	GLuint LowDetail, MidDetail, HighDetail, Trail, *textures;
146 	int texnum, texwidth, texheight, texsize;
147 	float DeltaRotation, InnerRadius, Radius, xflat, yflat, zflat,
148 		Rotation, Degrees, OrbitalPeriod;
149 	float Inclination, AscendingNode, Perihelion, MeanDistance,
150 		DailyMotion;
151 	float Eccentricity, MeanLongitude, Color[4];
152 	double pos[3], prevel[3], vel[3], grav[3], dir[3], up[3];
153 	double Mass;
154 	float tail_lenght;
155 	int num_particles, initialized, rot[3];
156 	particle *tail;
157 	vertex_data *vertex_list;
158 	GLuint *indices;
159 } planetdata;
160 
161 
162 typedef struct {
163 	int body;
164 	double dist;
165 	GLuint dlist;
166 } rlist;
167 
168 typedef struct {
169 	unsigned char key;
170 	int special, when;
171 } event;
172 
173 extern rlist renderlist[MAXBODIES];
174 extern planetdata planets[MAXBODIES];
175 extern stardata stars[NUMSTARS];
176 extern messierdata messierobjs[MAXMESSIER];
177 extern event events[MAXEVENTS];
178 
179 				/* cmdline.cpp */
180 void ParseCmdLine(int, char **);
181 
182 				/* ou.cpp */
183 void Idle(void);
184 void Reshape(int, int);
185 				/* init.cpp */
186 void Init(void);
187 				/* stars.cpp */
188 void InitStars(float, int);
189 				/* milkyway.cpp */
190 void InitMilkyWay();
191 				/* messier.cpp */
192 void InitMessier();
193 				/* positions.cpp */
194 void UpdatePositions(double, int);
195 				/* joystick.cpp */
196 void joystick(int *, double *, double *);
197 void joydetect(void);
198 				/* cfgparse */
199 void ReadConfigFile(void);
200 				/* vsop87.cpp */
201 void EarthPos(double, double *, double *, double *);
202 void JupiterPos(double, double *, double *, double *);
203 void MarsPos(double, double *, double *, double *);
204 void MercuryPos(double, double *, double *, double *);
205 void NeptunePos(double, double *, double *, double *);
206 void SaturnPos(double, double *, double *, double *);
207 void UranusPos(double, double *, double *, double *);
208 void VenusPos(double, double *, double *, double *);
209 void PlutoPos(double, double *, double *, double *);
210 void MoonPos(double, double *, double *, double *);
211 				/* keyboard.cpp */
212 void Key(unsigned char, int, int);
213 void Special(int, int, int);
214 				/* mouse.cpp */
215 void Mouse(int, int, int, int);
216 void Motion(int, int);
217 				/* sshot.cpp */
218 void ScreenShot(char *);
219 				/* sun.cpp */
220 void SunBillBoard(double);
221 				/* timer.cpp */
222 void TimerFunc(int);
223 				/* font.cpp */
224 void initfontengine(void);
225 void texprintstring(float, float, float, char *);
226 void glutprintstring(float, float, float, char *string);
227 void printstring(float, float, float, char *string);
228 				/* util.cpp */
229 float gettime(void);
230 void Rotation(double, double[3], double[3]);
231 void MakeQuat(double *, double, double, double, double);
232 void Quat2Matrix(double *, float[16]);
233 void Mat2Quat(float[4][4], double *);
234 void Euler2Quat(double, double, double, double *);
235 void MyLookAt(double[3], double[3]);
236 void RotMat(double[3], double[3], float[16]);
237 int SmoothTrans(double[3], double[3], double[3],
238 				double[3], double[3], double[3], double);
239 GLubyte *texture_LOD(GLubyte *, int *, int *, int);
240 void log(char *);
241 void shutdown(int);
242 				/* jpeg.cpp */
243 GLubyte *read_JPEG_file(char *, int *, int *, int *);
244 				/* dds.cpp */
245 GLubyte *read_DDS_file(char *, int *, int *, int *);
246 				/* stars.cpp */
247 void InitStars(float, int);
248 extern float star_size;
249 				/* comet.cpp */
250 void InitPointEXT(void);
251 void CometTail(int);
252 				/* rings.cpp */
253 void DrawRing(int);
254 				/* gravity.cpp */
255 void Gravity(double *, double *);
256 void FeelTheGravity(void);
257 				/* radar.cpp */
258 void Radar(void);
259 								/* camera.cpp */
260 void UpdateCamera(double[3], double[3], double[3]);
261 				/* info.cpp */
262 void OnScreenInfo(void);
263 				/* events.cpp */
264 void AutoEvents(void);
265 void DumpEvents(void);
266 void NewEvents(void);
267 								/* mp3.cpp */
268 void MP3_InitPlayer(void);
269 void MP3_FlushMessages(void);
270 				/* flares.cpp */
271 void InitFlares(void);
272 void LensFlares(void);
273