}
-#if 0
-// Basically, this is a modified version of the Mesa gluLookAt()
-// function that's been modified slightly so we can capture the
-// result before sending it off to OpenGL land.
-void FGView::LookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez,
- GLdouble centerx, GLdouble centery, GLdouble centerz,
- GLdouble upx, GLdouble upy, GLdouble upz ) {
- GLfloat *m;
- GLdouble x[3], y[3], z[3];
- GLdouble mag;
-
- m = current_view.MODEL_VIEW;
-
- /* Make rotation matrix */
-
- /* Z vector */
- z[0] = eyex - centerx;
- z[1] = eyey - centery;
- z[2] = eyez - centerz;
- mag = sqrt( z[0]*z[0] + z[1]*z[1] + z[2]*z[2] );
- if (mag) { /* mpichler, 19950515 */
- z[0] /= mag;
- z[1] /= mag;
- z[2] /= mag;
- }
-
- /* Y vector */
- y[0] = upx;
- y[1] = upy;
- y[2] = upz;
-
- /* X vector = Y cross Z */
- x[0] = y[1]*z[2] - y[2]*z[1];
- x[1] = -y[0]*z[2] + y[2]*z[0];
- x[2] = y[0]*z[1] - y[1]*z[0];
-
- /* Recompute Y = Z cross X */
- y[0] = z[1]*x[2] - z[2]*x[1];
- y[1] = -z[0]*x[2] + z[2]*x[0];
- y[2] = z[0]*x[1] - z[1]*x[0];
-
- /* mpichler, 19950515 */
- /* cross product gives area of parallelogram, which is < 1.0 for
- * non-perpendicular unit-length vectors; so normalize x, y here
- */
-
- mag = sqrt( x[0]*x[0] + x[1]*x[1] + x[2]*x[2] );
- if (mag) {
- x[0] /= mag;
- x[1] /= mag;
- x[2] /= mag;
- }
-
- mag = sqrt( y[0]*y[0] + y[1]*y[1] + y[2]*y[2] );
- if (mag) {
- y[0] /= mag;
- y[1] /= mag;
- y[2] /= mag;
- }
-
-#define M(row,col) m[col*4+row]
- M(0,0) = x[0]; M(0,1) = x[1]; M(0,2) = x[2]; M(0,3) = 0.0;
- M(1,0) = y[0]; M(1,1) = y[1]; M(1,2) = y[2]; M(1,3) = 0.0;
- M(2,0) = z[0]; M(2,1) = z[1]; M(2,2) = z[2]; M(2,3) = 0.0;
- // the following is part of the original gluLookAt(), but we are
- // commenting it out because we know we are going to be doing a
- // translation below which will set these values anyways
- // M(3,0) = 0.0; M(3,1) = 0.0; M(3,2) = 0.0; M(3,3) = 1.0;
-#undef M
-
- // Translate Eye to Origin
- // replaces: glTranslated( -eyex, -eyey, -eyez );
-
- // this has been slightly modified from the original glTranslate()
- // code because we know that coming into this m[12] = m[13] =
- // m[14] = 0.0, and m[15] = 1.0;
- m[12] = m[0] * -eyex + m[4] * -eyey + m[8] * -eyez /* + m[12] */;
- m[13] = m[1] * -eyex + m[5] * -eyey + m[9] * -eyez /* + m[13] */;
- m[14] = m[2] * -eyex + m[6] * -eyey + m[10] * -eyez /* + m[14] */;
- m[15] = 1.0 /* m[3] * -eyex + m[7] * -eyey + m[11] * -eyez + m[15] */;
-
- // xglMultMatrixd( m );
- xglLoadMatrixf( m );
-}
-#endif
-
-
// Update the view volume, position, and orientation
void FGView::UpdateViewParams( void ) {
FGInterface *f = current_aircraft.fdm_state;
UpdateViewMath(f);
- // UpdateWorldToEye(f);
if ((current_options.get_panel_status() != panel_hist) && (current_options.get_panel_status()))
{
// (GLint)((winHeight)*0.4232) );
}
- // Tell GL we are about to modify the projection parameters
- // xglMatrixMode(GL_PROJECTION);
- // xglLoadIdentity();
- if ( f->get_Altitude() * FEET_TO_METER - scenery.cur_elev > 10.0 ) {
- // ssgSetNearFar( 10.0, 100000.0 );
- // gluPerspective(current_options.get_fov(), win_ratio, 10.0, 100000.0);
- } else {
- // ssgSetNearFar( 0.5, 100000.0 );
- // gluPerspective(current_options.get_fov(), win_ratio, 0.5, 100000.0);
- // printf("Near ground, minimizing near clip plane\n");
- }
- // }
-
- // xglMatrixMode(GL_MODELVIEW);
- // xglLoadIdentity();
-
- // set up our view volume (default)
-#if !defined(FG_VIEW_INLINE_OPTIMIZATIONS)
- /* LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
- 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]); */
-
- // look almost straight up (testing and eclipse watching)
- /* LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
- view_pos.x() + view_up[0] + .001,
- view_pos.y() + view_up[1] + .001,
- view_pos.z() + view_up[2] + .001,
- view_up[0], view_up[1], view_up[2]); */
-
- // lock view horizontally towards sun (testing)
- /* LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
- view_pos.x() + surface_to_sun[0],
- view_pos.y() + surface_to_sun[1],
- view_pos.z() + surface_to_sun[2],
- view_up[0], view_up[1], view_up[2]); */
-
- // lock view horizontally towards south (testing)
- /* LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
- view_pos.x() + surface_south[0],
- view_pos.y() + surface_south[1],
- view_pos.z() + surface_south[2],
- view_up[0], view_up[1], view_up[2]); */
-
-#else // defined(FG_VIEW_INLINE_OPTIMIZATIONS)
- //void FGView::LookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez,
- // GLdouble centerx, GLdouble centery, GLdouble centerz,
- // GLdouble upx, GLdouble upy, GLdouble upz )
- {
- GLfloat *m;
- GLdouble x[3], y[3], z[3];
- // GLdouble mag;
-
- m = current_view.MODEL_VIEW;
-
- /* Make rotation matrix */
-
- /* Z vector */
- z[0] = -view_forward[0]; //eyex - centerx;
- z[1] = -view_forward[1]; //eyey - centery;
- z[2] = -view_forward[2]; //eyez - centerz;
-
- // In our case this is a unit vector NHV
-
- // mag = sqrt( z[0]*z[0] + z[1]*z[1] + z[2]*z[2] );
- // if (mag) { /* mpichler, 19950515 */
- // mag = 1.0/mag;
- // printf("mag(%f) ", mag);
- // z[0] *= mag;
- // z[1] *= mag;
- // z[2] *= mag;
- // }
-
- /* Y vector */
- y[0] = view_up[0]; //upx;
- y[1] = view_up[1]; //upy;
- y[2] = view_up[2]; //upz;
-
- /* X vector = Y cross Z */
- x[0] = y[1]*z[2] - y[2]*z[1];
- x[1] = -y[0]*z[2] + y[2]*z[0];
- x[2] = y[0]*z[1] - y[1]*z[0];
-
- // printf(" %f %f %f ", y[0], y[1], y[2]);
-
- /* Recompute Y = Z cross X */
- // y[0] = z[1]*x[2] - z[2]*x[1];
- // y[1] = -z[0]*x[2] + z[2]*x[0];
- // y[2] = z[0]*x[1] - z[1]*x[0];
-
- // printf(" %f %f %f\n", y[0], y[1], y[2]);
-
- // In our case these are unit vectors NHV
-
- /* mpichler, 19950515 */
- /* cross product gives area of parallelogram, which is < 1.0 for
- * non-perpendicular unit-length vectors; so normalize x, y here
- */
-
- // mag = sqrt( x[0]*x[0] + x[1]*x[1] + x[2]*x[2] );
- // if (mag) {
- // mag = 1.0/mag;
- // printf("mag2(%f) ", mag);
- // x[0] *= mag;
- // x[1] *= mag;
- // x[2] *= mag;
- // }
-
- // mag = sqrt( y[0]*y[0] + y[1]*y[1] + y[2]*y[2] );
- // if (mag) {
- // mag = 1.0/mag;
- // printf("mag3(%f)\n", mag);
- // y[0] *= mag;
- // y[1] *= mag;
- // y[2] *= mag;
- // }
-
-#define M(row,col) m[col*4+row]
- M(0,0) = x[0]; M(0,1) = x[1]; M(0,2) = x[2]; M(0,3) = 0.0;
- M(1,0) = y[0]; M(1,1) = y[1]; M(1,2) = y[2]; M(1,3) = 0.0;
- M(2,0) = z[0]; M(2,1) = z[1]; M(2,2) = z[2]; M(2,3) = 0.0;
- // the following is part of the original gluLookAt(), but we are
- // commenting it out because we know we are going to be doing a
- // translation below which will set these values anyways
- // M(3,0) = 0.0; M(3,1) = 0.0; M(3,2) = 0.0; M(3,3) = 1.0;
-#undef M
-
- // Translate Eye to Origin
- // replaces: glTranslated( -eyex, -eyey, -eyez );
-
- // this has been slightly modified from the original glTranslate()
- // code because we know that coming into this m[12] = m[13] =
- // m[14] = 0.0, and m[15] = 1.0;
- m[12] = m[0] * -view_pos.x() + m[4] * -view_pos.y() + m[8] * -view_pos.z() /* + m[12] */;
- m[13] = m[1] * -view_pos.x() + m[5] * -view_pos.y() + m[9] * -view_pos.z() /* + m[13] */;
- m[14] = m[2] * -view_pos.x() + m[6] * -view_pos.y() + m[10] * -view_pos.z() /* + m[14] */;
- m[15] = 1.0 /* m[3] * -view_pos.x() + m[7] * -view_pos.y() + m[11] * -view_pos.z() + m[15] */;
-
- // xglMultMatrixd( m );
- // xglLoadMatrixf( m );
- }
-#endif // FG_VIEW_INLINE_OPTIMIZATIONS
-
panel_hist = current_options.get_panel_status();
}
// cout << "VIEW matrix" << endl;;
// MAT3print(VIEW, stdout);
- sgMat4 sgTMP;
+ sgMat4 sgTMP, sgTMP2;
sgMultMat4( sgTMP, sgLOCAL, sgUP );
- sgMultMat4( sgVIEW_ROT, sgLARC_TO_SSG, sgTMP );
+
+ // generate the sg view up vector
+ sgVec3 vec1;
+ sgSetVec3( vec1, 1.0, 0.0, 0.0 );
+ sgXformVec3( sgview_up, vec1, sgTMP );
+
+ // generate the view offset matrix
+ sgMakeRotMat4( sgVIEW_OFFSET, view_offset * RAD_TO_DEG, sgview_up );
+
+ /*
+ cout << "sg VIEW_OFFSET matrix" << endl;
+ MAT3mat print;
+ int i;
+ int j;
+ for ( i = 0; i < 4; i++ ) {
+ for ( j = 0; j < 4; j++ ) {
+ print[i][j] = sgVIEW_OFFSET[i][j];
+ }
+ }
+ MAT3print( print, stdout);
+ */
+
+ sgMultMat4( sgTMP2, sgTMP, sgVIEW_OFFSET );
+ sgMultMat4( sgVIEW_ROT, sgLARC_TO_SSG, sgTMP2 );
sgMakeTransMat4( sgTRANS, view_pos.x(), view_pos.y(), view_pos.z() );
sgCopyMat4( tmp.m, sgVIEW );
follow.push_back( tmp );
+ // generate the current up, forward, and fwrd-view vectors
+ MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
+ MAT3mult_vec(view_up, vec, VIEW);
+
/*
cout << "FG derived VIEW matrix using sg routines" << endl;
MAT3mat print;
MAT3print( print, stdout);
*/
-
- // generate the current up, forward, and fwrd-view vectors
- MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
- 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],