C++ - ifiing the code a bit.
Starting to reorginize some of the lighting calcs to use a table lookup.
This commit is contained in:
parent
aba1974dad
commit
73ed3c180e
8 changed files with 357 additions and 85 deletions
|
@ -6,6 +6,7 @@ libTime_la_SOURCES = \
|
||||||
event.c event.h \
|
event.c event.h \
|
||||||
fg_time.c fg_time.h \
|
fg_time.c fg_time.h \
|
||||||
fg_timer.c fg_timer.h \
|
fg_timer.c fg_timer.h \
|
||||||
sunpos.c sunpos.h
|
light.cxx light.hxx \
|
||||||
|
sunpos.cxx sunpos.hxx
|
||||||
|
|
||||||
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator
|
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator
|
||||||
|
|
|
@ -78,7 +78,8 @@ libTime_la_SOURCES = \
|
||||||
event.c event.h \
|
event.c event.h \
|
||||||
fg_time.c fg_time.h \
|
fg_time.c fg_time.h \
|
||||||
fg_timer.c fg_timer.h \
|
fg_timer.c fg_timer.h \
|
||||||
sunpos.c sunpos.h
|
light.cxx light.hxx \
|
||||||
|
sunpos.cxx sunpos.hxx
|
||||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||||
CONFIG_HEADER = ../../Include/config.h
|
CONFIG_HEADER = ../../Include/config.h
|
||||||
CONFIG_CLEAN_FILES =
|
CONFIG_CLEAN_FILES =
|
||||||
|
@ -95,7 +96,11 @@ X_EXTRA_LIBS = @X_EXTRA_LIBS@
|
||||||
X_PRE_LIBS = @X_PRE_LIBS@
|
X_PRE_LIBS = @X_PRE_LIBS@
|
||||||
libTime_la_LDFLAGS =
|
libTime_la_LDFLAGS =
|
||||||
libTime_la_LIBADD =
|
libTime_la_LIBADD =
|
||||||
libTime_la_OBJECTS = event.lo fg_time.lo fg_timer.lo sunpos.lo
|
libTime_la_OBJECTS = event.lo fg_time.lo fg_timer.lo light.lo sunpos.lo
|
||||||
|
CXXFLAGS = @CXXFLAGS@
|
||||||
|
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)
|
||||||
|
LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)
|
||||||
|
CXXLINK = $(LIBTOOL) --mode=link $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@
|
||||||
CFLAGS = @CFLAGS@
|
CFLAGS = @CFLAGS@
|
||||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
|
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
|
||||||
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
|
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
|
||||||
|
@ -108,14 +113,15 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
|
||||||
TAR = tar
|
TAR = tar
|
||||||
GZIP = --best
|
GZIP = --best
|
||||||
DEP_FILES = .deps/event.P .deps/fg_time.P .deps/fg_timer.P \
|
DEP_FILES = .deps/event.P .deps/fg_time.P .deps/fg_timer.P \
|
||||||
.deps/sunpos.P
|
.deps/light.P .deps/sunpos.P
|
||||||
|
CXXMKDEP = $(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)
|
||||||
SOURCES = $(libTime_la_SOURCES)
|
SOURCES = $(libTime_la_SOURCES)
|
||||||
OBJECTS = $(libTime_la_OBJECTS)
|
OBJECTS = $(libTime_la_OBJECTS)
|
||||||
|
|
||||||
all: Makefile $(LTLIBRARIES)
|
all: Makefile $(LTLIBRARIES)
|
||||||
|
|
||||||
.SUFFIXES:
|
.SUFFIXES:
|
||||||
.SUFFIXES: .S .c .lo .o .s
|
.SUFFIXES: .S .c .cxx .lo .o .s
|
||||||
$(srcdir)/Makefile.in: @MAINT@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
|
$(srcdir)/Makefile.in: @MAINT@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
|
||||||
cd $(top_srcdir) && $(AUTOMAKE) --gnu Simulator/Time/Makefile
|
cd $(top_srcdir) && $(AUTOMAKE) --gnu Simulator/Time/Makefile
|
||||||
|
|
||||||
|
@ -182,7 +188,11 @@ distclean-libtool:
|
||||||
maintainer-clean-libtool:
|
maintainer-clean-libtool:
|
||||||
|
|
||||||
libTime.la: $(libTime_la_OBJECTS) $(libTime_la_DEPENDENCIES)
|
libTime.la: $(libTime_la_OBJECTS) $(libTime_la_DEPENDENCIES)
|
||||||
$(LINK) -rpath $(libdir) $(libTime_la_LDFLAGS) $(libTime_la_OBJECTS) $(libTime_la_LIBADD) $(LIBS)
|
$(CXXLINK) -rpath $(libdir) $(libTime_la_LDFLAGS) $(libTime_la_OBJECTS) $(libTime_la_LIBADD) $(LIBS)
|
||||||
|
.cxx.o:
|
||||||
|
$(CXXCOMPILE) -c $<
|
||||||
|
.cxx.lo:
|
||||||
|
$(LTCXXCOMPILE) -c $<
|
||||||
|
|
||||||
tags: TAGS
|
tags: TAGS
|
||||||
|
|
||||||
|
@ -249,6 +259,17 @@ maintainer-clean-depend:
|
||||||
@-sed -e 's/^\([^:]*\)\.o:/\1.lo \1.o:/' \
|
@-sed -e 's/^\([^:]*\)\.o:/\1.lo \1.o:/' \
|
||||||
< .deps/$(*F).p > .deps/$(*F).P
|
< .deps/$(*F).p > .deps/$(*F).P
|
||||||
@-rm -f .deps/$(*F).p
|
@-rm -f .deps/$(*F).p
|
||||||
|
|
||||||
|
%.o: %.cxx
|
||||||
|
@echo '$(CXXCOMPILE) -c $<'; \
|
||||||
|
$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).P -c $<
|
||||||
|
|
||||||
|
%.lo: %.cxx
|
||||||
|
@echo '$(LTCXXCOMPILE) -c $<'; \
|
||||||
|
$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).p -c $<
|
||||||
|
@-sed -e 's/^\([^:]*\)\.o:/\1.lo \1.o:/' \
|
||||||
|
< .deps/$(*F).p > .deps/$(*F).P
|
||||||
|
@-rm -f .deps/$(*F).p
|
||||||
info:
|
info:
|
||||||
dvi:
|
dvi:
|
||||||
check: all
|
check: all
|
||||||
|
|
|
@ -44,14 +44,15 @@
|
||||||
#include <Debug/fg_debug.h>
|
#include <Debug/fg_debug.h>
|
||||||
#include <Flight/flight.h>
|
#include <Flight/flight.h>
|
||||||
#include <Include/fg_constants.h>
|
#include <Include/fg_constants.h>
|
||||||
#include <Time/fg_time.h>
|
|
||||||
|
#include "fg_time.h"
|
||||||
|
|
||||||
|
|
||||||
#define DEGHR(x) ((x)/15.)
|
#define DEGHR(x) ((x)/15.)
|
||||||
#define RADHR(x) DEGHR(x*RAD_TO_DEG)
|
#define RADHR(x) DEGHR(x*RAD_TO_DEG)
|
||||||
|
|
||||||
|
|
||||||
struct fgTIME cur_time_params;
|
struct fgTIME cur_time_params;
|
||||||
struct fgLIGHT cur_light_params;
|
|
||||||
|
|
||||||
|
|
||||||
/* Initialize the time dependent variables */
|
/* Initialize the time dependent variables */
|
||||||
|
@ -367,9 +368,13 @@ void fgTimeUpdate(fgFLIGHT *f, struct fgTIME *t) {
|
||||||
|
|
||||||
|
|
||||||
/* $Log$
|
/* $Log$
|
||||||
/* Revision 1.40 1998/04/18 04:14:09 curt
|
/* Revision 1.41 1998/04/22 13:24:05 curt
|
||||||
/* Moved fg_debug.c to it's own library.
|
/* C++ - ifiing the code a bit.
|
||||||
|
/* Starting to reorginize some of the lighting calcs to use a table lookup.
|
||||||
/*
|
/*
|
||||||
|
* Revision 1.40 1998/04/18 04:14:09 curt
|
||||||
|
* Moved fg_debug.c to it's own library.
|
||||||
|
*
|
||||||
* Revision 1.39 1998/04/09 18:40:14 curt
|
* Revision 1.39 1998/04/09 18:40:14 curt
|
||||||
* We had unified some of the platform disparate time handling code, and
|
* We had unified some of the platform disparate time handling code, and
|
||||||
* there was a bug in timesum() which calculated a new time stamp based on
|
* there was a bug in timesum() which calculated a new time stamp based on
|
||||||
|
|
|
@ -28,11 +28,6 @@
|
||||||
#define _FG_TIME_H
|
#define _FG_TIME_H
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#ifdef HAVE_WINDOWS_H
|
#ifdef HAVE_WINDOWS_H
|
||||||
|
@ -46,6 +41,11 @@ extern "C" {
|
||||||
#include <Flight/flight.h>
|
#include <Flight/flight.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Define a structure containing global time parameters */
|
/* Define a structure containing global time parameters */
|
||||||
struct fgTIME {
|
struct fgTIME {
|
||||||
/* the date/time in various forms */
|
/* the date/time in various forms */
|
||||||
|
@ -74,26 +74,6 @@ struct fgTIME {
|
||||||
extern struct fgTIME cur_time_params;
|
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 */
|
|
||||||
GLfloat sun_vec[4]; /* (in view coordinates) */
|
|
||||||
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 fog_color[4]; /* fog color */
|
|
||||||
GLfloat sky_color[4]; /* clear screen color */
|
|
||||||
};
|
|
||||||
|
|
||||||
extern struct fgLIGHT cur_light_params;
|
|
||||||
|
|
||||||
typedef struct fg_timestamp_t {
|
typedef struct fg_timestamp_t {
|
||||||
long seconds;
|
long seconds;
|
||||||
long millis;
|
long millis;
|
||||||
|
@ -125,13 +105,17 @@ void fgTimeUpdate(fgFLIGHT *f, struct fgTIME *t);
|
||||||
|
|
||||||
|
|
||||||
/* $Log$
|
/* $Log$
|
||||||
/* Revision 1.19 1998/04/21 17:01:44 curt
|
/* Revision 1.20 1998/04/22 13:24:05 curt
|
||||||
/* Fixed a problems where a pointer to a function was being passed around. In
|
/* C++ - ifiing the code a bit.
|
||||||
/* one place this functions arguments were defined as ( void ) while in another
|
/* Starting to reorginize some of the lighting calcs to use a table lookup.
|
||||||
/* place they were defined as ( int ). The correct answer was ( int ).
|
|
||||||
/*
|
|
||||||
/* Prepairing for C++ integration.
|
|
||||||
/*
|
/*
|
||||||
|
* Revision 1.19 1998/04/21 17:01:44 curt
|
||||||
|
* Fixed a problems where a pointer to a function was being passed around. In
|
||||||
|
* one place this functions arguments were defined as ( void ) while in another
|
||||||
|
* place they were defined as ( int ). The correct answer was ( int ).
|
||||||
|
*
|
||||||
|
* Prepairing for C++ integration.
|
||||||
|
*
|
||||||
* Revision 1.18 1998/04/08 23:35:40 curt
|
* Revision 1.18 1998/04/08 23:35:40 curt
|
||||||
* Tweaks to Gnu automake/autoconf system.
|
* Tweaks to Gnu automake/autoconf system.
|
||||||
*
|
*
|
||||||
|
|
158
Time/light.cxx
Normal file
158
Time/light.cxx
Normal file
|
@ -0,0 +1,158 @@
|
||||||
|
//
|
||||||
|
// light.hxx -- lighting routines
|
||||||
|
//
|
||||||
|
// Written by Curtis Olson, started April 1998.
|
||||||
|
//
|
||||||
|
// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_WINDOWS_H
|
||||||
|
# include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <GL/glut.h>
|
||||||
|
#include <XGL/xgl.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <Debug/fg_debug.h>
|
||||||
|
#include <Include/fg_constants.h>
|
||||||
|
#include <Include/general.h>
|
||||||
|
#include <Main/views.hxx>
|
||||||
|
#include <Math/fg_geodesy.h>
|
||||||
|
#include <Math/interpolater.hxx>
|
||||||
|
#include <Math/mat3.h>
|
||||||
|
#include <Math/polar.h>
|
||||||
|
|
||||||
|
#include "fg_time.h"
|
||||||
|
#include "light.hxx"
|
||||||
|
#include "sunpos.hxx"
|
||||||
|
|
||||||
|
|
||||||
|
fgLIGHT cur_light_params;
|
||||||
|
|
||||||
|
static fgINTERPTABLE *ambient_tbl;
|
||||||
|
static fgINTERPTABLE *diffuse_tbl;
|
||||||
|
static fgINTERPTABLE *sky_tbl;
|
||||||
|
|
||||||
|
|
||||||
|
// initialize lighting tables
|
||||||
|
void fgLightInit( void ) {
|
||||||
|
fgGENERAL *g;
|
||||||
|
char path[256];
|
||||||
|
|
||||||
|
fgPrintf( FG_EVENT, FG_INFO,
|
||||||
|
"Initializing Lighting interpolation tables.\n" );
|
||||||
|
|
||||||
|
g = &general;
|
||||||
|
|
||||||
|
// build the path name to the ambient lookup table
|
||||||
|
path[0] = '\0';
|
||||||
|
strcat(path, g->root_dir);
|
||||||
|
strcat(path, "/Scenery/");
|
||||||
|
strcat(path, "Ambient.table");
|
||||||
|
// initialize ambient table
|
||||||
|
ambient_tbl = new fgINTERPTABLE(path);
|
||||||
|
|
||||||
|
// build the path name to the diffuse lookup table
|
||||||
|
path[0] = '\0';
|
||||||
|
strcat(path, g->root_dir);
|
||||||
|
strcat(path, "/Scenery/");
|
||||||
|
strcat(path, "Diffuse.table");
|
||||||
|
// initialize diffuse table
|
||||||
|
diffuse_tbl = new fgINTERPTABLE(path);
|
||||||
|
|
||||||
|
// build the path name to the sky lookup table
|
||||||
|
path[0] = '\0';
|
||||||
|
strcat(path, g->root_dir);
|
||||||
|
strcat(path, "/Scenery/");
|
||||||
|
strcat(path, "Sky.table");
|
||||||
|
// initialize sky table
|
||||||
|
sky_tbl = new fgINTERPTABLE(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// update lighting parameters based on current sun position
|
||||||
|
void fgLightUpdate( void ) {
|
||||||
|
struct fgLIGHT *l;
|
||||||
|
struct fgTIME *t;
|
||||||
|
struct fgVIEW *v;
|
||||||
|
/* if the 4th field is 0.0, this specifies a direction ... */
|
||||||
|
GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
|
||||||
|
/* base sky color */
|
||||||
|
GLfloat base_sky_color[4] = {0.60, 0.60, 0.90, 1.0};
|
||||||
|
/* base fog color */
|
||||||
|
GLfloat base_fog_color[4] = {0.70, 0.70, 0.70, 1.0};
|
||||||
|
double deg, ambient, diffuse, sky_brightness;
|
||||||
|
|
||||||
|
l = &cur_light_params;
|
||||||
|
t = &cur_time_params;
|
||||||
|
v = ¤t_view;
|
||||||
|
|
||||||
|
fgPrintf( FG_EVENT, FG_INFO, "Updating light parameters.\n" );
|
||||||
|
|
||||||
|
/* calculate lighting parameters based on sun's relative angle to
|
||||||
|
* local up */
|
||||||
|
|
||||||
|
deg = l->sun_angle * 180.0 / FG_PI;
|
||||||
|
fgPrintf( FG_EVENT, FG_INFO, " Sun angle = %.2f.\n", deg );
|
||||||
|
|
||||||
|
ambient = ambient_tbl->interpolate( deg );
|
||||||
|
diffuse = diffuse_tbl->interpolate( deg );
|
||||||
|
sky_brightness = sky_tbl->interpolate( deg );
|
||||||
|
|
||||||
|
fgPrintf( FG_EVENT, FG_INFO,
|
||||||
|
" ambient = %.2f diffuse = %.2f sky = %.2f\n",
|
||||||
|
ambient, diffuse, sky_brightness );
|
||||||
|
|
||||||
|
// sky_brightness = 0.15; // used to force a dark sky (when testing)
|
||||||
|
|
||||||
|
// if ( ambient < 0.02 ) { ambient = 0.02; }
|
||||||
|
// if ( diffuse < 0.0 ) { diffuse = 0.0; }
|
||||||
|
// if ( sky_brightness < 0.1 ) { sky_brightness = 0.1; }
|
||||||
|
|
||||||
|
l->scene_ambient[0] = white[0] * ambient;
|
||||||
|
l->scene_ambient[1] = white[1] * ambient;
|
||||||
|
l->scene_ambient[2] = white[2] * ambient;
|
||||||
|
|
||||||
|
l->scene_diffuse[0] = white[0] * diffuse;
|
||||||
|
l->scene_diffuse[1] = white[1] * diffuse;
|
||||||
|
l->scene_diffuse[2] = white[2] * diffuse;
|
||||||
|
|
||||||
|
/* set fog color */
|
||||||
|
l->fog_color[0] = base_fog_color[0] * (ambient + diffuse);
|
||||||
|
l->fog_color[1] = base_fog_color[1] * (ambient + diffuse);
|
||||||
|
l->fog_color[2] = base_fog_color[2] * (ambient + diffuse);
|
||||||
|
l->fog_color[3] = base_fog_color[3];
|
||||||
|
|
||||||
|
/* set sky color */
|
||||||
|
l->sky_color[0] = base_sky_color[0] * sky_brightness;
|
||||||
|
l->sky_color[1] = base_sky_color[1] * sky_brightness;
|
||||||
|
l->sky_color[2] = base_sky_color[2] * sky_brightness;
|
||||||
|
l->sky_color[3] = base_sky_color[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// $Log$
|
||||||
|
// Revision 1.1 1998/04/22 13:24:06 curt
|
||||||
|
// C++ - ifiing the code a bit.
|
||||||
|
// Starting to reorginize some of the lighting calcs to use a table lookup.
|
||||||
|
//
|
||||||
|
//
|
103
Time/light.hxx
Normal file
103
Time/light.hxx
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
//
|
||||||
|
// light.hxx -- lighting routines
|
||||||
|
//
|
||||||
|
// Written by Curtis Olson, started April 1998.
|
||||||
|
//
|
||||||
|
// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but
|
||||||
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef _LIGHT_HXX
|
||||||
|
#define _LIGHT_HXX
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __cplusplus
|
||||||
|
# error This library requires C++
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_WINDOWS_H
|
||||||
|
# include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <GL/glut.h>
|
||||||
|
#include <XGL/xgl.h>
|
||||||
|
|
||||||
|
#include <Include/fg_types.h>
|
||||||
|
|
||||||
|
|
||||||
|
// Define a structure containing the global lighting parameters
|
||||||
|
typedef struct {
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// position of the sun in various forms
|
||||||
|
|
||||||
|
// in geocentric coordinates
|
||||||
|
double sun_lon, sun_gc_lat;
|
||||||
|
|
||||||
|
// in cartesian coordiantes
|
||||||
|
struct fgCartesianPoint fg_sunpos;
|
||||||
|
|
||||||
|
// (in view coordinates)
|
||||||
|
GLfloat sun_vec[4];
|
||||||
|
|
||||||
|
// inverse (in view coordinates)
|
||||||
|
GLfloat sun_vec_inv[4];
|
||||||
|
|
||||||
|
// the angle between the sun and the local horizontal
|
||||||
|
double sun_angle;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// Derived lighting values
|
||||||
|
|
||||||
|
// ambient component
|
||||||
|
GLfloat scene_ambient[3];
|
||||||
|
|
||||||
|
// diffuse component
|
||||||
|
GLfloat scene_diffuse[3];
|
||||||
|
|
||||||
|
// fog color
|
||||||
|
GLfloat fog_color[4];
|
||||||
|
|
||||||
|
// clear screen color
|
||||||
|
GLfloat sky_color[4];
|
||||||
|
} fgLIGHT;
|
||||||
|
|
||||||
|
|
||||||
|
extern fgLIGHT cur_light_params;
|
||||||
|
|
||||||
|
|
||||||
|
// initialize lighting tables
|
||||||
|
void fgLightInit( void );
|
||||||
|
|
||||||
|
|
||||||
|
// update lighting parameters based on current sun position
|
||||||
|
void fgLightUpdate( void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _LIGHT_HXX
|
||||||
|
|
||||||
|
|
||||||
|
// $Log$
|
||||||
|
// Revision 1.1 1998/04/22 13:24:06 curt
|
||||||
|
// C++ - ifiing the code a bit.
|
||||||
|
// Starting to reorginize some of the lighting calcs to use a table lookup.
|
||||||
|
//
|
||||||
|
//
|
|
@ -43,14 +43,15 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include <Astro/orbits.h>
|
#include <Astro/orbits.hxx>
|
||||||
#include <Include/fg_constants.h>
|
#include <Include/fg_constants.h>
|
||||||
#include <Main/views.h>
|
#include <Main/views.hxx>
|
||||||
#include <Math/fg_geodesy.h>
|
#include <Math/fg_geodesy.h>
|
||||||
#include <Math/mat3.h>
|
#include <Math/mat3.h>
|
||||||
#include <Math/polar.h>
|
#include <Math/polar.h>
|
||||||
#include <Time/fg_time.h>
|
|
||||||
#include <Time/sunpos.h>
|
#include "fg_time.h"
|
||||||
|
#include "sunpos.hxx"
|
||||||
|
|
||||||
|
|
||||||
#undef E
|
#undef E
|
||||||
|
@ -337,51 +338,55 @@ void fgUpdateSunPos( void ) {
|
||||||
/* ya kind'a have to plot this to see how it works */
|
/* ya kind'a have to plot this to see how it works */
|
||||||
|
|
||||||
/* x = t->sun_angle^8 */
|
/* x = t->sun_angle^8 */
|
||||||
x_2 = l->sun_angle * l->sun_angle;
|
// x_2 = l->sun_angle * l->sun_angle;
|
||||||
x_4 = x_2 * x_2;
|
// x_4 = x_2 * x_2;
|
||||||
x_8 = x_4 * x_4;
|
// x_8 = x_4 * x_4;
|
||||||
x_10 = x_8 * x_2;
|
// x_10 = x_8 * x_2;
|
||||||
|
|
||||||
light = pow(1.1, -x_10 / 30.0);
|
// light = pow(1.1, -x_10 / 30.0);
|
||||||
ambient = 0.2 * light;
|
// ambient = 0.2 * light;
|
||||||
diffuse = 1.0 * light;
|
// diffuse = 1.0 * light;
|
||||||
|
|
||||||
sky_brightness = 0.85 * pow(1.2, -x_8 / 20.0) + 0.15;
|
// sky_brightness = 0.85 * pow(1.2, -x_8 / 20.0) + 0.15;
|
||||||
|
|
||||||
/* sky_brightness = 0.15; */ /* to force a dark sky (for testing) */
|
/* sky_brightness = 0.15; */ /* to force a dark sky (for testing) */
|
||||||
|
|
||||||
if ( ambient < 0.02 ) { ambient = 0.02; }
|
// if ( ambient < 0.02 ) { ambient = 0.02; }
|
||||||
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;
|
// l->scene_ambient[0] = white[0] * ambient;
|
||||||
l->scene_ambient[1] = white[1] * ambient;
|
// l->scene_ambient[1] = white[1] * ambient;
|
||||||
l->scene_ambient[2] = white[2] * ambient;
|
// l->scene_ambient[2] = white[2] * ambient;
|
||||||
|
|
||||||
l->scene_diffuse[0] = white[0] * diffuse;
|
// l->scene_diffuse[0] = white[0] * diffuse;
|
||||||
l->scene_diffuse[1] = white[1] * diffuse;
|
// l->scene_diffuse[1] = white[1] * diffuse;
|
||||||
l->scene_diffuse[2] = white[2] * diffuse;
|
// l->scene_diffuse[2] = white[2] * diffuse;
|
||||||
|
|
||||||
/* set fog color */
|
// /* set fog color */
|
||||||
l->fog_color[0] = base_fog_color[0] * (ambient + diffuse);
|
// l->fog_color[0] = base_fog_color[0] * (ambient + diffuse);
|
||||||
l->fog_color[1] = base_fog_color[1] * (ambient + diffuse);
|
// l->fog_color[1] = base_fog_color[1] * (ambient + diffuse);
|
||||||
l->fog_color[2] = base_fog_color[2] * (ambient + diffuse);
|
// l->fog_color[2] = base_fog_color[2] * (ambient + diffuse);
|
||||||
l->fog_color[3] = base_fog_color[3];
|
// l->fog_color[3] = base_fog_color[3];
|
||||||
|
|
||||||
/* set sky color */
|
// /* set sky color */
|
||||||
l->sky_color[0] = base_sky_color[0] * sky_brightness;
|
// l->sky_color[0] = base_sky_color[0] * sky_brightness;
|
||||||
l->sky_color[1] = base_sky_color[1] * sky_brightness;
|
// l->sky_color[1] = base_sky_color[1] * sky_brightness;
|
||||||
l->sky_color[2] = base_sky_color[2] * sky_brightness;
|
// l->sky_color[2] = base_sky_color[2] * sky_brightness;
|
||||||
l->sky_color[3] = base_sky_color[3];
|
// l->sky_color[3] = base_sky_color[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* $Log$
|
/* $Log$
|
||||||
/* Revision 1.27 1998/04/03 22:12:57 curt
|
/* Revision 1.1 1998/04/22 13:24:07 curt
|
||||||
/* Converting to Gnu autoconf system.
|
/* C++ - ifiing the code a bit.
|
||||||
/* Centralized time handling differences.
|
/* Starting to reorginize some of the lighting calcs to use a table lookup.
|
||||||
/*
|
/*
|
||||||
|
* Revision 1.27 1998/04/03 22:12:57 curt
|
||||||
|
* Converting to Gnu autoconf system.
|
||||||
|
* Centralized time handling differences.
|
||||||
|
*
|
||||||
* Revision 1.26 1998/02/23 19:08:00 curt
|
* Revision 1.26 1998/02/23 19:08:00 curt
|
||||||
* Incorporated Durk's Astro/ tweaks. Includes unifying the sun position
|
* Incorporated Durk's Astro/ tweaks. Includes unifying the sun position
|
||||||
* calculation code between sun display, and other FG sections that use this
|
* calculation code between sun display, and other FG sections that use this
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* sunpos.h
|
* sunpos.hxx
|
||||||
* kirk johnson
|
* kirk johnson
|
||||||
* july 1993
|
* july 1993
|
||||||
*
|
*
|
||||||
|
@ -36,12 +36,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef _SUNPOS_H
|
#ifndef _SUNPOS_HXX
|
||||||
#define _SUNPOS_H
|
#define _SUNPOS_HXX
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifndef __cplusplus
|
||||||
extern "C" {
|
# error This library requires C++
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,9 +55,4 @@ void fgUpdateSunPos( void );
|
||||||
void fgSunPosition(time_t ssue, double *lon, double *lat);
|
void fgSunPosition(time_t ssue, double *lon, double *lat);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* _SUNPOS_H */
|
#endif /* _SUNPOS_H */
|
Loading…
Add table
Reference in a new issue