1
0
Fork 0

Renamed & rearranged variables and routines. Added some initial simple

timer/alarm routines so the flight model can be updated on a regular interval.
This commit is contained in:
curt 1997-05-27 17:44:31 +00:00
parent c3eef96cfb
commit 1c25a7c67f
4 changed files with 158 additions and 75 deletions

View file

@ -68,12 +68,12 @@ void GLUTkey(unsigned char k, int x, int y) {
return; return;
case 122: case 122:
fogDensity *= 1.10; fogDensity *= 1.10;
glFogf(GL_FOG_DENSITY, fogDensity); glFogf(GL_FOG_END, fogDensity);
printf("Fog density = %.4f\n", fogDensity); printf("Fog density = %.4f\n", fogDensity);
return; return;
case 90: case 90:
fogDensity /= 1.10; fogDensity /= 1.10;
glFogf(GL_FOG_DENSITY, fogDensity); glFogf(GL_FOG_END, fogDensity);
printf("Fog density = %.4f\n", fogDensity); printf("Fog density = %.4f\n", fogDensity);
return; return;
case 27: /* ESC */ case 27: /* ESC */
@ -84,10 +84,14 @@ void GLUTkey(unsigned char k, int x, int y) {
/* $Log$ /* $Log$
/* Revision 1.3 1997/05/23 15:40:25 curt /* Revision 1.4 1997/05/27 17:44:31 curt
/* Added GNU copyright headers. /* Renamed & rearranged variables and routines. Added some initial simple
/* Fog now works! /* timer/alarm routines so the flight model can be updated on a regular interval.
/* /*
* Revision 1.3 1997/05/23 15:40:25 curt
* Added GNU copyright headers.
* Fog now works!
*
* Revision 1.2 1997/05/23 00:35:12 curt * Revision 1.2 1997/05/23 00:35:12 curt
* Trying to get fog to work ... * Trying to get fog to work ...
* *

View file

@ -27,7 +27,8 @@
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/time.h> #include <signal.h> /* for timer routines */
#include <sys/time.h> /* for timer routines */
#ifdef GLUT #ifdef GLUT
#include <GL/glut.h> #include <GL/glut.h>
@ -41,42 +42,50 @@
#include "../aircraft/aircraft.h" #include "../aircraft/aircraft.h"
#include "../scenery/scenery.h" #include "../scenery/scenery.h"
/* This is a record containing all the info for the aircraft currently /* This is a record containing all the info for the aircraft currently
being operated */ being operated */
struct aircraft_params current_aircraft; struct aircraft_params current_aircraft;
/* temporary hack */
extern struct mesh *mesh_ptr;
/* Function prototypes */
GLint make_mesh();
static void draw_mesh();
/* view parameters */ /* view parameters */
static GLfloat win_ratio = 1.0; static GLfloat win_ratio = 1.0;
/* temporary hack */
extern struct mesh *mesh_ptr;
/* Function prototypes */
GLint fgSceneryCompile();
static void fgSceneryDraw();
/* pointer to terrain mesh structure */ /* pointer to terrain mesh structure */
static GLint mesh; static GLint mesh;
double fogDensity = 0.001; /* Another hack */
double fogDensity = 2000.0;
/* init_view() -- Setup view parameters */ /* Another hack */
static void init_view() { #define DEFAULT_MODEL_HZ 120
double Simtime;
int Overrun;
int model_dt;
/**************************************************************************
* fgInitVisuals() -- Initialize various GL/view parameters
**************************************************************************/
static void fgInitVisuals() {
/* if the 4th field is 0.0, this specifies a direction ... */ /* if the 4th field is 0.0, this specifies a direction ... */
static GLfloat pos[4] = {-3.0, 1.0, 3.0, 0.0 }; static GLfloat sun_vec[4] = {3.0, 1.0, 3.0, 0.0 };
static GLfloat color[4] = { 0.3, 0.7, 0.2, 1.0 }; static GLfloat color[4] = { 0.3, 0.7, 0.2, 1.0 };
static GLfloat fogColor[4] = {0.5, 0.5, 0.5, 1.0}; static GLfloat fogColor[4] = {0.65, 0.65, 0.85, 1.0};
glEnable( GL_DEPTH_TEST ); glEnable( GL_DEPTH_TEST );
glFrontFace(GL_CW);
glEnable( GL_CULL_FACE ); glEnable( GL_CULL_FACE );
/* If enabled, normal vectors specified with glNormal are scaled /* If enabled, normal vectors specified with glNormal are scaled
to unit length after transformation. See glNormal. */ to unit length after transformation. See glNormal. */
glEnable( GL_NORMALIZE ); glEnable( GL_NORMALIZE );
glLightfv( GL_LIGHT0, GL_POSITION, pos ); glLightfv( GL_LIGHT0, GL_POSITION, sun_vec );
glEnable( GL_LIGHTING ); glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 ); glEnable( GL_LIGHT0 );
@ -86,7 +95,7 @@ static void init_view() {
glEnable( GL_FOG ); glEnable( GL_FOG );
glFogi (GL_FOG_MODE, GL_LINEAR); glFogi (GL_FOG_MODE, GL_LINEAR);
/* glFogf (GL_FOG_START, 1.0); */ /* glFogf (GL_FOG_START, 1.0); */
glFogf (GL_FOG_END, 2000.0); glFogf (GL_FOG_END, fogDensity);
glFogfv (GL_FOG_COLOR, fogColor); glFogfv (GL_FOG_COLOR, fogColor);
/* glFogf (GL_FOG_DENSITY, fogDensity); */ /* glFogf (GL_FOG_DENSITY, fogDensity); */
/* glHint (GL_FOG_HINT, GL_FASTEST); */ /* glHint (GL_FOG_HINT, GL_FASTEST); */
@ -95,26 +104,11 @@ static void init_view() {
} }
/* init_scene() -- build all objects */ /**************************************************************************
static void init_scene() { * Update the view volume, position, and orientation
**************************************************************************/
/* make terrain mesh */ static void fgUpdateViewParams() {
mesh = make_mesh();
}
/* create the terrain mesh */
GLint make_mesh() {
GLint mesh;
mesh = mesh2GL(mesh_ptr);
return(mesh);
}
/* update the view volume */
static void update_view() {
struct flight_params *f; struct flight_params *f;
f = &current_aircraft.flight; f = &current_aircraft.flight;
@ -132,10 +126,13 @@ static void update_view() {
} }
/* draw the scene */ /**************************************************************************
static void draw_scene( void ) { * Update all Visuals (redraws anything graphics related)
**************************************************************************/
static void fgUpdateVisuals( void ) {
/* update view volume parameters */ /* update view volume parameters */
update_view(); fgUpdateViewParams();
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
@ -144,7 +141,7 @@ static void draw_scene( void ) {
/* glLoadIdentity(); */ /* glLoadIdentity(); */
/* draw terrain mesh */ /* draw terrain mesh */
draw_mesh(); fgSceneryDraw();
#ifdef GLUT #ifdef GLUT
glutSwapBuffers(); glutSwapBuffers();
@ -154,26 +151,92 @@ static void draw_scene( void ) {
} }
/**************************************************************************
* Timer management routines
**************************************************************************/
static struct itimerval t, ot;
/* This routine catches the SIGALRM */
void fgTimerCatch() {
static double lastSimtime = -99.9;
/* printf("In fgTimerCatch()\n"); */
Overrun = (lastSimtime == Simtime);
/* if ( Overrun ) {
printf("OVERRUN!!!\n");
} */
lastSimtime = Simtime;
signal(SIGALRM, fgTimerCatch);
}
/* this routine initializes the interval timer to generate a SIGALRM after
* the specified interval (dt) */
void fgTimerInit(float dt) {
int terr;
int isec;
float usec;
isec = (int) dt;
usec = 1000000* (dt - (float) isec);
t.it_interval.tv_sec = isec;
t.it_interval.tv_usec = usec;
t.it_value.tv_sec = isec;
t.it_value.tv_usec = usec;
/* printf("fgTimerInit() called\n"); */
fgTimerCatch(); /* set up for SIGALRM signal catch */
terr = setitimer( ITIMER_REAL, &t, &ot );
if (terr) perror("Error returned from setitimer");
}
/**************************************************************************
* Scenery management routines
**************************************************************************/
static void fgSceneryInit() {
/* make terrain mesh */
mesh = fgSceneryCompile();
}
/* create the terrain mesh */
GLint fgSceneryCompile() {
GLint mesh;
mesh = mesh2GL(mesh_ptr);
return(mesh);
}
/* draw the terrain mesh */ /* draw the terrain mesh */
static void draw_mesh() { static void fgSceneryDraw() {
glCallList(mesh); glCallList(mesh);
} }
/* What should we do when we have nothing else to do? How about get /* What should we do when we have nothing else to do? How about get
* ready for the next move?*/ * ready for the next move?*/
static void idle( void ) static void fgMainLoop( void )
{ {
slew_update(); slew_update();
aircraft_debug(1); aircraft_debug(1);
draw_scene(); fgUpdateVisuals();
} }
/* new window size or exposure */ /**************************************************************************
static void reshape( int width, int height ) { * Handle new window size or exposure
/* Do this so we can call reshape(0,0) ourselves without having to know **************************************************************************/
static void fgReshape( int width, int height ) {
/* Do this so we can call fgReshape(0,0) ourselves without having to know
* what the values of width & height are. */ * what the values of width & height are. */
if ( (height > 0) && (width > 0) ) { if ( (height > 0) && (width > 0) ) {
win_ratio = (GLfloat) height / (GLfloat) width; win_ratio = (GLfloat) height / (GLfloat) width;
@ -182,7 +245,7 @@ static void reshape( int width, int height ) {
/* Inform gl of our view window size */ /* Inform gl of our view window size */
glViewport(0, 0, (GLint)width, (GLint)height); glViewport(0, 0, (GLint)width, (GLint)height);
update_view(); fgUpdateViewParams();
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
} }
@ -222,46 +285,50 @@ int main( int argc, char *argv[] ) {
#endif #endif
/* setup view parameters, only makes GL calls */ /* setup view parameters, only makes GL calls */
init_view(); fgInitVisuals();
/* build all objects */
init_scene();
/* Set initial position and slew parameters */ /* Set initial position and slew parameters */
/* slew_init(-398391.3, 120070.4, 244, 3.1415); */ /* GLOBE Airport */ /* slew_init(-398391.3, 120070.4, 244, 3.1415); */ /* GLOBE Airport */
/* slew_init(-335340,162540, 15, 4.38); */
slew_init(-398673.28,120625.64, 53, 4.38); slew_init(-398673.28,120625.64, 53, 4.38);
/* build all objects */
fgSceneryInit();
/* initialize timer */
fgTimerInit( 1.0 / DEFAULT_MODEL_HZ );
#ifdef GLUT #ifdef GLUT
/* call reshape() on window resizes */ /* call fgReshape() on window resizes */
glutReshapeFunc( reshape ); glutReshapeFunc( fgReshape );
/* call key() on keyboard event */ /* call key() on keyboard event */
glutKeyboardFunc( GLUTkey ); glutKeyboardFunc( GLUTkey );
glutSpecialFunc( GLUTkey ); glutSpecialFunc( GLUTkey );
/* call idle() whenever there is nothing else to do */ /* call fgMainLoop() whenever there is nothing else to do */
glutIdleFunc( idle ); glutIdleFunc( fgMainLoop );
/* draw the scene */ /* draw the scene */
glutDisplayFunc( draw_scene ); glutDisplayFunc( fgUpdateVisuals );
/* pass control off to the GLUT event handler */ /* pass control off to the GLUT event handler */
glutMainLoop(); glutMainLoop();
#elif MESA_TK #elif MESA_TK
/* call reshape() on expose events */ /* call fgReshape() on expose events */
tkExposeFunc( reshape ); tkExposeFunc( fgReshape );
/* call reshape() on window resizes */ /* call fgReshape() on window resizes */
tkReshapeFunc( reshape ); tkReshapeFunc( fgReshape );
/* call key() on keyboard event */ /* call key() on keyboard event */
tkKeyDownFunc( GLTKkey ); tkKeyDownFunc( GLTKkey );
/* call idle() whenever there is nothing else to do */ /* call fgMainLoop() whenever there is nothing else to do */
tkIdleFunc( idle ); tkIdleFunc( fgMainLoop );
/* draw the scene */ /* draw the scene */
tkDisplayFunc( draw_scene ); tkDisplayFunc( fgUpdateVisuals );
/* pass control off to the tk event handler */ /* pass control off to the tk event handler */
tkExec(); tkExec();
@ -272,10 +339,14 @@ int main( int argc, char *argv[] ) {
/* $Log$ /* $Log$
/* Revision 1.3 1997/05/23 15:40:25 curt /* Revision 1.4 1997/05/27 17:44:31 curt
/* Added GNU copyright headers. /* Renamed & rearranged variables and routines. Added some initial simple
/* Fog now works! /* timer/alarm routines so the flight model can be updated on a regular interval.
/* /*
* Revision 1.3 1997/05/23 15:40:25 curt
* Added GNU copyright headers.
* Fog now works!
*
* Revision 1.2 1997/05/23 00:35:12 curt * Revision 1.2 1997/05/23 00:35:12 curt
* Trying to get fog to work ... * Trying to get fog to work ...
* *

View file

@ -56,7 +56,7 @@ INTERFACE_FILES = GLUTkey.c
# GRAPHICS_LIBS = -lGLU -lGL -lXmu -lX11 # GRAPHICS_LIBS = -lGLU -lGL -lXmu -lX11
# For Mesa # For Mesa
MESA_LIBS = -L/usr/lib/mesa -lMesaaux -lMesatk -lMesaGLU -lMesaGL MESA_LIBS = -L/usr/lib/mesa -lMesatk -lMesaaux -lMesaGLU -lMesaGL
X11_LIBS = -L/usr/X11R6/lib -lXext -lXmu -lXi -lX11 X11_LIBS = -L/usr/X11R6/lib -lXext -lXmu -lXi -lX11
GRAPHICS_LIBS = $(MESA_LIBS) $(X11_LIBS) GRAPHICS_LIBS = $(MESA_LIBS) $(X11_LIBS)
@ -102,6 +102,10 @@ mesh2GL.o: mesh2GL.c ../scenery/mesh.h
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# $Log$ # $Log$
# Revision 1.5 1997/05/27 17:44:32 curt
# Renamed & rearranged variables and routines. Added some initial simple
# timer/alarm routines so the flight model can be updated on a regular interval.
#
# Revision 1.4 1997/05/23 15:40:26 curt # Revision 1.4 1997/05/23 15:40:26 curt
# Added GNU copyright headers. # Added GNU copyright headers.
# Fog now works! # Fog now works!

View file

@ -59,7 +59,7 @@ GLint mesh2GL(struct mesh *m) {
int i, j, istep, jstep, iend, jend; int i, j, istep, jstep, iend, jend;
float temp; float temp;
istep = jstep = 1; /* Detail level 1 -- 1200 ... */ istep = jstep = 5; /* Detail level 1 - 1200 ... */
mesh = glGenLists(1); mesh = glGenLists(1);
glNewList(mesh, GL_COMPILE); glNewList(mesh, GL_COMPILE);
@ -119,9 +119,13 @@ GLint mesh2GL(struct mesh *m) {
/* $Log$ /* $Log$
/* Revision 1.5 1997/05/24 01:45:32 curt /* Revision 1.6 1997/05/27 17:44:32 curt
/* Fixed surface normals for triangle mesh. /* Renamed & rearranged variables and routines. Added some initial simple
/* timer/alarm routines so the flight model can be updated on a regular interval.
/* /*
* Revision 1.5 1997/05/24 01:45:32 curt
* Fixed surface normals for triangle mesh.
*
* Revision 1.4 1997/05/23 20:05:24 curt * Revision 1.4 1997/05/23 20:05:24 curt
* First stab at using GL_TRIANGLE_STRIP's instead of GL_POLYGONS (to conserve * First stab at using GL_TRIANGLE_STRIP's instead of GL_POLYGONS (to conserve
* memory) * memory)