1
0
Fork 0

Norman's changes to make the current scenery normal available.

This commit is contained in:
curt 2000-08-09 21:35:17 +00:00
parent 5103729ca0
commit 0537a0ac84
4 changed files with 111 additions and 41 deletions

View file

@ -55,6 +55,36 @@ FGView current_view;
FGView::FGView( void ) {
}
#define USE_FAST_VIEWROT
#ifdef USE_FAST_VIEWROT
// VIEW_ROT = LARC_TO_SSG * ( VIEWo * VIEW_OFFSET )
// This takes advantage of the fact that VIEWo and VIEW_OFFSET
// only have entries in the upper 3x3 block
// and that LARC_TO_SSG is just a shift of rows NHV
inline static void fgMakeViewRot( sgMat4 dst, const sgMat4 m1, const sgMat4 m2 )
{
for ( int j = 0 ; j < 3 ; j++ ) {
dst[2][j] = m2[0][0] * m1[0][j] +
m2[0][1] * m1[1][j] +
m2[0][2] * m1[2][j];
dst[0][j] = m2[1][0] * m1[0][j] +
m2[1][1] * m1[1][j] +
m2[1][2] * m1[2][j];
dst[1][j] = m2[2][0] * m1[0][j] +
m2[2][1] * m1[1][j] +
m2[2][2] * m1[2][j];
}
dst[0][3] =
dst[1][3] =
dst[2][3] =
dst[3][0] =
dst[3][1] =
dst[3][2] = SG_ZERO;
dst[3][3] = SG_ONE;
}
#endif
// Initialize a view structure
void FGView::Init( void ) {
@ -73,6 +103,7 @@ void FGView::Init( void ) {
set_win_ratio( (winHeight*0.4232) / winWidth );
}
#ifndef USE_FAST_VIEWROT
// This never changes -- NHV
LARC_TO_SSG[0][0] = 0.0;
LARC_TO_SSG[0][1] = 1.0;
@ -93,7 +124,8 @@ void FGView::Init( void ) {
LARC_TO_SSG[3][1] = 0.0;
LARC_TO_SSG[3][2] = 0.0;
LARC_TO_SSG[3][3] = 1.0;
#endif // USE_FAST_VIEWROT
force_update_fov_math();
}
@ -248,7 +280,7 @@ void FGView::UpdateViewMath( const FGInterface& f ) {
-f.get_Latitude() * RAD_TO_DEG );
sgSetVec3( local_up, UP[0][0], UP[0][1], UP[0][2] );
// sgXformVec3( local_up, UP );
// sgXformVec3( local_up, UP );
// cout << "Local Up = " << local_up[0] << "," << local_up[1] << ","
// << local_up[2] << endl;
@ -283,19 +315,23 @@ void FGView::UpdateViewMath( const FGInterface& f ) {
sgMakeRotMat4( VIEW_OFFSET, view_offset * RAD_TO_DEG, view_up );
// cout << "VIEW_OFFSET matrix" << endl;
// print_sgMat4( VIEW_OFFSET );
sgXformVec3( view_forward, forward, VIEW_OFFSET );
// cout << "view_forward = " << view_forward[0] << ","
// << view_forward[1] << "," << view_forward[2] << endl;
// VIEW_ROT = LARC_TO_SSG * ( VIEWo * VIEW_OFFSET )
sgMat4 TMP2;
// sgMultMat4( TMP2, VIEWo, VIEW_OFFSET );
// sgMultMat4( VIEW_ROT, LARC_TO_SSG, TMP2 );
#ifdef USE_FAST_VIEWROT
fgMakeViewRot( VIEW_ROT, VIEW_OFFSET, VIEWo );
#else
// sgMultMat4( VIEW_ROT, VIEW_OFFSET, VIEWo );
// sgPreMultMat4( VIEW_ROT, LARC_TO_SSG );
sgCopyMat4( VIEW_ROT, VIEWo );
sgPostMultMat4( VIEW_ROT, VIEW_OFFSET );
sgPreMultMat4( VIEW_ROT, LARC_TO_SSG );
#endif
// cout << "VIEW_ROT matrix" << endl;
// print_sgMat4( VIEW_ROT );
sgVec3 trans_vec;
sgSetVec3( trans_vec,
view_pos.x() + pilot_offset_world[0],
@ -314,11 +350,6 @@ void FGView::UpdateViewMath( const FGInterface& f ) {
sgPreMultMat4( VIEW, quat_mat);
// !!!!!!!!!! testing
sgMakeRotMat4( TMP, view_offset * RAD_TO_DEG, view_up );
sgXformVec3( view_forward, forward, TMP );
// cout << "view_forward = " << view_forward[0] << ","
// << view_forward[1] << "," << view_forward[2] << endl;
// make a vector to the current view position
sgSetVec3( v0, view_pos.x(), view_pos.y(), view_pos.z() );
@ -333,17 +364,39 @@ void FGView::UpdateViewMath( const FGInterface& f ) {
// << surface_south[1] << "," << surface_south[2] << endl;
// now calculate the surface east vector
#define USE_FAST_SURFACE_EAST
#ifdef USE_FAST_SURFACE_EAST
sgVec3 local_down;
sgNegateVec3(local_down, local_up);
sgVectorProductVec3(surface_east, surface_south, local_down);
#else
#define USE_LOCAL_UP
#ifdef USE_LOCAL_UP
sgMakeRotMat4( TMP, FG_PI_2 * RAD_TO_DEG, local_up );
#else
sgMakeRotMat4( TMP, FG_PI_2 * RAD_TO_DEG, view_up );
#endif // USE_LOCAL_UP
// cout << "sgMat4 TMP" << endl;
// print_sgMat4( TMP );
sgXformVec3(surface_east, surface_south, TMP);
// cout << "Surface direction directly east" << surface_east[0] << ","
#endif // USE_FAST_SURFACE_EAST
// cout << "Surface direction directly east " << surface_east[0] << ","
// << surface_east[1] << "," << surface_east[2] << endl;
// cout << "Should be close to zero = "
// << sgScalarProductVec3(surface_south, surface_east) << endl;
}
void FGView::CurrentNormalInLocalPlane(sgVec3 dst, sgVec3 src) {
sgVec3 tmp;
sgSetVec3(tmp, src[0], src[1], src[2] );
sgMat4 TMP;
sgTransposeNegateMat4 ( TMP, UP ) ;
sgXformVec3(tmp, tmp, TMP);
sgSetVec3(dst, tmp[2], tmp[1], tmp[0] );
}
// Destructor
FGView::~FGView( void ) {
}

View file

@ -151,6 +151,9 @@ public:
// Update the field of view coefficients
void UpdateFOV( const fgOPTIONS& o );
// Transform a vector from world coordinates to the local plane
void CurrentNormalInLocalPlane(sgVec3 dst, sgVec3 src);
// accessor functions
inline double get_view_offset() const { return view_offset; }
inline void set_view_offset( double a ) { view_offset = a; }

View file

@ -89,17 +89,7 @@ int FGTileMgr::init( void ) {
if ( state != Start ) {
FG_LOG( FG_TERRAIN, FG_INFO,
"... Reinitializing." );
// This is necessay to keep bookeeping straight for the
// tile_cache -- which actually handles all the
// (de)allocations
while( load_queue.size() ) {
FG_LOG( FG_TERRAIN, FG_INFO,
"Load queue not empty, popping a tile" );
FGLoadRec pending = load_queue.front();
load_queue.pop_front();
load_tile( pending.b, pending.cache_index );
}
destroy_queue();
} else {
FG_LOG( FG_TERRAIN, FG_INFO,
"... First time through." );
@ -159,9 +149,7 @@ int FGTileMgr::sched_tile( const FGBucket& b ) {
void FGTileMgr::load_tile( const FGBucket& b, int cache_index) {
FG_LOG( FG_TERRAIN, FG_DEBUG, "Loading tile " << b );
global_tile_cache.fill_in(cache_index, b);
FG_LOG( FG_TERRAIN, FG_DEBUG, "Loaded for cache index: " << cache_index );
}
@ -202,7 +190,11 @@ FGTileMgr::current_elev_ssg( const Point3D& abs_view_pos,
if ( result > -9000 ) {
scenery.cur_elev = result;
scenery.cur_radius = geoc.radius();
sgdCopyVec3(scenery.cur_normal, hit_list.get_normal(this_hit));
sgVec3 tmp;
sgSetVec3(tmp, hit_list.get_normal(this_hit));
current_view.CurrentNormalInLocalPlane(tmp, tmp);
sgdSetVec3( scenery.cur_normal, tmp );
// cout << "NED: " << tmp[0] << " " << tmp[1] << " " << tmp[2] << endl;
return true;
} else {
FG_LOG( FG_TERRAIN, FG_INFO, "no terrain intersection" );
@ -218,11 +210,9 @@ FGBucket FGTileMgr::BucketOffset( int dx, int dy )
{
double clat, clon, span;
if( scroll_direction == SCROLL_INIT ) {
pending.set_bucket( longitude, latitude );
clat = pending.get_center_lat() + dy * FG_BUCKET_SPAN;
// use current latitude and longitude
// walk dy units in the lat direction
pending.set_bucket( longitude, clat );
clat = current_bucket.get_center_lat() + dy * FG_BUCKET_SPAN;
// find the lon span for the new latitude
span = bucket_span( clat );
@ -230,11 +220,9 @@ FGBucket FGTileMgr::BucketOffset( int dx, int dy )
// walk dx units in the lon direction
clon = longitude + dx * span;
} else {
pending.set_bucket( last_longitude, last_latitude );
clat = pending.get_center_lat() + dy * FG_BUCKET_SPAN;
// use previous latitude and longitude
// walk dy units in the lat direction
pending.set_bucket( last_longitude, clat );
clat = previous_bucket.get_center_lat() + dy * FG_BUCKET_SPAN;
// find the lon span for the new latitude
span = bucket_span( clat );
@ -266,7 +254,7 @@ void FGTileMgr::scroll( void )
dw = tile_diameter / 2;
dh = dw + 1;
for ( i = 0; i < tile_diameter; i++ ) {
sched_tile( BucketOffset( i - dw, dh) );
sched_tile( BucketOffset( i - dw, dh ) );
}
break;
case SCROLL_EAST:
@ -279,19 +267,19 @@ void FGTileMgr::scroll( void )
}
break;
case SCROLL_SOUTH:
dw = tile_diameter / 2;
dh = -dw - 1;
FG_LOG( FG_TERRAIN, FG_DEBUG,
" (South) Loading " << tile_diameter << " tiles" );
dw = tile_diameter / 2;
dh = -dw - 1;
for ( i = 0; i < tile_diameter; i++ ) {
sched_tile( BucketOffset( i - dw, dh) );
sched_tile( BucketOffset( i - dw, dh ) );
}
break;
case SCROLL_WEST:
dh = tile_diameter / 2;
dw = -dh - 1;
FG_LOG( FG_TERRAIN, FG_DEBUG,
" (West) Loading " << tile_diameter << " tiles" );
dh = tile_diameter / 2;
dw = -dh - 1;
for ( i = 0; i < tile_diameter; i++ ) {
sched_tile( BucketOffset( dw, i - dh ) );
}
@ -365,6 +353,27 @@ void FGTileMgr::initialize_queue()
}
// forced emptying of the queue
// This is necessay to keep bookeeping straight for the
// tile_cache -- which actually handles all the
// (de)allocations
void FGTileMgr::destroy_queue() {
while( load_queue.size() ) {
FG_LOG( FG_TERRAIN, FG_INFO,
"Load queue not empty, popping a tile" );
FGLoadRec pending = load_queue.front();
load_queue.pop_front();
FGTileEntry *t = global_tile_cache.get_tile( pending.cache_index );
// just t->mark_unused() should be enough
// but a little paranoia doesn't hurt us here
if(t->is_scheduled_for_use())
t->mark_unused();
else
load_tile( pending.b, pending.cache_index );
}
}
// given the current lon/lat (in degrees), fill in the array of local
// chunks. If the chunk isn't already in the cache, then read it from
// disk.

View file

@ -96,6 +96,11 @@ private:
// initialize the cache
void initialize_queue();
// forced emptying of the queue. This is necessay to keep
// bookeeping straight for the tile_cache -- which actually
// handles all the (de)allocations
void destroy_queue();
FGBucket BucketOffset( int dx, int dy );
// schedule a tile for loading