1
0
Fork 0

Working on correct real time sun lighting.

This commit is contained in:
curt 1997-08-06 00:24:22 +00:00
parent 1b7267aaad
commit 88c803c7fc
10 changed files with 94 additions and 42 deletions

View file

@ -40,10 +40,12 @@
#include "../Aircraft/aircraft.h"
#include "../Scenery/mesh.h"
#include "../Scenery/scenery.h"
#include "../Math/fg_geodesy.h"
#include "../Math/fg_random.h"
#include "../Math/mat3.h"
#include "../Math/polar.h"
#include "../Time/fg_timer.h"
#include "../Time/sunpos.h"
#include "../Weather/weather.h"
@ -55,7 +57,7 @@ struct aircraft_params current_aircraft;
static GLfloat win_ratio = 1.0;
/* sun direction */
static GLfloat sun_vec[4] = {0.2948, 0.7816, -0.5498, 0.0 };
static GLfloat sun_vec[4] = {1.0, 0.0, 0.0, 0.0 };
/* temporary hack */
/* extern struct mesh *mesh_ptr; */
@ -136,9 +138,15 @@ static void fgUpdateViewParams() {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glLightfv( GL_LIGHT0, GL_POSITION, sun_vec );
/* calculate view position in current FG view coordinate system */
view_pos = fgPolarToCart(FG_Longitude, FG_Lat_geocentric,
FG_Radius_to_vehicle * FEET_TO_METER + 1.0);
view_pos.x -= scenery.center.x;
view_pos.y -= scenery.center.y;
view_pos.z -= scenery.center.z;
printf("View pos = %.4f, %.4f, %.4f\n", view_pos.x, view_pos.y, view_pos.z);
/* Derive the LOCAL aircraft rotation matrix (roll, pitch, yaw) */
@ -214,8 +222,6 @@ static void fgUpdateViewParams() {
view_pos.x + view_forward[0], view_pos.y + view_forward[1],
view_pos.z + view_forward[2],
view_up[0], view_up[1], view_up[2]);
glLightfv( GL_LIGHT0, GL_POSITION, sun_vec );
}
@ -248,6 +254,8 @@ static void fgUpdateVisuals( void ) {
void fgUpdateTimeDepCalcs(int multi_loop) {
struct flight_params *f;
struct fgCartesianPoint sunpos;
double sun_lon, sun_gd_lat, sun_gc_lat, sl_radius;
int i;
f = &current_aircraft.flight;
@ -260,6 +268,21 @@ void fgUpdateTimeDepCalcs(int multi_loop) {
/* printf("updating flight model x %d\n", multi_loop); */
fgFlightModelUpdate(FG_LARCSIM, f, multi_loop);
/* refresh sun position */
fgSunPosition(time(NULL), &sun_lon, &sun_gd_lat);
fgGeodToGeoc(sun_gd_lat, 0, &sl_radius, &sun_gc_lat);
sunpos = fgPolarToCart(sun_lon, sun_gc_lat, sl_radius);
printf("Sun position is (%.2f, %.2f, %.2f)\n",
sunpos.x, sunpos.y, sunpos.z);
/* not necessary to divide, but I'm just doing it by a "random"
* constant to get near the magnitude of the number down to the
* 0.0 - 1.0 range */
sun_vec[0] = -sunpos.x;
sun_vec[1] = -sunpos.y;
sun_vec[2] = -sunpos.z;
sun_vec[3] = 0.0; /* make this a directional light source only */
/* update the view angle */
for ( i = 0; i < multi_loop; i++ ) {
if ( fabs(goal_view_offset - view_offset) < 0.05 ) {
view_offset = goal_view_offset;
@ -620,9 +643,12 @@ int main( int argc, char *argv[] ) {
/* $Log$
/* Revision 1.2 1997/08/04 20:25:15 curt
/* Organizational tweaking.
/* Revision 1.3 1997/08/06 00:24:22 curt
/* Working on correct real time sun lighting.
/*
* Revision 1.2 1997/08/04 20:25:15 curt
* Organizational tweaking.
*
* Revision 1.1 1997/08/02 18:45:00 curt
* Renamed GLmain.c GLUTmain.c
*

View file

@ -1,22 +1,15 @@
GLTKkey.o: GLTKkey.c /usr/include/gltk.h GLTKkey.h \
../Aircraft/aircraft.h ../Aircraft/../Flight/flight.h \
../Aircraft/../Flight/Slew/slew.h \
../Aircraft/../Flight/LaRCsim/ls_interface.h \
../Aircraft/../Flight/LaRCsim/../flight.h \
../Aircraft/../Controls/controls.h \
../Aircraft/../Controls/../limits.h
GLUTkey.o: GLUTkey.c GLUTkey.h ../Aircraft/aircraft.h \
../Aircraft/../Flight/flight.h ../Aircraft/../Flight/Slew/slew.h \
../Aircraft/../Flight/LaRCsim/ls_interface.h \
../Aircraft/../Flight/LaRCsim/../flight.h \
../Aircraft/../Controls/controls.h \
../Aircraft/../Controls/../limits.h ../constants.h
GLmain.o: GLmain.c ../constants.h ../Aircraft/aircraft.h \
GLUTmain.o: GLUTmain.c ../constants.h ../Aircraft/aircraft.h \
../Aircraft/../Flight/flight.h ../Aircraft/../Flight/Slew/slew.h \
../Aircraft/../Flight/LaRCsim/ls_interface.h \
../Aircraft/../Flight/LaRCsim/../flight.h \
../Aircraft/../Controls/controls.h \
../Aircraft/../Controls/../limits.h ../Scenery/mesh.h \
../Scenery/scenery.h ../Math/fg_random.h ../Math/mat3.h \
../Math/polar.h ../Math/../types.h ../Time/fg_timer.h \
../Weather/weather.h
../Scenery/scenery.h ../Scenery/../types.h ../Math/fg_random.h \
../Math/mat3.h ../Math/polar.h ../Math/../types.h ../Time/fg_timer.h \
../Time/sunpos.h ../Weather/weather.h

View file

@ -1,6 +1,10 @@
chunkmgr.o: chunkmgr.c chunkmgr.h mesh.h
common.o: common.c common.h
geometry.o: geometry.c geometry.h mesh.h
mesh.o: mesh.c ../constants.h scenery.h mesh.h common.h
parser.o: parser.c parsevrml.h geometry.h common.h mesh.h scenery.h
mesh.o: mesh.c ../constants.h ../types.h ../Math/fg_geodesy.h \
../Math/fg_random.h ../Math/mat3.h ../Math/polar.h ../Math/../types.h \
mesh.h common.h scenery.h
parser.o: parser.c parsevrml.h geometry.h common.h mesh.h scenery.h \
../types.h
scanner.o: scanner.c parser.h
scenery.o: scenery.c scenery.h parsevrml.h
scenery.o: scenery.c scenery.h ../types.h parsevrml.h

View file

@ -175,7 +175,7 @@ double mesh_altitude(double lon, double lat) {
int xindex, yindex;
int skip;
skip = cur_scenery_params.terrain_skip;
skip = scenery.terrain_skip;
/* determine if we are in the lower triangle or the upper triangle
______
| /|
@ -275,10 +275,11 @@ GLint mesh_to_OpenGL(struct mesh *m) {
GLint mesh;
/* static GLfloat color[4] = { 0.5, 0.4, 0.25, 1.0 }; */ /* dark desert */
static GLfloat color[4] = { 0.5, 0.5, 0.25, 1.0 };
double centerx, centery;
double randx, randy;
float x1, y1, x2, y2, z11, z12, z21, z22;
struct fgCartesianPoint p11, p12, p21, p22;
struct fgCartesianPoint p11, p12, p21, p22, c;
double gc_lon, gc_lat, sl_radius;
MAT3vec v1, v2, normal;
@ -290,7 +291,13 @@ GLint mesh_to_OpenGL(struct mesh *m) {
/* Detail level. This is how big a step we take as we walk
* through the DEM data set. This value is initialized in
* .../Scenery/scenery.c:fgSceneryInit() */
istep = jstep = cur_scenery_params.terrain_skip ;
istep = jstep = scenery.terrain_skip ;
centerx = m->originx + (m->rows * m->row_step) / 2.0;
centery = m->originy + (m->cols * m->col_step) / 2.0;
fgGeodToGeoc(centery*ARCSEC_TO_RAD, 0, &sl_radius, &gc_lat);
c = fgPolarToCart(centerx*ARCSEC_TO_RAD, gc_lat, sl_radius);
scenery.center = c;
mesh = glGenLists(1);
glNewList(mesh, GL_COMPILE);
@ -347,11 +354,11 @@ GLint mesh_to_OpenGL(struct mesh *m) {
if ( j == 0 ) {
/* first time through */
glVertex3d(p12.x, p12.y, p12.z);
glVertex3d(p11.x, p11.y, p11.z);
glVertex3d(p12.x - c.x, p12.y - c.y, p12.z - c.z);
glVertex3d(p11.x - c.x, p11.y - c.y, p11.z - c.z);
}
glVertex3d(p22.x, p22.y, p22.z);
glVertex3d(p22.x - c.x, p22.y - c.y, p22.z - c.z);
v2[0] = p21.y - p11.y; v2[1] = p21.z - p11.z; v2[2] = z21 - z11;
MAT3cross_product(normal, v2, v1);
@ -360,7 +367,7 @@ GLint mesh_to_OpenGL(struct mesh *m) {
/* printf("normal 2 = (%.2f %.2f %.2f\n", normal[0], normal[1],
normal[2]); */
glVertex3d(p21.x, p21.y, p21.z);
glVertex3d(p21.x - c.x, p21.y - c.y, p21.z - c.z);
x1 += m->row_step * jstep;
x2 += m->row_step * jstep;
@ -387,9 +394,12 @@ GLint mesh_to_OpenGL(struct mesh *m) {
/* $Log$
/* Revision 1.18 1997/08/02 19:10:14 curt
/* Incorporated mesh2GL.c into mesh.c
/* Revision 1.19 1997/08/06 00:24:28 curt
/* Working on correct real time sun lighting.
/*
* Revision 1.18 1997/08/02 19:10:14 curt
* Incorporated mesh2GL.c into mesh.c
*
* Revision 1.17 1997/07/18 23:41:26 curt
* Tweaks for building with Cygnus Win32 compiler.
*

View file

@ -39,13 +39,13 @@ GLint mesh_hack;
/* Shared structure to hold current scenery parameters */
struct scenery_params cur_scenery_params;
struct scenery_params scenery;
/* Initialize the Scenery Management system */
void fgSceneryInit() {
/* set the default terrain detail level */
cur_scenery_params.terrain_skip = 5;
scenery.terrain_skip = 3;
}
@ -69,9 +69,12 @@ void fgSceneryRender() {
/* $Log$
/* Revision 1.9 1997/08/04 17:08:11 curt
/* Testing cvs on IRIX 6.x
/* Revision 1.10 1997/08/06 00:24:30 curt
/* Working on correct real time sun lighting.
/*
* Revision 1.9 1997/08/04 17:08:11 curt
* Testing cvs on IRIX 6.x
*
* Revision 1.8 1997/07/18 23:41:27 curt
* Tweaks for building with Cygnus Win32 compiler.
*

View file

@ -28,12 +28,19 @@
#define SCENERY_H
#include "../types.h"
/* Define a structure containing global scenery parameters */
struct scenery_params {
int terrain_skip; /* number of terrain data points to skip */
/* number of terrain data points to skip */
int terrain_skip;
/* center of current scenery chunk */
struct fgCartesianPoint center;
};
extern struct scenery_params cur_scenery_params;
extern struct scenery_params scenery;
/* Initialize the Scenery Management system */
@ -53,9 +60,12 @@ void fgSceneryRender();
/* $Log$
/* Revision 1.7 1997/07/23 21:52:27 curt
/* Put comments around the text after an #endif for increased portability.
/* Revision 1.8 1997/08/06 00:24:30 curt
/* Working on correct real time sun lighting.
/*
* Revision 1.7 1997/07/23 21:52:27 curt
* Put comments around the text after an #endif for increased portability.
*
* Revision 1.6 1997/07/11 01:30:03 curt
* More tweaking of terrian floor.
*

View file

@ -26,8 +26,7 @@
TARGET = libTime.a
CFILES = fg_timer.c sunpos.c
HFILES = fg_timer.h
CFILES = fg_time.c fg_timer.c sunpos.c
OFILES = $(CFILES:.c=.o)
@ -63,6 +62,9 @@ fg_timer.o:
#---------------------------------------------------------------------------
# $Log$
# Revision 1.12 1997/08/06 00:24:31 curt
# Working on correct real time sun lighting.
#
# Revision 1.11 1997/08/01 15:28:44 curt
# Added sunpos.c
#

View file

@ -1,2 +1,3 @@
fg_time.o: fg_time.c fg_time.h ../types.h
fg_timer.o: fg_timer.c fg_timer.h
sunpos.o: sunpos.c sunpos.h ../constants.h

View file

@ -41,7 +41,7 @@
#include <math.h>
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include "sunpos.h"
#include "../constants.h"
@ -254,7 +254,10 @@ void fgSunPosition(time_t ssue, double *lon, double *lat) {
/* $Log$
/* Revision 1.1 1997/08/01 15:27:56 curt
/* Initial revision.
/* Revision 1.2 1997/08/06 00:24:32 curt
/* Working on correct real time sun lighting.
/*
* Revision 1.1 1997/08/01 15:27:56 curt
* Initial revision.
*
*/

View file

@ -40,7 +40,7 @@
#define SUNPOS_H
#include <sys/time.h>
#include <time.h>
/* given a particular time (expressed in seconds since the unix