From: curt Date: Wed, 27 May 1998 02:24:05 +0000 (+0000) Subject: View optimizations by Norman Vine. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2cd509d3de3d0d1e415b33870615f552e61112f5;p=flightgear.git View optimizations by Norman Vine. --- diff --git a/Main/GLUTkey.cxx b/Main/GLUTkey.cxx index 59e37b7f6..3f49a0944 100644 --- a/Main/GLUTkey.cxx +++ b/Main/GLUTkey.cxx @@ -111,6 +111,7 @@ void GLUTkey(unsigned char k, int x, int y) { if ( o->fov > FG_FOV_MAX ) { o->fov = FG_FOV_MAX; } + v->update_fov = TRUE; return; case 90: /* Z key */ w->visibility /= 1.10; @@ -179,6 +180,7 @@ void GLUTkey(unsigned char k, int x, int y) { if ( o->fov < FG_FOV_MIN ) { o->fov = FG_FOV_MIN; } + v->update_fov = TRUE; return; case 122: /* z key */ w->visibility *= 1.10; @@ -280,9 +282,12 @@ void GLUTspecialkey(int k, int x, int y) { /* $Log$ -/* Revision 1.9 1998/05/16 13:05:21 curt -/* Added limits to fov. +/* Revision 1.10 1998/05/27 02:24:05 curt +/* View optimizations by Norman Vine. /* + * Revision 1.9 1998/05/16 13:05:21 curt + * Added limits to fov. + * * Revision 1.8 1998/05/13 18:29:56 curt * Added a keyboard binding to dynamically adjust field of view. * Added a command line option to specify fov. diff --git a/Main/views.cxx b/Main/views.cxx index 803eb4d89..88bc02c3f 100644 --- a/Main/views.cxx +++ b/Main/views.cxx @@ -55,6 +55,34 @@ void fgVIEW::Init( void ) { view_offset = 0.0; goal_view_offset = 0.0; + + winWidth = 640; // FG_DEFAULT_WIN_WIDTH + winHeight = 480; // FG_DEFAULT_WIN_HEIGHT + win_ratio = (double) winWidth / (double) winHeight; + update_fov = TRUE; +} + + +// Update the field of view parameters +void fgVIEW::UpdateFOV( fgOPTIONS *o ) { + double theta_x, theta_y; + + // printf("win_ratio = %.2f\n", win_ratio); + // calculate sin() and cos() of fov / 2 in X direction; + theta_x = (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 = (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); } @@ -64,32 +92,20 @@ void fgVIEW::Update( fgFLIGHT *f ) { fgPolarPoint3d p; MAT3vec vec, forward, v0, minus_z; MAT3mat R, TMP, UP, LOCAL, VIEW; - double theta_x, theta_y, ntmp; + double ntmp; o = ¤t_options; + if(update_fov == TRUE) { + // printf("Updating fov\n"); + UpdateFOV(o); + update_fov = FALSE; + } + 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 = (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 = (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; @@ -240,23 +256,63 @@ void fgVIEW::UpdateWorldToEye( fgFLIGHT *f ) { 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); + // if we have a view offset use slow way for now + if(fabs(view_offset)>FG_EPSILON){ + // 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); + + // aircraft roll/pitch/yaw + MAT3mult(TMP, R_Phi, R_Theta); + MAT3mult(AIRCRAFT, TMP, R_Psi); + + } else { // JUST USE LOCAL_TO_BODY NHV 5/25/98 + // hey this is even different then LOCAL[][] above ?? + + AIRCRAFT[0][0] = -FG_T_local_to_body_22; + AIRCRAFT[0][1] = -FG_T_local_to_body_23; + AIRCRAFT[0][2] = FG_T_local_to_body_21; + AIRCRAFT[0][3] = 0.0; + AIRCRAFT[1][0] = FG_T_local_to_body_32; + AIRCRAFT[1][1] = FG_T_local_to_body_33; + AIRCRAFT[1][2] = -FG_T_local_to_body_31; + AIRCRAFT[1][3] = 0.0; + AIRCRAFT[2][0] = FG_T_local_to_body_12; + AIRCRAFT[2][1] = FG_T_local_to_body_13; + AIRCRAFT[2][2] = -FG_T_local_to_body_11; + AIRCRAFT[2][3] = 0.0; + AIRCRAFT[3][0] = AIRCRAFT[3][1] = AIRCRAFT[3][2] = AIRCRAFT[3][3] = 0.0; + AIRCRAFT[3][3] = 1.0; + + // ??? SOMETHING LIKE THIS SHOULD WORK NHV + // Rotate about LOCAL_UP (AIRCRAFT[2][]) + // MAT3_SET_HVEC(vec, AIRCRAFT[2][0], AIRCRAFT[2][1], + // AIRCRAFT[2][2], AIRCRAFT[2][3]); + // MAT3rotate(TMP, vec, FG_PI - view_offset ); + // MAT3mult(AIRCRAFT, AIRCRAFT, TMP); + } + // printf("\naircraft roll pitch yaw\n"); + // MAT3print(AIRCRAFT, 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); + // 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); // Latitude MAT3_SET_HVEC(vec, 1.0, 0.0, 0.0, 1.0); @@ -272,6 +328,7 @@ void fgVIEW::UpdateWorldToEye( fgFLIGHT *f ) { // printf("\nLongitude matrix\n"); // MAT3print(R_Lon, stdout); +#ifdef THIS_IS_OLD_CODE // 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); @@ -283,6 +340,7 @@ void fgVIEW::UpdateWorldToEye( fgFLIGHT *f ) { MAT3mult(AIRCRAFT, TMP, R_Psi); // printf("\naircraft roll pitch yaw\n"); // MAT3print(AIRCRAFT, stdout); +#endif THIS_IS_OLD_CODE // lon/lat MAT3mult(WORLD, R_Lat, R_Lon); @@ -318,6 +376,9 @@ fgVIEW::~fgVIEW( void ) { // $Log$ +// Revision 1.11 1998/05/27 02:24:05 curt +// View optimizations by Norman Vine. +// // Revision 1.10 1998/05/17 16:59:03 curt // First pass at view frustum culling now operational. // diff --git a/Main/views.hxx b/Main/views.hxx index d95f9945f..c4b335878 100644 --- a/Main/views.hxx +++ b/Main/views.hxx @@ -38,6 +38,16 @@ #include