C++ - ified views.[ch]xx
Shuffled some additional view parameters into the fgVIEW class. Changed tile-radius to tile-diameter because it is a much better name. Added a WORLD_TO_EYE transformation to views.cxx. This allows us to transform world space to eye space for view frustum culling.
This commit is contained in:
parent
fb69df5880
commit
65cc9a9e66
8 changed files with 415 additions and 204 deletions
|
@ -72,10 +72,6 @@
|
|||
// This is a record containing global housekeeping information
|
||||
fgGENERAL general;
|
||||
|
||||
// view parameters
|
||||
static GLfloat win_ratio = 1.0;
|
||||
static GLint winWidth, winHeight;
|
||||
|
||||
// Another hack
|
||||
int use_signals = 0;
|
||||
|
||||
|
@ -233,21 +229,22 @@ static void fgUpdateViewParams( void ) {
|
|||
o = ¤t_options;
|
||||
v = ¤t_view;
|
||||
|
||||
fgViewUpdate(f, v, l);
|
||||
v->Update(f);
|
||||
v->UpdateWorldToEye(f);
|
||||
|
||||
if (displayInstruments) {
|
||||
xglViewport( 0, (GLint)(winHeight / 2 ) ,
|
||||
(GLint)winWidth, (GLint)winHeight / 2 );
|
||||
xglViewport( 0, (GLint)((v->winHeight) / 2 ) ,
|
||||
(GLint)(v->winWidth), (GLint)(v->winHeight) / 2 );
|
||||
// Tell GL we are about to modify the projection parameters
|
||||
xglMatrixMode(GL_PROJECTION);
|
||||
xglLoadIdentity();
|
||||
gluPerspective(o->fov, 2.0/win_ratio, 1.0, 100000.0);
|
||||
gluPerspective(o->fov, v->win_ratio / 2.0, 1.0, 100000.0);
|
||||
} else {
|
||||
xglViewport(0, 0 , (GLint)winWidth, (GLint) winHeight);
|
||||
xglViewport(0, 0 , (GLint)(v->winWidth), (GLint)(v->winHeight) );
|
||||
// Tell GL we are about to modify the projection parameters
|
||||
xglMatrixMode(GL_PROJECTION);
|
||||
xglLoadIdentity();
|
||||
gluPerspective(o->fov, 1.0/win_ratio, 10.0, 100000.0);
|
||||
gluPerspective(o->fov, v->win_ratio, 10.0, 100000.0);
|
||||
}
|
||||
|
||||
xglMatrixMode(GL_MODELVIEW);
|
||||
|
@ -288,7 +285,11 @@ static void fgUpdateViewParams( void ) {
|
|||
|
||||
// Draw a basic instrument panel
|
||||
static void fgUpdateInstrViewParams( void ) {
|
||||
xglViewport(0, 0 , (GLint)winWidth, (GLint)winHeight / 2);
|
||||
fgVIEW *v;
|
||||
|
||||
v = ¤t_view;
|
||||
|
||||
xglViewport(0, 0 , (GLint)(v->winWidth), (GLint)(v->winHeight) / 2);
|
||||
|
||||
xglMatrixMode(GL_PROJECTION);
|
||||
xglPushMatrix();
|
||||
|
@ -618,14 +619,18 @@ static void fgMainLoop( void ) {
|
|||
|
||||
// Handle new window size or exposure
|
||||
static void fgReshape( int width, int height ) {
|
||||
fgVIEW *v;
|
||||
|
||||
v = ¤t_view;
|
||||
|
||||
// Do this so we can call fgReshape(0,0) ourselves without having
|
||||
// to know what the values of width & height are.
|
||||
if ( (height > 0) && (width > 0) ) {
|
||||
win_ratio = (GLfloat) height / (GLfloat) width;
|
||||
v->win_ratio = (GLfloat) width / (GLfloat) height;
|
||||
}
|
||||
|
||||
winWidth = width;
|
||||
winHeight = height;
|
||||
v->winWidth = width;
|
||||
v->winHeight = height;
|
||||
|
||||
// Inform gl of our view window size (now handled elsewhere)
|
||||
// xglViewport(0, 0, (GLint)width, (GLint)height);
|
||||
|
@ -768,6 +773,14 @@ extern "C" {
|
|||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.15 1998/05/16 13:08:34 curt
|
||||
// C++ - ified views.[ch]xx
|
||||
// Shuffled some additional view parameters into the fgVIEW class.
|
||||
// Changed tile-radius to tile-diameter because it is a much better
|
||||
// name.
|
||||
// Added a WORLD_TO_EYE transformation to views.cxx. This allows us
|
||||
// to transform world space to eye space for view frustum culling.
|
||||
//
|
||||
// Revision 1.14 1998/05/13 18:29:57 curt
|
||||
// Added a keyboard binding to dynamically adjust field of view.
|
||||
// Added a command line option to specify fov.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
EXTRA_DIST = runfg.in runfg.bat.in
|
||||
|
||||
bin_PROGRAMS = fg
|
||||
bin_PROGRAMS = fg ttest
|
||||
|
||||
bin_SCRIPTS = runfg runfg.bat
|
||||
|
||||
|
@ -31,6 +31,10 @@ fg_LDADD = \
|
|||
$(top_builddir)/Lib/Debug/libDebug.la \
|
||||
$(top_builddir)/Lib/zlib/libz.la
|
||||
|
||||
ttest_SOURCES = ttest.cxx
|
||||
|
||||
ttest_LDADD = $(top_builddir)/Lib/Math/libMath.la \
|
||||
|
||||
INCLUDES += \
|
||||
-DGLUT \
|
||||
-I$(top_builddir) \
|
||||
|
|
|
@ -73,7 +73,7 @@ VERSION = @VERSION@
|
|||
|
||||
EXTRA_DIST = runfg.in runfg.bat.in
|
||||
|
||||
bin_PROGRAMS = fg
|
||||
bin_PROGRAMS = fg ttest
|
||||
|
||||
bin_SCRIPTS = runfg runfg.bat
|
||||
|
||||
|
@ -103,6 +103,8 @@ fg_LDADD = \
|
|||
$(top_builddir)/Lib/Bucket/libBucket.la \
|
||||
$(top_builddir)/Lib/Debug/libDebug.la \
|
||||
$(top_builddir)/Lib/zlib/libz.la
|
||||
|
||||
ttest_SOURCES = ttest.cxx
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = ../../Include/config.h
|
||||
CONFIG_CLEAN_FILES = runfg runfg.bat
|
||||
|
@ -135,6 +137,10 @@ $(top_builddir)/Lib/Math/libMath.la \
|
|||
$(top_builddir)/Lib/Bucket/libBucket.la \
|
||||
$(top_builddir)/Lib/Debug/libDebug.la $(top_builddir)/Lib/zlib/libz.la
|
||||
fg_LDFLAGS =
|
||||
ttest_OBJECTS = ttest.o
|
||||
ttest_LDADD = $(LDADD)
|
||||
ttest_DEPENDENCIES =
|
||||
ttest_LDFLAGS =
|
||||
SCRIPTS = $(bin_SCRIPTS)
|
||||
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
|
@ -149,10 +155,10 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
|
|||
TAR = tar
|
||||
GZIP = --best
|
||||
DEP_FILES = .deps/GLUTkey.P .deps/GLUTmain.P .deps/airports.P \
|
||||
.deps/fg_init.P .deps/options.P .deps/views.P
|
||||
.deps/fg_init.P .deps/options.P .deps/ttest.P .deps/views.P
|
||||
CXXMKDEP = $(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)
|
||||
SOURCES = $(fg_SOURCES)
|
||||
OBJECTS = $(fg_OBJECTS)
|
||||
SOURCES = $(fg_SOURCES) $(ttest_SOURCES)
|
||||
OBJECTS = $(fg_OBJECTS) $(ttest_OBJECTS)
|
||||
|
||||
all: Makefile $(PROGRAMS) $(SCRIPTS)
|
||||
|
||||
|
@ -231,6 +237,10 @@ fg: $(fg_OBJECTS) $(fg_DEPENDENCIES)
|
|||
@rm -f fg
|
||||
$(CXXLINK) $(fg_LDFLAGS) $(fg_OBJECTS) $(fg_LDADD) $(LIBS)
|
||||
|
||||
ttest: $(ttest_OBJECTS) $(ttest_DEPENDENCIES)
|
||||
@rm -f ttest
|
||||
$(CXXLINK) $(ttest_LDFLAGS) $(ttest_OBJECTS) $(ttest_LDADD) $(LIBS)
|
||||
|
||||
install-binSCRIPTS: $(bin_SCRIPTS)
|
||||
@$(NORMAL_INSTALL)
|
||||
$(mkinstalldirs) $(DESTDIR)$(bindir)
|
||||
|
|
|
@ -133,8 +133,8 @@ int fgInitPosition( void ) {
|
|||
// Test Position
|
||||
// FG_Longitude = ( 8.5 ) * DEG_TO_RAD;
|
||||
// FG_Latitude = ( 47.5 ) * DEG_TO_RAD;
|
||||
// FG_Runway_altitude = ( 6000 );
|
||||
// FG_Altitude = FG_Runway_altitude + 3.758099;
|
||||
FG_Runway_altitude = ( 6000 );
|
||||
FG_Altitude = FG_Runway_altitude + 3.758099;
|
||||
|
||||
if ( strlen(o->airport_id) ) {
|
||||
fgAIRPORTS airports;
|
||||
|
@ -271,9 +271,9 @@ int fgInitSubsystems( void ) {
|
|||
fgTimeUpdate(f, t);
|
||||
|
||||
// Initialize view parameters
|
||||
// ---->
|
||||
fgViewInit(v);
|
||||
fgViewUpdate(f, v, l);
|
||||
v->Init();
|
||||
v->Update(f);
|
||||
v->UpdateWorldToEye(f);
|
||||
|
||||
// Initialize the orbital elements of sun, moon and mayor planets
|
||||
fgSolarSystemInit(*t);
|
||||
|
@ -297,11 +297,9 @@ int fgInitSubsystems( void ) {
|
|||
// fgUpdateSunPos() needs a few position and view parameters set
|
||||
// so it can calculate local relative sun angle and a few other
|
||||
// things for correctly orienting the sky.
|
||||
// ---->
|
||||
fgUpdateSunPos();
|
||||
|
||||
// Initialize Lighting interpolation tables
|
||||
// ---->
|
||||
fgLightInit();
|
||||
|
||||
// update the lighting parameters (based on sun angle)
|
||||
|
@ -323,7 +321,6 @@ int fgInitSubsystems( void ) {
|
|||
}
|
||||
|
||||
// Initialize the "sky"
|
||||
// ---->
|
||||
fgSkyInit();
|
||||
|
||||
// Initialize the Scenery Management subsystem
|
||||
|
@ -384,6 +381,14 @@ int fgInitSubsystems( void ) {
|
|||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.13 1998/05/16 13:08:35 curt
|
||||
// C++ - ified views.[ch]xx
|
||||
// Shuffled some additional view parameters into the fgVIEW class.
|
||||
// Changed tile-radius to tile-diameter because it is a much better
|
||||
// name.
|
||||
// Added a WORLD_TO_EYE transformation to views.cxx. This allows us
|
||||
// to transform world space to eye space for view frustum culling.
|
||||
//
|
||||
// Revision 1.12 1998/05/13 18:29:58 curt
|
||||
// Added a keyboard binding to dynamically adjust field of view.
|
||||
// Added a command line option to specify fov.
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include <Debug/fg_debug.h>
|
||||
#include <Include/fg_constants.h>
|
||||
#include <Include/fg_zlib.h>
|
||||
|
||||
#include "options.hxx"
|
||||
|
@ -79,7 +80,7 @@ fgOPTIONS::fgOPTIONS( void ) {
|
|||
wireframe = 0;
|
||||
|
||||
// Scenery options
|
||||
tile_radius = 7;
|
||||
tile_diameter = 7;
|
||||
|
||||
// Time options
|
||||
time_offset = 0;
|
||||
|
@ -229,22 +230,16 @@ static int parse_time_offset(char *time_str) {
|
|||
}
|
||||
|
||||
|
||||
// Parse --tile-radius=n type option
|
||||
// Parse --tile-diameter=n type option
|
||||
|
||||
#define FG_RADIUS_MIN 3
|
||||
#define FG_RADIUS_MAX 9
|
||||
#define FG_RADIUS_MIN 1
|
||||
#define FG_RADIUS_MAX 4
|
||||
|
||||
static int parse_tile_radius(char *arg) {
|
||||
int radius, tmp;
|
||||
|
||||
radius = parse_int(arg);
|
||||
|
||||
// radius must be odd
|
||||
tmp = radius / 2;
|
||||
if ( radius == ( tmp * 2 ) ) {
|
||||
radius -= 1;
|
||||
}
|
||||
|
||||
if ( radius < FG_RADIUS_MIN ) { radius = FG_RADIUS_MIN; }
|
||||
if ( radius > FG_RADIUS_MAX ) { radius = FG_RADIUS_MAX; }
|
||||
|
||||
|
@ -255,10 +250,6 @@ static int parse_tile_radius(char *arg) {
|
|||
|
||||
|
||||
// Parse --fov=x.xx type option
|
||||
|
||||
#define FG_FOV_MIN 0.1
|
||||
#define FG_FOV_MAX 179.9
|
||||
|
||||
static double parse_fov(char *arg) {
|
||||
double fov;
|
||||
|
||||
|
@ -318,6 +309,7 @@ int fgOPTIONS::parse_option( char *arg ) {
|
|||
wireframe = 1;
|
||||
} else if ( strncmp(arg, "--tile-radius=", 14) == 0 ) {
|
||||
tile_radius = parse_tile_radius(arg);
|
||||
tile_diameter = tile_radius * 2 + 1;
|
||||
} else if ( strncmp(arg, "--time-offset=", 14) == 0 ) {
|
||||
time_offset = parse_time_offset(arg);
|
||||
} else {
|
||||
|
@ -424,7 +416,7 @@ void fgOPTIONS::usage ( void ) {
|
|||
printf("\n");
|
||||
|
||||
printf("Scenery Options:\n");
|
||||
printf("\t--tile-radius=n: specify tile radius, must be odd 3, 5, or 7\n");
|
||||
printf("\t--tile-radius=n: specify tile radius, must be 1 - 4\n");
|
||||
printf("\n");
|
||||
|
||||
printf("Time Options:\n");
|
||||
|
@ -438,6 +430,14 @@ fgOPTIONS::~fgOPTIONS( void ) {
|
|||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.10 1998/05/16 13:08:36 curt
|
||||
// C++ - ified views.[ch]xx
|
||||
// Shuffled some additional view parameters into the fgVIEW class.
|
||||
// Changed tile-radius to tile-diameter because it is a much better
|
||||
// name.
|
||||
// Added a WORLD_TO_EYE transformation to views.cxx. This allows us
|
||||
// to transform world space to eye space for view frustum culling.
|
||||
//
|
||||
// Revision 1.9 1998/05/13 18:29:59 curt
|
||||
// Added a keyboard binding to dynamically adjust field of view.
|
||||
// Added a command line option to specify fov.
|
||||
|
|
|
@ -59,8 +59,10 @@ public:
|
|||
int wireframe; // Wireframe mode enabled/disabled
|
||||
|
||||
// Scenery options
|
||||
int tile_radius; // Square radius of rendered tiles. for instance
|
||||
// if tile_radius = 3 then a 3 x 3 grid of tiles will
|
||||
int tile_radius; // Square radius of rendered tiles (around center
|
||||
// square.)
|
||||
int tile_diameter; // Diameter of rendered tiles. for instance
|
||||
// if tile_diameter = 3 then a 3 x 3 grid of tiles will
|
||||
// be drawn. Increase this to see terrain that is
|
||||
// further away.
|
||||
|
||||
|
@ -95,6 +97,14 @@ extern fgOPTIONS current_options;
|
|||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.8 1998/05/16 13:08:36 curt
|
||||
// C++ - ified views.[ch]xx
|
||||
// Shuffled some additional view parameters into the fgVIEW class.
|
||||
// Changed tile-radius to tile-diameter because it is a much better
|
||||
// name.
|
||||
// Added a WORLD_TO_EYE transformation to views.cxx. This allows us
|
||||
// to transform world space to eye space for view frustum culling.
|
||||
//
|
||||
// Revision 1.7 1998/05/13 18:29:59 curt
|
||||
// Added a keyboard binding to dynamically adjust field of view.
|
||||
// Added a command line option to specify fov.
|
||||
|
|
182
Main/views.cxx
182
Main/views.cxx
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// views.cxx -- data structures and routines for managing and view parameters.
|
||||
// views.cxx -- data structures and routines for managing and view
|
||||
// parameters.
|
||||
//
|
||||
// Written by Curtis Olson, started August 1997.
|
||||
//
|
||||
|
@ -23,7 +23,6 @@
|
|||
// (Log is kept at end of this file)
|
||||
|
||||
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
@ -37,6 +36,7 @@
|
|||
#include <Scenery/scenery.hxx>
|
||||
#include <Time/fg_time.hxx>
|
||||
|
||||
#include "options.hxx"
|
||||
#include "views.hxx"
|
||||
|
||||
|
||||
|
@ -44,51 +44,77 @@
|
|||
fgVIEW current_view;
|
||||
|
||||
|
||||
// Constructor
|
||||
fgVIEW::fgVIEW( void ) {
|
||||
}
|
||||
|
||||
|
||||
// Initialize a view structure
|
||||
void fgViewInit(fgVIEW *v) {
|
||||
void fgVIEW::Init( void ) {
|
||||
fgPrintf( FG_VIEW, FG_INFO, "Initializing View parameters\n");
|
||||
|
||||
v->view_offset = 0.0;
|
||||
v->goal_view_offset = 0.0;
|
||||
view_offset = 0.0;
|
||||
goal_view_offset = 0.0;
|
||||
}
|
||||
|
||||
|
||||
// Update the view parameters
|
||||
void fgViewUpdate(fgFLIGHT *f, fgVIEW *v, fgLIGHT *l) {
|
||||
void fgVIEW::Update( fgFLIGHT *f ) {
|
||||
fgOPTIONS *o;
|
||||
fgPolarPoint3d p;
|
||||
MAT3vec vec, forward, v0, minus_z;
|
||||
MAT3mat R, TMP, UP, LOCAL, VIEW;
|
||||
double ntmp;
|
||||
double theta_x, theta_y, ntmp;
|
||||
|
||||
o = ¤t_options;
|
||||
|
||||
scenery.center.x = scenery.next_center.x;
|
||||
scenery.center.y = scenery.next_center.y;
|
||||
scenery.center.z = scenery.next_center.z;
|
||||
|
||||
printf("win_ratio = %.2f\n", win_ratio);
|
||||
|
||||
// calculate sin() and cos() of fov / 2 in X direction;
|
||||
theta_x = FG_PI_2 - (o->fov * win_ratio * DEG_TO_RAD) / 2.0;
|
||||
printf("theta_x = %.2f\n", theta_x);
|
||||
sin_fov_x = sin(theta_x);
|
||||
cos_fov_x = cos(theta_x);
|
||||
slope_x = sin_fov_x / cos_fov_x;
|
||||
printf("slope_x = %.2f\n", slope_x);
|
||||
|
||||
// calculate sin() and cos() of fov / 2 in Y direction;
|
||||
theta_y = FG_PI_2 - (o->fov * DEG_TO_RAD) / 2.0;
|
||||
printf("theta_y = %.2f\n", theta_y);
|
||||
sin_fov_y = sin(theta_y);
|
||||
cos_fov_y = cos(theta_y);
|
||||
slope_y = sin_fov_y / cos_fov_y;
|
||||
printf("slope_y = %.2f\n", slope_y);
|
||||
|
||||
// calculate the cartesion coords of the current lat/lon/0 elev
|
||||
p.lon = FG_Longitude;
|
||||
p.lat = FG_Lat_geocentric;
|
||||
p.radius = FG_Sea_level_radius * FEET_TO_METER;
|
||||
|
||||
v->cur_zero_elev = fgPolarToCart3d(p);
|
||||
cur_zero_elev = fgPolarToCart3d(p);
|
||||
|
||||
v->cur_zero_elev.x -= scenery.center.x;
|
||||
v->cur_zero_elev.y -= scenery.center.y;
|
||||
v->cur_zero_elev.z -= scenery.center.z;
|
||||
cur_zero_elev.x -= scenery.center.x;
|
||||
cur_zero_elev.y -= scenery.center.y;
|
||||
cur_zero_elev.z -= scenery.center.z;
|
||||
|
||||
// calculate view position in current FG view coordinate system
|
||||
// p.lon & p.lat are already defined earlier
|
||||
p.radius = FG_Radius_to_vehicle * FEET_TO_METER + 1.0;
|
||||
|
||||
v->abs_view_pos = fgPolarToCart3d(p);
|
||||
abs_view_pos = fgPolarToCart3d(p);
|
||||
|
||||
v->view_pos.x = v->abs_view_pos.x - scenery.center.x;
|
||||
v->view_pos.y = v->abs_view_pos.y - scenery.center.y;
|
||||
v->view_pos.z = v->abs_view_pos.z - scenery.center.z;
|
||||
view_pos.x = abs_view_pos.x - scenery.center.x;
|
||||
view_pos.y = abs_view_pos.y - scenery.center.y;
|
||||
view_pos.z = abs_view_pos.z - scenery.center.z;
|
||||
|
||||
fgPrintf( FG_VIEW, FG_DEBUG, "Absolute view pos = %.4f, %.4f, %.4f\n",
|
||||
v->abs_view_pos.x, v->abs_view_pos.y, v->abs_view_pos.z);
|
||||
abs_view_pos.x, abs_view_pos.y, abs_view_pos.z);
|
||||
fgPrintf( FG_VIEW, FG_DEBUG, "Relative view pos = %.4f, %.4f, %.4f\n",
|
||||
v->view_pos.x, v->view_pos.y, v->view_pos.z);
|
||||
view_pos.x, view_pos.y, view_pos.z);
|
||||
|
||||
// Derive the LOCAL aircraft rotation matrix (roll, pitch, yaw)
|
||||
// from FG_T_local_to_body[3][3]
|
||||
|
@ -156,11 +182,11 @@ void fgViewUpdate(fgFLIGHT *f, fgVIEW *v, fgLIGHT *l) {
|
|||
// printf("Local up matrix\n");
|
||||
// MAT3print(UP, stdout);
|
||||
|
||||
MAT3_SET_VEC(v->local_up, 1.0, 0.0, 0.0);
|
||||
MAT3mult_vec(v->local_up, v->local_up, UP);
|
||||
MAT3_SET_VEC(local_up, 1.0, 0.0, 0.0);
|
||||
MAT3mult_vec(local_up, local_up, UP);
|
||||
|
||||
// printf( "Local Up = (%.4f, %.4f, %.4f)\n",
|
||||
// v->local_up[0], v->local_up[1], v->local_up[2]);
|
||||
// local_up[0], local_up[1], local_up[2]);
|
||||
|
||||
// Alternative method to Derive local up vector based on
|
||||
// *geodetic* coordinates
|
||||
|
@ -175,39 +201,131 @@ void fgViewUpdate(fgFLIGHT *f, fgVIEW *v, fgLIGHT *l) {
|
|||
|
||||
// generate the current up, forward, and fwrd-view vectors
|
||||
MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
|
||||
MAT3mult_vec(v->view_up, vec, VIEW);
|
||||
MAT3mult_vec(view_up, vec, VIEW);
|
||||
|
||||
MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
|
||||
MAT3mult_vec(forward, vec, VIEW);
|
||||
// printf( "Forward vector is (%.2f,%.2f,%.2f)\n", forward[0], forward[1],
|
||||
// forward[2]);
|
||||
|
||||
MAT3rotate(TMP, v->view_up, v->view_offset);
|
||||
MAT3mult_vec(v->view_forward, forward, TMP);
|
||||
MAT3rotate(TMP, view_up, view_offset);
|
||||
MAT3mult_vec(view_forward, forward, TMP);
|
||||
|
||||
// make a vector to the current view position
|
||||
MAT3_SET_VEC(v0, v->view_pos.x, v->view_pos.y, v->view_pos.z);
|
||||
MAT3_SET_VEC(v0, view_pos.x, view_pos.y, view_pos.z);
|
||||
|
||||
// Given a vector pointing straight down (-Z), map into onto the
|
||||
// local plane representing "horizontal". This should give us the
|
||||
// local direction for moving "south".
|
||||
MAT3_SET_VEC(minus_z, 0.0, 0.0, -1.0);
|
||||
map_vec_onto_cur_surface_plane(v->local_up, v0, minus_z, v->surface_south);
|
||||
MAT3_NORMALIZE_VEC(v->surface_south, ntmp);
|
||||
map_vec_onto_cur_surface_plane(local_up, v0, minus_z, surface_south);
|
||||
MAT3_NORMALIZE_VEC(surface_south, ntmp);
|
||||
// printf( "Surface direction directly south %.2f %.2f %.2f\n",
|
||||
// v->surface_south[0], v->surface_south[1], v->surface_south[2]);
|
||||
// surface_south[0], surface_south[1], surface_south[2]);
|
||||
|
||||
// now calculate the surface east vector
|
||||
MAT3rotate(TMP, v->view_up, FG_PI_2);
|
||||
MAT3mult_vec(v->surface_east, v->surface_south, TMP);
|
||||
MAT3rotate(TMP, view_up, FG_PI_2);
|
||||
MAT3mult_vec(surface_east, surface_south, TMP);
|
||||
// printf( "Surface direction directly east %.2f %.2f %.2f\n",
|
||||
// v->surface_east[0], v->surface_east[1], v->surface_east[2]);
|
||||
// surface_east[0], surface_east[1], surface_east[2]);
|
||||
// printf( "Should be close to zero = %.2f\n",
|
||||
// MAT3_DOT_PRODUCT(v->surface_south, v->surface_east));
|
||||
// MAT3_DOT_PRODUCT(surface_south, surface_east));
|
||||
}
|
||||
|
||||
|
||||
// Update the "World to Eye" transformation matrix
|
||||
// This is most useful for view frustum culling
|
||||
void fgVIEW::UpdateWorldToEye( fgFLIGHT *f ) {
|
||||
MAT3mat R_Phi, R_Theta, R_Psi, R_Lat, R_Lon, T_view;
|
||||
MAT3mat TMP;
|
||||
MAT3hvec vec;
|
||||
|
||||
// Roll Matrix
|
||||
MAT3_SET_HVEC(vec, 0.0, 0.0, -1.0, 1.0);
|
||||
MAT3rotate(R_Phi, vec, FG_Phi);
|
||||
// printf("Roll matrix (Phi)\n");
|
||||
// MAT3print(R_Phi, stdout);
|
||||
|
||||
// Pitch Matrix
|
||||
MAT3_SET_HVEC(vec, 1.0, 0.0, 0.0, 1.0);
|
||||
MAT3rotate(R_Theta, vec, FG_Theta);
|
||||
// printf("\nPitch matrix (Theta)\n");
|
||||
// MAT3print(R_Theta, stdout);
|
||||
|
||||
// Yaw Matrix
|
||||
MAT3_SET_HVEC(vec, 0.0, -1.0, 0.0, 1.0);
|
||||
MAT3rotate(R_Psi, vec, FG_Psi + FG_PI - view_offset );
|
||||
// printf("\nYaw matrix (Psi)\n");
|
||||
// MAT3print(R_Psi, stdout);
|
||||
|
||||
// Latitude
|
||||
MAT3_SET_HVEC(vec, 1.0, 0.0, 0.0, 1.0);
|
||||
// R_Lat = rotate about X axis
|
||||
MAT3rotate(R_Lat, vec, FG_Latitude);
|
||||
// printf("\nLatitude matrix\n");
|
||||
// MAT3print(R_Lat, stdout);
|
||||
|
||||
// Longitude
|
||||
MAT3_SET_HVEC(vec, 0.0, 0.0, 1.0, 1.0);
|
||||
// R_Lon = rotate about Z axis
|
||||
MAT3rotate(R_Lon, vec, FG_Longitude - FG_PI_2 );
|
||||
// printf("\nLongitude matrix\n");
|
||||
// MAT3print(R_Lon, stdout);
|
||||
|
||||
// View position in scenery centered coordinates
|
||||
MAT3_SET_HVEC(vec, view_pos.x, view_pos.y, view_pos.z, 1.0);
|
||||
MAT3translate(T_view, vec);
|
||||
// printf("\nTranslation matrix\n");
|
||||
// MAT3print(T_view, stdout);
|
||||
|
||||
// aircraft roll/pitch/yaw
|
||||
MAT3mult(TMP, R_Phi, R_Theta);
|
||||
MAT3mult(AIRCRAFT, TMP, R_Psi);
|
||||
// printf("\naircraft roll pitch yaw\n");
|
||||
// MAT3print(AIRCRAFT, stdout);
|
||||
|
||||
// lon/lat
|
||||
MAT3mult(WORLD, R_Lat, R_Lon);
|
||||
// printf("\nworld\n");
|
||||
// MAT3print(WORLD, stdout);
|
||||
|
||||
MAT3mult(EYE_TO_WORLD, AIRCRAFT, WORLD);
|
||||
MAT3mult(EYE_TO_WORLD, EYE_TO_WORLD, T_view);
|
||||
// printf("\nEye to world\n");
|
||||
// MAT3print(EYE_TO_WORLD, stdout);
|
||||
|
||||
MAT3invert(WORLD_TO_EYE, EYE_TO_WORLD);
|
||||
// printf("\nWorld to eye\n");
|
||||
// MAT3print(WORLD_TO_EYE, stdout);
|
||||
|
||||
// printf( "\nview_pos = %.2f %.2f %.2f\n",
|
||||
// view_pos.x, view_pos.y, view_pos.z );
|
||||
|
||||
// MAT3_SET_HVEC(eye, 0.0, 0.0, 0.0, 1.0);
|
||||
// MAT3mult_vec(vec, eye, EYE_TO_WORLD);
|
||||
// printf("\neye -> world = %.2f %.2f %.2f\n", vec[0], vec[1], vec[2]);
|
||||
|
||||
// MAT3_SET_HVEC(vec1, view_pos.x, view_pos.y, view_pos.z, 1.0);
|
||||
// MAT3mult_vec(vec, vec1, WORLD_TO_EYE);
|
||||
// printf( "\nabs_view_pos -> eye = %.2f %.2f %.2f\n",
|
||||
// vec[0], vec[1], vec[2]);
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
fgVIEW::~fgVIEW( void ) {
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.9 1998/05/16 13:08:37 curt
|
||||
// C++ - ified views.[ch]xx
|
||||
// Shuffled some additional view parameters into the fgVIEW class.
|
||||
// Changed tile-radius to tile-diameter because it is a much better
|
||||
// name.
|
||||
// Added a WORLD_TO_EYE transformation to views.cxx. This allows us
|
||||
// to transform world space to eye space for view frustum culling.
|
||||
//
|
||||
// Revision 1.8 1998/05/02 01:51:01 curt
|
||||
// Updated polartocart conversion routine.
|
||||
//
|
||||
|
|
307
Main/views.hxx
307
Main/views.hxx
|
@ -1,27 +1,26 @@
|
|||
/**************************************************************************
|
||||
* views.hxx -- data structures and routines for managing and view parameters.
|
||||
*
|
||||
* Written by Curtis Olson, started August 1997.
|
||||
*
|
||||
* Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
||||
*
|
||||
* 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$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
//
|
||||
// views.hxx -- data structures and routines for managing and view parameters.
|
||||
//
|
||||
// Written by Curtis Olson, started August 1997.
|
||||
//
|
||||
// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
|
||||
//
|
||||
// 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$
|
||||
// (Log is kept at end of this file)
|
||||
|
||||
|
||||
#ifndef _VIEWS_HXX
|
||||
|
@ -40,119 +39,171 @@
|
|||
#include <Time/light.hxx>
|
||||
|
||||
|
||||
/* Define a structure containing view information */
|
||||
typedef struct {
|
||||
/* absolute view position */
|
||||
fgCartesianPoint3d abs_view_pos;
|
||||
// Define a structure containing view information
|
||||
class fgVIEW {
|
||||
|
||||
/* view position translated to scenery.center */
|
||||
fgCartesianPoint3d view_pos;
|
||||
public:
|
||||
|
||||
/* cartesion coordinates of current lon/lat if at sea level
|
||||
* translated to scenery.center*/
|
||||
fgCartesianPoint3d cur_zero_elev;
|
||||
|
||||
/* vector in cartesian coordinates from current position to the
|
||||
* postion on the earth's surface the sun is directly over */
|
||||
MAT3vec to_sun;
|
||||
|
||||
/* surface direction to go to head towards sun */
|
||||
MAT3vec surface_to_sun;
|
||||
|
||||
/* surface vector heading south */
|
||||
MAT3vec surface_south;
|
||||
|
||||
/* surface vector heading east (used to unambiguously align sky with sun) */
|
||||
MAT3vec surface_east;
|
||||
|
||||
/* local up vector (normal to the plane tangent to the earth's
|
||||
* surface at the spot we are directly above */
|
||||
MAT3vec local_up;
|
||||
|
||||
/* up vector for the view (usually point straight up through the
|
||||
* top of the aircraft */
|
||||
MAT3vec view_up;
|
||||
|
||||
/* the vector pointing straight out the nose of the aircraft */
|
||||
MAT3vec view_forward;
|
||||
|
||||
/* the current offset from forward for viewing */
|
||||
// the current offset from forward for viewing
|
||||
double view_offset;
|
||||
|
||||
/* the goal view offset for viewing (used for smooth view changes) */
|
||||
// the goal view offset for viewing (used for smooth view changes)
|
||||
double goal_view_offset;
|
||||
} fgVIEW;
|
||||
|
||||
// fov of view is specified in the y direction, win_ratio is used to
|
||||
// calculate the fov in the X direction = width/height
|
||||
double win_ratio;
|
||||
|
||||
// width & height of window
|
||||
int winWidth, winHeight;
|
||||
|
||||
// sin and cos of (fov / 2) in Y axis
|
||||
double sin_fov_y, cos_fov_y;
|
||||
|
||||
// slope of view frustum edge in eye space Y axis
|
||||
double slope_y;
|
||||
|
||||
// sin and cos of (fov / 2) in X axis
|
||||
double sin_fov_x, cos_fov_x;
|
||||
|
||||
// slope of view frustum edge in eye space X axis
|
||||
double slope_x;
|
||||
|
||||
// absolute view position
|
||||
fgCartesianPoint3d abs_view_pos;
|
||||
|
||||
// view position translated to scenery.center
|
||||
fgCartesianPoint3d view_pos;
|
||||
|
||||
// cartesion coordinates of current lon/lat if at sea level
|
||||
// translated to scenery.center*/
|
||||
fgCartesianPoint3d cur_zero_elev;
|
||||
|
||||
// vector in cartesian coordinates from current position to the
|
||||
// postion on the earth's surface the sun is directly over
|
||||
MAT3vec to_sun;
|
||||
|
||||
// surface direction to go to head towards sun
|
||||
MAT3vec surface_to_sun;
|
||||
|
||||
// surface vector heading south
|
||||
MAT3vec surface_south;
|
||||
|
||||
// surface vector heading east (used to unambiguously align sky
|
||||
// with sun)
|
||||
MAT3vec surface_east;
|
||||
|
||||
// local up vector (normal to the plane tangent to the earth's
|
||||
// surface at the spot we are directly above
|
||||
MAT3vec local_up;
|
||||
|
||||
// up vector for the view (usually point straight up through the
|
||||
// top of the aircraft
|
||||
MAT3vec view_up;
|
||||
|
||||
// the vector pointing straight out the nose of the aircraft
|
||||
MAT3vec view_forward;
|
||||
|
||||
// Transformation matrix for eye coordinates to aircraft coordinates
|
||||
MAT3mat AIRCRAFT;
|
||||
|
||||
// Transformation matrix for aircraft coordinates to world
|
||||
// coordinates
|
||||
MAT3mat WORLD;
|
||||
|
||||
// Combined transformation from eye coordinates to world coordinates
|
||||
MAT3mat EYE_TO_WORLD;
|
||||
|
||||
// Inverse of EYE_TO_WORLD which is a transformation from world
|
||||
// coordinates to eye coordinates
|
||||
MAT3mat WORLD_TO_EYE;
|
||||
|
||||
// Constructor
|
||||
fgVIEW( void );
|
||||
|
||||
// Initialize a view class
|
||||
void Init( void );
|
||||
|
||||
// Update the view parameters
|
||||
void Update( fgFLIGHT *f );
|
||||
|
||||
// Update the "World to Eye" transformation matrix
|
||||
void UpdateWorldToEye( fgFLIGHT *f );
|
||||
|
||||
// Destructor
|
||||
~fgVIEW( void );
|
||||
};
|
||||
|
||||
|
||||
extern fgVIEW current_view;
|
||||
|
||||
|
||||
/* Initialize a view structure */
|
||||
void fgViewInit(fgVIEW *v);
|
||||
|
||||
/* Update the view parameters */
|
||||
void fgViewUpdate(fgFLIGHT *f, fgVIEW *v, fgLIGHT *l);
|
||||
#endif // _VIEWS_HXX
|
||||
|
||||
|
||||
#endif /* _VIEWS_HXX */
|
||||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.5 1998/05/02 01:51:02 curt
|
||||
/* Updated polartocart conversion routine.
|
||||
/*
|
||||
* Revision 1.4 1998/04/28 01:20:24 curt
|
||||
* Type-ified fgTIME and fgVIEW.
|
||||
* Added a command line option to disable textures.
|
||||
*
|
||||
* Revision 1.3 1998/04/25 22:06:31 curt
|
||||
* Edited cvs log messages in source files ... bad bad bad!
|
||||
*
|
||||
* Revision 1.2 1998/04/24 00:49:22 curt
|
||||
* Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
|
||||
* Trying out some different option parsing code.
|
||||
* Some code reorganization.
|
||||
*
|
||||
* Revision 1.1 1998/04/22 13:25:46 curt
|
||||
* C++ - ifing the code.
|
||||
* Starting a bit of reorganization of lighting code.
|
||||
*
|
||||
* Revision 1.11 1998/04/21 17:02:42 curt
|
||||
* Prepairing for C++ integration.
|
||||
*
|
||||
* Revision 1.10 1998/02/07 15:29:45 curt
|
||||
* Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
|
||||
* <chotchkiss@namg.us.anritsu.com>
|
||||
*
|
||||
* Revision 1.9 1998/01/29 00:50:29 curt
|
||||
* Added a view record field for absolute x, y, z position.
|
||||
*
|
||||
* Revision 1.8 1998/01/27 00:47:58 curt
|
||||
* Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
|
||||
* system and commandline/config file processing code.
|
||||
*
|
||||
* Revision 1.7 1998/01/22 02:59:38 curt
|
||||
* Changed #ifdef FILE_H to #ifdef _FILE_H
|
||||
*
|
||||
* Revision 1.6 1998/01/19 19:27:10 curt
|
||||
* Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
||||
* This should simplify things tremendously.
|
||||
*
|
||||
* Revision 1.5 1997/12/22 04:14:32 curt
|
||||
* Aligned sky with sun so dusk/dawn effects can be correct relative to the sun.
|
||||
*
|
||||
* Revision 1.4 1997/12/17 23:13:36 curt
|
||||
* Began working on rendering a sky.
|
||||
*
|
||||
* Revision 1.3 1997/12/15 23:54:51 curt
|
||||
* Add xgl wrappers for debugging.
|
||||
* Generate terrain normals on the fly.
|
||||
*
|
||||
* Revision 1.2 1997/12/10 22:37:48 curt
|
||||
* Prepended "fg" on the name of all global structures that didn't have it yet.
|
||||
* i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
|
||||
*
|
||||
* Revision 1.1 1997/08/27 21:31:18 curt
|
||||
* Initial revision.
|
||||
*
|
||||
*/
|
||||
// $Log$
|
||||
// Revision 1.6 1998/05/16 13:08:37 curt
|
||||
// C++ - ified views.[ch]xx
|
||||
// Shuffled some additional view parameters into the fgVIEW class.
|
||||
// Changed tile-radius to tile-diameter because it is a much better
|
||||
// name.
|
||||
// Added a WORLD_TO_EYE transformation to views.cxx. This allows us
|
||||
// to transform world space to eye space for view frustum culling.
|
||||
//
|
||||
// Revision 1.5 1998/05/02 01:51:02 curt
|
||||
// Updated polartocart conversion routine.
|
||||
//
|
||||
// Revision 1.4 1998/04/28 01:20:24 curt
|
||||
// Type-ified fgTIME and fgVIEW.
|
||||
// Added a command line option to disable textures.
|
||||
//
|
||||
// Revision 1.3 1998/04/25 22:06:31 curt
|
||||
// Edited cvs log messages in source files ... bad bad bad!
|
||||
//
|
||||
// Revision 1.2 1998/04/24 00:49:22 curt
|
||||
// Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
|
||||
// Trying out some different option parsing code.
|
||||
// Some code reorganization.
|
||||
//
|
||||
// Revision 1.1 1998/04/22 13:25:46 curt
|
||||
// C++ - ifing the code.
|
||||
// Starting a bit of reorganization of lighting code.
|
||||
//
|
||||
// Revision 1.11 1998/04/21 17:02:42 curt
|
||||
// Prepairing for C++ integration.
|
||||
//
|
||||
// Revision 1.10 1998/02/07 15:29:45 curt
|
||||
// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
|
||||
// <chotchkiss@namg.us.anritsu.com>
|
||||
//
|
||||
// Revision 1.9 1998/01/29 00:50:29 curt
|
||||
// Added a view record field for absolute x, y, z position.
|
||||
//
|
||||
// Revision 1.8 1998/01/27 00:47:58 curt
|
||||
// Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
|
||||
// system and commandline/config file processing code.
|
||||
//
|
||||
// Revision 1.7 1998/01/22 02:59:38 curt
|
||||
// Changed #ifdef FILE_H to #ifdef _FILE_H
|
||||
//
|
||||
// Revision 1.6 1998/01/19 19:27:10 curt
|
||||
// Merged in make system changes from Bob Kuehne <rpk@sgi.com>
|
||||
// This should simplify things tremendously.
|
||||
//
|
||||
// Revision 1.5 1997/12/22 04:14:32 curt
|
||||
// Aligned sky with sun so dusk/dawn effects can be correct relative to the sun.
|
||||
//
|
||||
// Revision 1.4 1997/12/17 23:13:36 curt
|
||||
// Began working on rendering a sky.
|
||||
//
|
||||
// Revision 1.3 1997/12/15 23:54:51 curt
|
||||
// Add xgl wrappers for debugging.
|
||||
// Generate terrain normals on the fly.
|
||||
//
|
||||
// Revision 1.2 1997/12/10 22:37:48 curt
|
||||
// Prepended "fg" on the name of all global structures that didn't have it yet.
|
||||
// i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
|
||||
//
|
||||
// Revision 1.1 1997/08/27 21:31:18 curt
|
||||
// Initial revision.
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue