Working on adding a global lighting params structure.
This commit is contained in:
parent
92aa2446e6
commit
4ab16fd58e
8 changed files with 123 additions and 87 deletions
|
@ -100,9 +100,11 @@ int show_hud;
|
|||
**************************************************************************/
|
||||
|
||||
static void fgInitVisuals() {
|
||||
struct fgLIGHT *l;
|
||||
struct fgTIME *t;
|
||||
struct WEATHER *w;
|
||||
|
||||
l = &cur_light_params;
|
||||
t = &cur_time_params;
|
||||
w = ¤t_weather;
|
||||
|
||||
|
@ -114,7 +116,7 @@ static void fgInitVisuals() {
|
|||
to unit length after transformation. See glNormal. */
|
||||
glEnable( GL_NORMALIZE );
|
||||
|
||||
glLightfv( GL_LIGHT0, GL_POSITION, t->sun_vec );
|
||||
glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
|
||||
glEnable( GL_LIGHTING );
|
||||
glEnable( GL_LIGHT0 );
|
||||
|
||||
|
@ -139,6 +141,7 @@ static void fgInitVisuals() {
|
|||
|
||||
static void fgUpdateViewParams() {
|
||||
struct FLIGHT *f;
|
||||
struct fgLIGHT *l;
|
||||
struct fgTIME *t;
|
||||
struct VIEW *v;
|
||||
double x_2, x_4, x_8, x_10;
|
||||
|
@ -147,6 +150,7 @@ static void fgUpdateViewParams() {
|
|||
GLfloat amb[3], diff[3], fog[4], clear[4];
|
||||
|
||||
f = ¤t_aircraft.flight;
|
||||
l = &cur_light_params;
|
||||
t = &cur_time_params;
|
||||
v = ¤t_view;
|
||||
|
||||
|
@ -168,14 +172,14 @@ static void fgUpdateViewParams() {
|
|||
v->view_up[0], v->view_up[1], v->view_up[2]);
|
||||
|
||||
/* set the sun position */
|
||||
glLightfv( GL_LIGHT0, GL_POSITION, t->sun_vec );
|
||||
glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
|
||||
|
||||
/* calculate lighting parameters based on sun's relative angle to
|
||||
* local up */
|
||||
/* ya kind'a have to plot this to see the magic */
|
||||
|
||||
/* x = t->sun_angle^8 */
|
||||
x_2 = t->sun_angle * t->sun_angle;
|
||||
x_2 = l->sun_angle * l->sun_angle;
|
||||
x_4 = x_2 * x_2;
|
||||
x_8 = x_4 * x_4;
|
||||
x_10 = x_8 * x_2;
|
||||
|
@ -577,9 +581,12 @@ int main( int argc, char *argv[] ) {
|
|||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.25 1997/12/08 22:54:09 curt
|
||||
/* Enabled GL_CULL_FACE.
|
||||
/* Revision 1.26 1997/12/09 04:25:29 curt
|
||||
/* Working on adding a global lighting params structure.
|
||||
/*
|
||||
* Revision 1.25 1997/12/08 22:54:09 curt
|
||||
* Enabled GL_CULL_FACE.
|
||||
*
|
||||
* Revision 1.24 1997/11/25 19:25:32 curt
|
||||
* Changes to integrate Durk's moon/sun code updates + clean up.
|
||||
*
|
||||
|
|
|
@ -69,11 +69,13 @@ void fgAstroInit() {
|
|||
/* Render Astronomical Objects */
|
||||
void fgAstroRender() {
|
||||
struct FLIGHT *f;
|
||||
struct fgLIGHT *l;
|
||||
struct VIEW *v;
|
||||
struct fgTIME *t;
|
||||
double angle;
|
||||
|
||||
f = ¤t_aircraft.flight;
|
||||
l = &cur_light_params;
|
||||
t = &cur_time_params;
|
||||
v = ¤t_view;
|
||||
|
||||
|
@ -88,7 +90,7 @@ void fgAstroRender() {
|
|||
glDisable( GL_FOG );
|
||||
|
||||
/* reverse light direction so the moon is displayed properly */
|
||||
glLightfv( GL_LIGHT0, GL_POSITION, t->sun_vec_inv );
|
||||
glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec_inv );
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
|
@ -119,7 +121,10 @@ void fgAstroRender() {
|
|||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.1 1997/11/25 23:20:22 curt
|
||||
/* Initial revision.
|
||||
/* Revision 1.2 1997/12/09 04:25:33 curt
|
||||
/* Working on adding a global lighting params structure.
|
||||
/*
|
||||
* Revision 1.1 1997/11/25 23:20:22 curt
|
||||
* Initial revision.
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -218,10 +218,12 @@ void fgStarsInit() {
|
|||
void fgStarsRender() {
|
||||
struct FLIGHT *f;
|
||||
struct VIEW *v;
|
||||
struct fgLIGHT *l;
|
||||
struct fgTIME *t;
|
||||
int i;
|
||||
|
||||
f = ¤t_aircraft.flight;
|
||||
l = &cur_light_params;
|
||||
t = &cur_time_params;
|
||||
v = ¤t_view;
|
||||
|
||||
|
@ -230,13 +232,13 @@ void fgStarsRender() {
|
|||
/* t->sun_angle = 3.0; */ /* to force stars to be drawn (for testing) */
|
||||
|
||||
/* render the stars */
|
||||
if ( t->sun_angle > (FG_PI_2 + 5 * DEG_TO_RAD ) ) {
|
||||
if ( l->sun_angle > (FG_PI_2 + 5 * DEG_TO_RAD ) ) {
|
||||
/* determine which star structure to draw */
|
||||
if ( t->sun_angle > (FG_PI_2 + 7.25 * DEG_TO_RAD ) ) {
|
||||
if ( l->sun_angle > (FG_PI_2 + 7.25 * DEG_TO_RAD ) ) {
|
||||
i = 0;
|
||||
} else if ( t->sun_angle > (FG_PI_2 + 6.50 * DEG_TO_RAD ) ) {
|
||||
} else if ( l->sun_angle > (FG_PI_2 + 6.50 * DEG_TO_RAD ) ) {
|
||||
i = 1;
|
||||
} else if ( t->sun_angle > (FG_PI_2 + 5.75 * DEG_TO_RAD ) ) {
|
||||
} else if ( l->sun_angle > (FG_PI_2 + 5.75 * DEG_TO_RAD ) ) {
|
||||
i = 2;
|
||||
} else {
|
||||
i = 3;
|
||||
|
@ -254,9 +256,12 @@ void fgStarsRender() {
|
|||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.16 1997/11/25 19:25:38 curt
|
||||
/* Changes to integrate Durk's moon/sun code updates + clean up.
|
||||
/* Revision 1.17 1997/12/09 04:25:33 curt
|
||||
/* Working on adding a global lighting params structure.
|
||||
/*
|
||||
* Revision 1.16 1997/11/25 19:25:38 curt
|
||||
* Changes to integrate Durk's moon/sun code updates + clean up.
|
||||
*
|
||||
* Revision 1.15 1997/10/30 12:38:45 curt
|
||||
* Working on new scenery subsystem.
|
||||
*
|
||||
|
|
|
@ -1,58 +1,49 @@
|
|||
majordomo writes:
|
||||
Subdirectories
|
||||
==============
|
||||
Main/
|
||||
-------
|
||||
"main()" and GLUT dependent mouse/keyboard/graphics code.
|
||||
Welcome to the Flight Gear project.
|
||||
|
||||
|
||||
Aircraft/
|
||||
---------
|
||||
Structure and code to tie together all the pieces of an aircraft such
|
||||
as flight model, engine model, panel, controls, etc.
|
||||
Starting the executable
|
||||
=======================
|
||||
|
||||
Unix: runfg
|
||||
Windows: runfg.bat
|
||||
|
||||
"runfg" is a script which sets the FG_ROOT environment variable, then
|
||||
runs the flight gear executable.
|
||||
|
||||
|
||||
Controls/
|
||||
---------
|
||||
Provide a standardized interface to all aircraft controls.
|
||||
Keyboard controls
|
||||
=================
|
||||
|
||||
Flying is mainly done via the numeric keypad. There is some
|
||||
unresolved wierdness with the GLUT libraries and keyboard input, so
|
||||
for now, the state of the "Num Lock" key is important.
|
||||
|
||||
Num Lock Active
|
||||
---------------
|
||||
|
||||
Pg Up/Pg Dn Throttle
|
||||
Left Arrow/Right Arrow Aileron
|
||||
Up Arrow/Down Arrow Elevator
|
||||
Ins/Del Rudder
|
||||
"5" Center aileron/elevator/rudder
|
||||
Home/End Elevator Trim
|
||||
|
||||
Num Lock Inactive
|
||||
-----------------
|
||||
Shift + <Numeric Keypad Key> Change view
|
||||
|
||||
where key is one of:
|
||||
|
||||
8 = forward
|
||||
7 = left/forward
|
||||
4 = left
|
||||
1 = left/back
|
||||
2 = back
|
||||
3 = right/back
|
||||
6 = right
|
||||
9 = right/forward
|
||||
|
||||
|
||||
Flight/
|
||||
-------
|
||||
Strucures and code to implement various flight models. Provides a
|
||||
standardized interface to all interesting flight model variabls.
|
||||
|
||||
|
||||
|
||||
Math/
|
||||
-----
|
||||
Contains miscellaneous matrix/vector routines.
|
||||
|
||||
|
||||
Scenery/
|
||||
--------
|
||||
Scenery parsing/generating code.
|
||||
|
||||
|
||||
Sound/
|
||||
------
|
||||
Sound management code
|
||||
|
||||
|
||||
Timer/
|
||||
------
|
||||
Code to handle time and timing of events.
|
||||
|
||||
|
||||
Utils/
|
||||
------
|
||||
Miscellaneous utility routines such as a general random number generator
|
||||
|
||||
|
||||
Weather/
|
||||
--------
|
||||
Weather management and modeling code.
|
||||
|
||||
|
||||
Win32/
|
||||
------
|
||||
Win32 support stuff
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
#---------------------------------------------------------------------------
|
||||
|
||||
VERSION_MAJOR = 0
|
||||
VERSION_MINOR = 14
|
||||
VERSION_MINOR = 15
|
||||
VERSION = $(VERSION_MAJOR).$(VERSION_MINOR)
|
||||
|
||||
|
||||
|
@ -131,6 +131,9 @@ FG_CFLAGS = $(GLOBAL_CFLAGS)
|
|||
|
||||
#---------------------------------------------------------------------------
|
||||
# $Log$
|
||||
# Revision 1.20 1997/12/09 04:25:25 curt
|
||||
# Working on adding a global lighting params structure.
|
||||
#
|
||||
# Revision 1.19 1997/11/25 19:25:27 curt
|
||||
# Changes to integrate Durk's moon/sun code updates + clean up.
|
||||
#
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
|
||||
|
||||
struct fgTIME cur_time_params;
|
||||
struct fgLIGHT cur_light_params;
|
||||
|
||||
|
||||
/* Initialize the time dependent variables */
|
||||
|
@ -284,9 +285,12 @@ void fgTimeUpdate(struct FLIGHT *f, struct fgTIME *t) {
|
|||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.11 1997/11/25 19:25:40 curt
|
||||
/* Changes to integrate Durk's moon/sun code updates + clean up.
|
||||
/* Revision 1.12 1997/12/09 04:25:37 curt
|
||||
/* Working on adding a global lighting params structure.
|
||||
/*
|
||||
* Revision 1.11 1997/11/25 19:25:40 curt
|
||||
* Changes to integrate Durk's moon/sun code updates + clean up.
|
||||
*
|
||||
* Revision 1.10 1997/11/15 18:16:42 curt
|
||||
* minor tweaks.
|
||||
*
|
||||
|
|
|
@ -55,7 +55,14 @@ struct fgTIME {
|
|||
sidereal time algorithm result and the
|
||||
course result. course + diff has good
|
||||
accuracy for the short term */
|
||||
};
|
||||
|
||||
extern struct fgTIME cur_time_params;
|
||||
|
||||
|
||||
/* Lighting is time dependent so it shows up here */
|
||||
/* Define a structure containing the global lighting parameters */
|
||||
struct fgLIGHT {
|
||||
/* position of the sun in various forms */
|
||||
double sun_lon, sun_gc_lat; /* in geocentric coordinates */
|
||||
struct fgCartesianPoint fg_sunpos; /* in cartesian coordiantes */
|
||||
|
@ -63,9 +70,15 @@ struct fgTIME {
|
|||
GLfloat sun_vec_inv[4]; /* inverse (in view coordinates) */
|
||||
double sun_angle; /* the angle between the sun and the
|
||||
local horizontal */
|
||||
|
||||
/* Derived lighting values */
|
||||
GLfloat scene_ambient[3]; /* ambient component */
|
||||
GLfloat scene_diffuse[3]; /* diffuse component */
|
||||
GLfloat scene_fog[4]; /* fog color */
|
||||
GLfloat scene_clear[4]; /* clear screen color */
|
||||
};
|
||||
|
||||
extern struct fgTIME cur_time_params;
|
||||
extern struct fgLIGHT cur_light_params;
|
||||
|
||||
|
||||
/* Initialize the time dependent variables */
|
||||
|
@ -79,9 +92,12 @@ void fgTimeUpdate(struct FLIGHT *f, struct fgTIME *t);
|
|||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.7 1997/11/25 19:25:41 curt
|
||||
/* Changes to integrate Durk's moon/sun code updates + clean up.
|
||||
/* Revision 1.8 1997/12/09 04:25:38 curt
|
||||
/* Working on adding a global lighting params structure.
|
||||
/*
|
||||
* Revision 1.7 1997/11/25 19:25:41 curt
|
||||
* Changes to integrate Durk's moon/sun code updates + clean up.
|
||||
*
|
||||
* Revision 1.6 1997/09/20 03:34:35 curt
|
||||
* Still trying to get those durned stars aligned properly.
|
||||
*
|
||||
|
|
|
@ -261,54 +261,59 @@ void fgSunPosition(time_t ssue, double *lon, double *lat) {
|
|||
|
||||
/* update the cur_time_params structure with the current sun position */
|
||||
void fgUpdateSunPos(struct fgCartesianPoint scenery_center) {
|
||||
struct fgLIGHT *l;
|
||||
struct fgTIME *t;
|
||||
struct VIEW *v;
|
||||
MAT3vec nup, nsun;
|
||||
double sun_gd_lat, sl_radius, temp;
|
||||
static int time_warp = 0;
|
||||
|
||||
l = &cur_light_params;
|
||||
t = &cur_time_params;
|
||||
v = ¤t_view;
|
||||
|
||||
time_warp += 0; /* increase this to make the world spin real fast */
|
||||
|
||||
fgSunPosition(t->cur_time + time_warp, &t->sun_lon, &sun_gd_lat);
|
||||
fgSunPosition(t->cur_time + time_warp, &l->sun_lon, &sun_gd_lat);
|
||||
|
||||
fgGeodToGeoc(sun_gd_lat, 0.0, &sl_radius, &t->sun_gc_lat);
|
||||
fgGeodToGeoc(sun_gd_lat, 0.0, &sl_radius, &l->sun_gc_lat);
|
||||
|
||||
t->fg_sunpos = fgPolarToCart(t->sun_lon, t->sun_gc_lat, sl_radius);
|
||||
l->fg_sunpos = fgPolarToCart(l->sun_lon, l->sun_gc_lat, sl_radius);
|
||||
|
||||
/* printf("Geodetic lat = %.5f Geocentric lat = %.5f\n", sun_gd_lat,
|
||||
t->sun_gc_lat); */
|
||||
|
||||
/* the sun position has to be translated just like everything else */
|
||||
t->sun_vec_inv[0] = t->fg_sunpos.x - scenery_center.x;
|
||||
t->sun_vec_inv[1] = t->fg_sunpos.y - scenery_center.y;
|
||||
t->sun_vec_inv[2] = t->fg_sunpos.z - scenery_center.z;
|
||||
MAT3_SCALE_VEC(t->sun_vec, t->sun_vec_inv, -1.0);
|
||||
l->sun_vec_inv[0] = l->fg_sunpos.x - scenery_center.x;
|
||||
l->sun_vec_inv[1] = l->fg_sunpos.y - scenery_center.y;
|
||||
l->sun_vec_inv[2] = l->fg_sunpos.z - scenery_center.z;
|
||||
MAT3_SCALE_VEC(l->sun_vec, l->sun_vec_inv, -1.0);
|
||||
|
||||
/* make these are directional light sources only */
|
||||
t->sun_vec[3] = 0.0;
|
||||
t->sun_vec_inv[3] = 0.0;
|
||||
l->sun_vec[3] = 0.0;
|
||||
l->sun_vec_inv[3] = 0.0;
|
||||
|
||||
/* calculate thesun's relative angle to local up */
|
||||
MAT3_COPY_VEC(nup, v->local_up);
|
||||
nsun[0] = t->fg_sunpos.x;
|
||||
nsun[1] = t->fg_sunpos.y;
|
||||
nsun[2] = t->fg_sunpos.z;
|
||||
nsun[0] = l->fg_sunpos.x;
|
||||
nsun[1] = l->fg_sunpos.y;
|
||||
nsun[2] = l->fg_sunpos.z;
|
||||
MAT3_NORMALIZE_VEC(nup, temp);
|
||||
MAT3_NORMALIZE_VEC(nsun, temp);
|
||||
|
||||
t->sun_angle = acos(MAT3_DOT_PRODUCT(nup, nsun));
|
||||
l->sun_angle = acos(MAT3_DOT_PRODUCT(nup, nsun));
|
||||
printf("SUN ANGLE relative to current location = %.3f rads.\n",
|
||||
t->sun_angle);
|
||||
l->sun_angle);
|
||||
}
|
||||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.13 1997/11/25 19:25:42 curt
|
||||
/* Changes to integrate Durk's moon/sun code updates + clean up.
|
||||
/* Revision 1.14 1997/12/09 04:25:39 curt
|
||||
/* Working on adding a global lighting params structure.
|
||||
/*
|
||||
* Revision 1.13 1997/11/25 19:25:42 curt
|
||||
* Changes to integrate Durk's moon/sun code updates + clean up.
|
||||
*
|
||||
* Revision 1.12 1997/11/15 18:15:39 curt
|
||||
* Reverse direction of sun vector, so object normals can be more normal.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue