#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"
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; */
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) */
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 );
}
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 = ¤t_aircraft.flight;
/* 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;
/* $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
*
-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
+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
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
______
| /|
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;
/* 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);
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);
/* 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;
/* $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.
*
/* 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;
}
/* $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.
*
#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 */
/* $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.
*
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)
#---------------------------------------------------------------------------
# $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
#
+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
#include <math.h>
#include <stdio.h>
-#include <sys/time.h>
+#include <time.h>
#include "sunpos.h"
#include "../constants.h"
/* $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.
+ *
*/
#define SUNPOS_H
-#include <sys/time.h>
+#include <time.h>
/* given a particular time (expressed in seconds since the unix