Working on lookat views.
This commit is contained in:
parent
1b206c6202
commit
49aab2af8e
3 changed files with 88 additions and 88 deletions
|
@ -46,19 +46,19 @@
|
|||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h> /* for stat() */
|
||||
# include <sys/stat.h> // for stat()
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h> /* for stat() */
|
||||
# include <unistd.h> // for stat()
|
||||
#endif
|
||||
|
||||
#include <plib/pu.h> // plib include
|
||||
#include <plib/ssg.h> // plib include
|
||||
#include <plib/pu.h>
|
||||
#include <plib/ssg.h>
|
||||
|
||||
#ifdef ENABLE_AUDIO_SUPPORT
|
||||
# include <plib/sl.h> // plib include
|
||||
# include <plib/sm.h> // plib include
|
||||
# include <plib/sl.h>
|
||||
# include <plib/sm.h>
|
||||
#endif
|
||||
|
||||
#include <simgear/constants.h> // for VERSION
|
||||
|
@ -341,37 +341,42 @@ void fgRenderFrame( void ) {
|
|||
|
||||
sgVec3 po; // chase view pilot_offset
|
||||
sgVec3 wup; // chase view world up
|
||||
sgCopyVec3( po, chase_view->get_pilot_offset() );
|
||||
sgCopyVec3( wup, chase_view->get_world_up() );
|
||||
sgMat4 CXFM; // chase view + pilot offset xform
|
||||
sgMakeRotMat4( CXFM, cur_fdm_state->get_Psi() * RAD_TO_DEG, wup );
|
||||
sgVec3 npo; // new pilot offset after rotation
|
||||
sgXformVec3( npo, po, CXFM );
|
||||
sgSetVec3( po, 0.0, 0.0, 200.0 );
|
||||
sgCopyVec3( wup, pilot_view->get_world_up() );
|
||||
// sgMat4 CXFM; // chase view + pilot offset xform
|
||||
// sgMakeRotMat4( CXFM, cur_fdm_state->get_Psi() * RAD_TO_DEG, wup );
|
||||
// sgVec3 npo; // new pilot offset after rotation
|
||||
// sgXformVec3( npo, po, CXFM );
|
||||
|
||||
chase_view->set_geod_view_pos( cur_fdm_state->get_Longitude(),
|
||||
cur_fdm_state->get_Lat_geocentric(),
|
||||
cur_fdm_state->get_Altitude() *
|
||||
FEET_TO_METER );
|
||||
chase_view->set_pilot_offset( npo[0], npo[1], npo[2] );
|
||||
chase_view->set_sea_level_radius( cur_fdm_state->
|
||||
get_Sea_level_radius() *
|
||||
FEET_TO_METER );
|
||||
chase_view->set_pilot_offset( po[0], po[1], po[2] );
|
||||
sgVec3 negpo;
|
||||
sgNegateVec3( negpo, npo );
|
||||
sgNegateVec3( negpo, po );
|
||||
chase_view->set_view_forward( negpo );
|
||||
chase_view->set_view_up( wup );
|
||||
|
||||
#if 0
|
||||
// this is a test, we are trying to match RPH and LookAt
|
||||
// matrices
|
||||
tv->set_geod_view_pos( cur_fdm_state->get_Longitude(),
|
||||
cur_fdm_state->get_Lat_geocentric(),
|
||||
cur_fdm_state->get_Altitude() *
|
||||
FEET_TO_METER );
|
||||
tv->set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() *
|
||||
FEET_TO_METER );
|
||||
tv->set_view_forward( globals->get_current_view()->get_view_forward() );
|
||||
tv->set_view_up( globals->get_current_view()->get_view_up() );
|
||||
chase_view->set_geod_view_pos( cur_fdm_state->get_Longitude(),
|
||||
cur_fdm_state->get_Lat_geocentric(),
|
||||
cur_fdm_state->get_Altitude() *
|
||||
FEET_TO_METER );
|
||||
chase_view->set_sea_level_radius( cur_fdm_state->
|
||||
get_Sea_level_radius() *
|
||||
FEET_TO_METER );
|
||||
chase_view->set_view_forward( pilot_view->get_view_forward() );
|
||||
chase_view->set_view_up( pilot_view->get_view_up() );
|
||||
#endif
|
||||
|
||||
sgMat4 rph;
|
||||
sgCopyMat4( rph, globals->get_current_view()->get_VIEW_ROT() );
|
||||
sgCopyMat4( rph, pilot_view->get_VIEW() );
|
||||
cout << "RPH Matrix = " << endl;
|
||||
int i, j;
|
||||
for ( i = 0; i < 4; i++ ) {
|
||||
|
@ -380,8 +385,9 @@ void fgRenderFrame( void ) {
|
|||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
sgMat4 la;
|
||||
sgCopyMat4( la, tv->get_VIEW_ROT() );
|
||||
sgCopyMat4( la, chase_view->get_VIEW() );
|
||||
cout << "LookAt Matrix = " << endl;
|
||||
for ( i = 0; i < 4; i++ ) {
|
||||
for ( j = 0; j < 4; j++ ) {
|
||||
|
@ -389,10 +395,10 @@ void fgRenderFrame( void ) {
|
|||
}
|
||||
cout << endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
// update view volume parameters
|
||||
// cout << "before pilot_view update" << endl;
|
||||
#if 0
|
||||
if ( globals->get_options()->get_view_mode() ==
|
||||
FGOptions::FG_VIEW_FOLLOW )
|
||||
{
|
||||
|
@ -403,6 +409,7 @@ void fgRenderFrame( void ) {
|
|||
} else {
|
||||
globals->get_current_view()->set_pilot_offset(0.0, 0.0, 0.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( ! fgPanelVisible() ) {
|
||||
xglViewport( 0, 0 ,
|
||||
|
@ -586,20 +593,18 @@ void fgRenderFrame( void ) {
|
|||
ssgSetNearFar( 0.5f, 120000.0f );
|
||||
}
|
||||
|
||||
if ( globals->get_options()->get_view_mode() ==
|
||||
FGOptions::FG_VIEW_PILOT )
|
||||
{
|
||||
if ( globals->get_viewmgr()->get_current() == 0 ) {
|
||||
// disable TuX
|
||||
penguin_sel->select(0);
|
||||
} else if ( globals->get_options()->get_view_mode() ==
|
||||
FGOptions::FG_VIEW_FOLLOW )
|
||||
{
|
||||
} else {
|
||||
// enable TuX and set up his position and orientation
|
||||
penguin_sel->select(1);
|
||||
|
||||
FGViewerRPH *pilot_view =
|
||||
(FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
|
||||
|
||||
sgMat4 sgTRANS;
|
||||
sgMakeTransMat4( sgTRANS,
|
||||
globals->get_current_view()->get_view_pos() );
|
||||
sgMakeTransMat4( sgTRANS, pilot_view->get_view_pos() );
|
||||
|
||||
sgVec3 ownship_up;
|
||||
sgSetVec3( ownship_up, 0.0, 0.0, 1.0);
|
||||
|
@ -615,7 +620,7 @@ void fgRenderFrame( void ) {
|
|||
// sgTUX = ( sgROT * pilot_view.VIEW_ROT ) * sgTRANS
|
||||
sgMat4 sgTUX;
|
||||
sgCopyMat4( sgTUX, sgROT );
|
||||
sgPostMultMat4( sgTUX, globals->get_current_view()->get_VIEW_ROT() );
|
||||
sgPostMultMat4( sgTUX, pilot_view->get_VIEW_ROT() );
|
||||
sgPostMultMat4( sgTUX, sgTRANS );
|
||||
|
||||
sgCoord tuxpos;
|
||||
|
|
|
@ -38,6 +38,14 @@
|
|||
// Define a structure containing view information
|
||||
class FGViewer {
|
||||
|
||||
public:
|
||||
|
||||
enum fgViewType {
|
||||
FG_RPH = 0,
|
||||
FG_LOOKAT = 1,
|
||||
FG_HPR = 2
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
// flag forcing a recalc of derived view parameters
|
||||
|
@ -45,6 +53,8 @@ private:
|
|||
|
||||
protected:
|
||||
|
||||
fgViewType _type;
|
||||
|
||||
// the current view offset angle from forward (rotated about the
|
||||
// view_up vector)
|
||||
double view_offset;
|
||||
|
@ -151,6 +161,8 @@ public:
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
// accessor functions
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
inline int get_type() const { return _type ; }
|
||||
inline int is_a( int t ) const { return get_type() == t ; }
|
||||
inline bool is_dirty() const { return dirty; }
|
||||
inline double get_view_offset() const { return view_offset; }
|
||||
inline double get_goal_view_offset() const { return goal_view_offset; }
|
||||
|
|
|
@ -48,62 +48,41 @@ FGViewerLookAt::FGViewerLookAt( void )
|
|||
}
|
||||
|
||||
|
||||
static void fgLookAt( sgVec3 eye, sgVec3 center, sgVec3 up, sgMat4 &m ) {
|
||||
double x[3], y[3], z[3];
|
||||
double mag;
|
||||
void fgMakeLookAtMat4 ( sgMat4 dst, const sgVec3 eye, const sgVec3 center,
|
||||
const sgVec3 up )
|
||||
{
|
||||
// Caveats:
|
||||
// 1) In order to compute the line of sight, the eye point must not be equal
|
||||
// to the center point.
|
||||
// 2) The up vector must not be parallel to the line of sight from the eye
|
||||
// to the center point.
|
||||
|
||||
/* Make rotation matrix */
|
||||
/* Compute the direction vectors */
|
||||
sgVec3 x,y,z;
|
||||
|
||||
/* Z vector */
|
||||
z[0] = eye[0] - center[0];
|
||||
z[1] = eye[1] - center[1];
|
||||
z[2] = eye[2] - center[2];
|
||||
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 = center - eye */
|
||||
sgSubVec3 ( y, center, eye ) ;
|
||||
|
||||
/* Y vector */
|
||||
y[0] = up[0];
|
||||
y[1] = up[1];
|
||||
y[2] = up[2];
|
||||
/* Z vector = up */
|
||||
sgCopyVec3 ( z, up ) ;
|
||||
|
||||
/* 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];
|
||||
/* X vector = Y cross Z */
|
||||
sgVectorProductVec3 ( x, y, z ) ;
|
||||
|
||||
/* 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];
|
||||
/* Recompute Z = X cross Y */
|
||||
sgVectorProductVec3 ( z, x, y ) ;
|
||||
|
||||
/* mpichler, 19950515 */
|
||||
/* cross product gives area of parallelogram, which is < 1.0 for
|
||||
* non-perpendicular unit-length vectors; so normalize x, y here
|
||||
*/
|
||||
/* Normalize everything */
|
||||
sgNormaliseVec3 ( x ) ;
|
||||
sgNormaliseVec3 ( y ) ;
|
||||
sgNormaliseVec3 ( z ) ;
|
||||
|
||||
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[row][col]
|
||||
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;
|
||||
M(3,0) = -eye[0]; M(3,1) = -eye[1]; M(3,2) = -eye[2]; M(3,3) = 1.0;
|
||||
/* Build the matrix */
|
||||
#define M(row,col) dst[row][col]
|
||||
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;
|
||||
M(3,0) = eye[0]; M(3,1) = eye[1]; M(3,2) = eye[2]; M(3,3) = 1.0;
|
||||
#undef M
|
||||
}
|
||||
|
||||
|
@ -152,24 +131,28 @@ void FGViewerLookAt::update() {
|
|||
sgdVec3 vp;
|
||||
sgdSubVec3( vp, abs_view_pos, sc );
|
||||
sgSetVec3( view_pos, vp );
|
||||
sgAddVec3( view_pos, pilot_offset );
|
||||
|
||||
FG_LOG( FG_VIEW, FG_DEBUG, "sea level radius = " << sea_level_radius );
|
||||
FG_LOG( FG_VIEW, FG_DEBUG, "Polar view pos = " << p );
|
||||
FG_LOG( FG_VIEW, FG_DEBUG, "Absolute view pos = "
|
||||
FG_LOG( FG_VIEW, FG_INFO, "Absolute view pos = "
|
||||
<< abs_view_pos[0] << ","
|
||||
<< abs_view_pos[1] << ","
|
||||
<< abs_view_pos[2] );
|
||||
FG_LOG( FG_VIEW, FG_DEBUG, "Relative view pos = "
|
||||
FG_LOG( FG_VIEW, FG_INFO, "Relative view pos = "
|
||||
<< view_pos[0] << "," << view_pos[1] << "," << view_pos[2] );
|
||||
FG_LOG( FG_VIEW, FG_DEBUG, "view forward = "
|
||||
FG_LOG( FG_VIEW, FG_INFO, "pilot offset = "
|
||||
<< pilot_offset[0] << "," << pilot_offset[1] << ","
|
||||
<< pilot_offset[2] );
|
||||
FG_LOG( FG_VIEW, FG_INFO, "view forward = "
|
||||
<< view_forward[0] << "," << view_forward[1] << ","
|
||||
<< view_forward[2] );
|
||||
FG_LOG( FG_VIEW, FG_DEBUG, "view up = "
|
||||
FG_LOG( FG_VIEW, FG_INFO, "view up = "
|
||||
<< view_up[0] << "," << view_up[1] << ","
|
||||
<< view_up[2] );
|
||||
|
||||
// Make the VIEW matrix.
|
||||
fgLookAt( view_pos, view_forward, view_up, VIEW );
|
||||
fgMakeLookAtMat4( VIEW, view_pos, view_forward, view_up );
|
||||
// cout << "VIEW matrix" << endl;
|
||||
// print_sgMat4( VIEW );
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue