1
0
Fork 0

Converted fgLIGHT to a C++ class.

This commit is contained in:
curt 1998-05-20 20:54:16 +00:00
parent 70fae724a7
commit cbdc65f55a
2 changed files with 73 additions and 43 deletions

View file

@ -51,13 +51,14 @@
fgLIGHT cur_light_params; fgLIGHT cur_light_params;
static fgINTERPTABLE *ambient_tbl;
static fgINTERPTABLE *diffuse_tbl; // Constructor
static fgINTERPTABLE *sky_tbl; fgLIGHT::fgLIGHT( void ) {
}
// initialize lighting tables // initialize lighting tables
void fgLightInit( void ) { void fgLIGHT::Init( void ) {
fgOPTIONS *o; fgOPTIONS *o;
char path[256]; char path[256];
@ -93,28 +94,26 @@ void fgLightInit( void ) {
// update lighting parameters based on current sun position // update lighting parameters based on current sun position
void fgLightUpdate( void ) { void fgLIGHT::Update( void ) {
fgLIGHT *l;
fgTIME *t; fgTIME *t;
fgVIEW *v; fgVIEW *v;
/* if the 4th field is 0.0, this specifies a direction ... */ // if the 4th field is 0.0, this specifies a direction ...
GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
/* base sky color */ // base sky color
GLfloat base_sky_color[4] = {0.60, 0.60, 0.90, 1.0}; GLfloat base_sky_color[4] = {0.60, 0.60, 0.90, 1.0};
/* base fog color */ // base fog color
GLfloat base_fog_color[4] = {0.90, 0.90, 1.00, 1.0}; GLfloat base_fog_color[4] = {0.90, 0.90, 1.00, 1.0};
double deg, ambient, diffuse, sky_brightness; double deg, ambient, diffuse, sky_brightness;
l = &cur_light_params;
t = &cur_time_params; t = &cur_time_params;
v = &current_view; v = &current_view;
fgPrintf( FG_EVENT, FG_INFO, "Updating light parameters.\n" ); fgPrintf( FG_EVENT, FG_INFO, "Updating light parameters.\n" );
/* calculate lighting parameters based on sun's relative angle to // calculate lighting parameters based on sun's relative angle to
* local up */ // local up
deg = l->sun_angle * 180.0 / FG_PI; deg = sun_angle * 180.0 / FG_PI;
fgPrintf( FG_EVENT, FG_INFO, " Sun angle = %.2f.\n", deg ); fgPrintf( FG_EVENT, FG_INFO, " Sun angle = %.2f.\n", deg );
ambient = ambient_tbl->interpolate( deg ); ambient = ambient_tbl->interpolate( deg );
@ -131,33 +130,46 @@ void fgLightUpdate( void ) {
// if ( diffuse < 0.0 ) { diffuse = 0.0; } // if ( diffuse < 0.0 ) { diffuse = 0.0; }
// if ( sky_brightness < 0.1 ) { sky_brightness = 0.1; } // if ( sky_brightness < 0.1 ) { sky_brightness = 0.1; }
l->scene_ambient[0] = white[0] * ambient; scene_ambient[0] = white[0] * ambient;
l->scene_ambient[1] = white[1] * ambient; scene_ambient[1] = white[1] * ambient;
l->scene_ambient[2] = white[2] * ambient; scene_ambient[2] = white[2] * ambient;
l->scene_diffuse[0] = white[0] * diffuse; scene_diffuse[0] = white[0] * diffuse;
l->scene_diffuse[1] = white[1] * diffuse; scene_diffuse[1] = white[1] * diffuse;
l->scene_diffuse[2] = white[2] * diffuse; scene_diffuse[2] = white[2] * diffuse;
/* set fog color */ // set fog color
// l->fog_color[0] = base_fog_color[0] * (ambient + diffuse); fog_color[0] = base_fog_color[0] * sky_brightness;
// l->fog_color[1] = base_fog_color[1] * (ambient + diffuse); fog_color[1] = base_fog_color[1] * sky_brightness;
// l->fog_color[2] = base_fog_color[2] * (ambient + diffuse); fog_color[2] = base_fog_color[2] * sky_brightness;
// l->fog_color[3] = base_fog_color[3]; fog_color[3] = base_fog_color[3];
l->fog_color[0] = base_fog_color[0] * sky_brightness;
l->fog_color[1] = base_fog_color[1] * sky_brightness;
l->fog_color[2] = base_fog_color[2] * sky_brightness;
l->fog_color[3] = base_fog_color[3];
/* set sky color */ // set sky color
l->sky_color[0] = base_sky_color[0] * sky_brightness; sky_color[0] = base_sky_color[0] * sky_brightness;
l->sky_color[1] = base_sky_color[1] * sky_brightness; sky_color[1] = base_sky_color[1] * sky_brightness;
l->sky_color[2] = base_sky_color[2] * sky_brightness; sky_color[2] = base_sky_color[2] * sky_brightness;
l->sky_color[3] = base_sky_color[3]; sky_color[3] = base_sky_color[3];
}
// Destructor
fgLIGHT::~fgLIGHT( void ) {
}
// wrapper function for updating light parameters via the event scheduler
void fgLightUpdate ( void ) {
fgLIGHT *l;
l = &cur_light_params;
l->Update();
} }
// $Log$ // $Log$
// Revision 1.8 1998/05/20 20:54:16 curt
// Converted fgLIGHT to a C++ class.
//
// Revision 1.7 1998/05/13 18:26:50 curt // Revision 1.7 1998/05/13 18:26:50 curt
// Root path info moved to fgOPTIONS. // Root path info moved to fgOPTIONS.
// //
@ -182,4 +194,3 @@ void fgLightUpdate( void ) {
// C++ - ifiing the code a bit. // C++ - ifiing the code a bit.
// Starting to reorginize some of the lighting calcs to use a table lookup. // Starting to reorginize some of the lighting calcs to use a table lookup.
// //
//

View file

@ -1,4 +1,3 @@
//
// light.hxx -- lighting routines // light.hxx -- lighting routines
// //
// Written by Curtis Olson, started April 1998. // Written by Curtis Olson, started April 1998.
@ -43,10 +42,18 @@
#include <XGL/xgl.h> #include <XGL/xgl.h>
#include <Include/fg_types.h> #include <Include/fg_types.h>
#include <Math/interpolater.hxx>
// Define a structure containing the global lighting parameters // Define a structure containing the global lighting parameters
typedef struct { class fgLIGHT {
// Lighting look up tables (based on sun angle with local horizon)
fgINTERPTABLE *ambient_tbl;
fgINTERPTABLE *diffuse_tbl;
fgINTERPTABLE *sky_tbl;
public:
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// position of the sun in various forms // position of the sun in various forms
@ -80,24 +87,36 @@ typedef struct {
// clear screen color // clear screen color
GLfloat sky_color[4]; GLfloat sky_color[4];
} fgLIGHT;
// Constructor
fgLIGHT( void );
// initialize lighting tables
void Init( void );
// update lighting parameters based on current sun position
void Update( void);
// Destructor
~fgLIGHT( void );
};
// Global shared light parameter structure
extern fgLIGHT cur_light_params; extern fgLIGHT cur_light_params;
// initialize lighting tables // wrapper function for updating light parameters via the event scheduler
void fgLightInit( void ); void fgLightUpdate ( void );
// update lighting parameters based on current sun position
void fgLightUpdate( void);
#endif // _LIGHT_HXX #endif // _LIGHT_HXX
// $Log$ // $Log$
// Revision 1.4 1998/05/20 20:54:17 curt
// Converted fgLIGHT to a C++ class.
//
// Revision 1.3 1998/05/02 01:53:18 curt // Revision 1.3 1998/05/02 01:53:18 curt
// Fine tuning mktime() support because of varying behavior on different // Fine tuning mktime() support because of varying behavior on different
// platforms. // platforms.