1
0
Fork 0

Makefile.am: Got rid of -DUSE_SSG

options.cxx: reorder option initializations to match declaration order.
views.cxx: much cleanup of stuff that was depricated by the move to ssg.
           I now use ssg to do all the projection/modelview matrix calculation
           and setup. (mostly)
vies.hxx: also added the view pan offset to the view matrix calcs.
This commit is contained in:
curt 1999-08-08 15:21:54 +00:00
parent 471fe324ff
commit 1e8b5c8956
4 changed files with 35 additions and 251 deletions

View file

@ -4,7 +4,7 @@ else
SERIAL_LIBS =
endif
CPPFLAGS += -DUSE_SSG -DPKGLIBDIR=\"$(pkglibdir)\"
CPPFLAGS += -DPKGLIBDIR=\"$(pkglibdir)\"
EXTRA_DIST = 3dfx.sh runfgfs.in runfgfs.bat.in

View file

@ -138,14 +138,14 @@ fgOPTIONS::fgOPTIONS() :
// if it is lower than the terrain
altitude(-9999.0),
// Initialize current options velocities to 0.0
uBody(0.0), vBody(0.0), wBody(0.0),
// Initial Orientation
heading(270.0), // heading (yaw) angle in degress (Psi)
roll(0.0), // roll angle in degrees (Phi)
pitch(0.424), // pitch angle in degrees (Theta)
// Initialize current options velocities to 0.0
uBody(0.0), vBody(0.0), wBody(0.0),
// Miscellaneous
game_mode(0),
splash_screen(1),

View file

@ -141,99 +141,11 @@ void FGView::cycle_view_mode() {
}
#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()))
{
@ -247,150 +159,6 @@ void FGView::UpdateViewParams( void ) {
// (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();
}
@ -752,9 +520,32 @@ void FGView::UpdateViewMath( FGInterface *f ) {
// 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() );
@ -764,6 +555,10 @@ void FGView::UpdateViewMath( FGInterface *f ) {
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;
@ -777,11 +572,6 @@ void FGView::UpdateViewMath( FGInterface *f ) {
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],

View file

@ -150,6 +150,7 @@ public:
// up vector for the view (usually point straight up through the
// top of the aircraft
MAT3vec view_up;
sgVec3 sgview_up;
// the vector pointing straight out the nose of the aircraft
MAT3vec view_forward;
@ -160,6 +161,7 @@ public:
// Transformation matrix for the view direction offset relative to
// the AIRCRAFT matrix
MAT3mat VIEW_OFFSET;
sgMat4 sgVIEW_OFFSET;
// Current model view matrix;
GLfloat MODEL_VIEW[16];
@ -184,14 +186,6 @@ public:
// Initialize a view class
void Init( void );
// Basically, this is a modified version of the Mesa gluLookAt()
// function that's been modified slightly so we can capture the
// result (and use it later) otherwise this all gets calculated in
// OpenGL land and we don't have access to the results.
/* void LookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez,
GLdouble centerx, GLdouble centery, GLdouble centerz,
GLdouble upx, GLdouble upy, GLdouble upz ); */
// Update the view volume, position, and orientation
void UpdateViewParams( void );