+++ /dev/null
-// viewer_lookat.hxx -- class for managing a "look at" viewer in
-// the flightgear world.
-//
-// Written by Curtis Olson, started October 2000.
-//
-// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 2 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//
-// $Id$
-
-
-#include <simgear/compiler.h>
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <plib/ssg.h> // plib include
-
-#include <simgear/constants.h>
-#include <simgear/debug/logstream.hxx>
-#include <simgear/math/point3d.hxx>
-#include <simgear/math/polar3d.hxx>
-#include <simgear/math/sg_geodesy.hxx>
-#include <simgear/math/vector.hxx>
-
-#include <Scenery/scenery.hxx>
-
-#include "globals.hxx"
-#include "viewer_lookat.hxx"
-
-
-// Constructor
-FGViewerLookAt::FGViewerLookAt( void )
-{
- set_reverse_view_offset(true);
-}
-
-
-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.
-
- /* Compute the direction vectors */
- sgVec3 x,y,z;
-
- /* Y vector = center - eye */
- sgSubVec3 ( y, center, eye ) ;
-
- /* Z vector = up */
- sgCopyVec3 ( z, up ) ;
-
- /* X vector = Y cross Z */
- sgVectorProductVec3 ( x, y, z ) ;
-
- /* Recompute Z = X cross Y */
- sgVectorProductVec3 ( z, x, y ) ;
-
- /* Normalize everything */
- sgNormaliseVec3 ( x ) ;
- sgNormaliseVec3 ( y ) ;
- sgNormaliseVec3 ( z ) ;
-
- /* 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
-}
-
-
-// Update the view parameters
-void FGViewerLookAt::update() {
- sgVec3 minus_z;
-
- view_point.setPosition(geod_view_pos[0] * SGD_RADIANS_TO_DEGREES,
- geod_view_pos[1] * SGD_RADIANS_TO_DEGREES,
- geod_view_pos[2] * SG_METER_TO_FEET);
- sgCopyVec3(zero_elev, view_point.getZeroElevViewPos());
- sgdCopyVec3(abs_view_pos, view_point.getAbsoluteViewPos());
- sgCopyVec3(view_pos, view_point.getRelativeViewPos());
-
- sgVec3 tmp_offset;
- sgCopyVec3( tmp_offset, pilot_offset );
- SG_LOG( SG_VIEW, SG_DEBUG, "tmp offset = "
- << tmp_offset[0] << "," << tmp_offset[1] << ","
- << tmp_offset[2] );
-
- //!!!!!!!!!!!!!!!!!!!
- // THIS IS THE EXPERIMENTAL VIEWING ANGLE SHIFTER
- // THE MAJORITY OF THE WORK IS DONE IN GUI.CXX
- extern float GuiQuat_mat[4][4];
- sgXformPnt3( tmp_offset, tmp_offset, GuiQuat_mat );
- SG_LOG( SG_VIEW, SG_DEBUG, "tmp_offset = "
- << tmp_offset[0] << "," << tmp_offset[1] << ","
- << tmp_offset[2] );
-
- sgAddVec3( view_pos, tmp_offset );
- // !!!!!!!!!! testing
-
- // Make the VIEW matrix.
- fgMakeLookAtMat4( VIEW, view_pos, view_forward, view_up );
-
- // the VIEW matrix includes both rotation and translation. Let's
- // knock out the translation part to make the VIEW_ROT matrix
- sgCopyMat4( VIEW_ROT, VIEW );
- VIEW_ROT[3][0] = VIEW_ROT[3][1] = VIEW_ROT[3][2] = 0.0;
-
- // Make the world up rotation matrix
- sgMakeRotMat4( UP,
- geod_view_pos[0] * SGD_RADIANS_TO_DEGREES,
- 0.0,
- -geod_view_pos[1] * SGD_RADIANS_TO_DEGREES );
-
- // use a clever observation into the nature of our tranformation
- // matrix to grab the world_up vector
- sgSetVec3( world_up, UP[0][0], UP[0][1], UP[0][2] );
-
- // Given a vector pointing straight down (-Z), map into onto the
- // local plane representing "horizontal". This should give us the
- // local direction for moving "south".
- sgSetVec3( minus_z, 0.0, 0.0, -1.0 );
-
- sgmap_vec_onto_cur_surface_plane(world_up, view_pos, minus_z,
- surface_south);
- sgNormalizeVec3(surface_south);
-
- // now calculate the surface east vector
- sgVec3 world_down;
- sgNegateVec3(world_down, world_up);
- sgVectorProductVec3(surface_east, surface_south, world_down);
-
- set_clean();
-}
-
-
-// Destructor
-FGViewerLookAt::~FGViewerLookAt( void ) {
-}
+++ /dev/null
-// viewer_lookat.hxx -- class for managing a "look at" viewer in
-// the flightgear world.
-//
-// Written by Curtis Olson, started October 2000.
-//
-// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 2 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//
-// $Id$
-
-
-#ifndef _VIEWER_LOOKAT_HXX
-#define _VIEWER_LOOKAT_HXX
-
-
-#ifndef __cplusplus
-# error This library requires C++
-#endif
-
-
-#include "viewer.hxx"
-
-
-// Define a structure containing view information
-class FGViewerLookAt: public FGViewer {
-
-private:
-
- // up vector for the view (usually point straight up through the
- // top of the aircraft
- sgVec3 view_up;
-
- // the vector pointing straight out the nose of the aircraft
- sgVec3 view_forward;
-
- // Transformation matrix for the view direction offset relative to
- // the AIRCRAFT matrix
- sgMat4 VIEW_OFFSET;
-
- // sg versions of our friendly matrices
- sgMat4 LOCAL, TRANS, LARC_TO_SSG;
-
- // Update the view volume, position, and orientation
- void update();
-
-public:
-
- // Constructor
- FGViewerLookAt( void );
-
- // Destructor
- ~FGViewerLookAt( void );
-
- //////////////////////////////////////////////////////////////////////
- // setter functions
- //////////////////////////////////////////////////////////////////////
- inline void set_view_forward( sgVec3 vf ) {
- set_dirty();
- sgCopyVec3( view_forward, vf );
- }
- inline void set_view_up( sgVec3 vf ) {
- set_dirty();
- sgCopyVec3( view_up, vf );
- }
-
- //////////////////////////////////////////////////////////////////////
- // accessor functions
- //////////////////////////////////////////////////////////////////////
- inline float *get_view_forward() { return view_forward; }
- inline float *get_view_up() { return view_up; }
-
- //////////////////////////////////////////////////////////////////////
- // derived values accessor functions
- //////////////////////////////////////////////////////////////////////
-};
-
-
-#endif // _VIEWER_LOOKAT_HXX
+++ /dev/null
-// viewer_rph.cxx -- class for managing a Roll/Pitch/Heading viewer in
-// the flightgear world.
-//
-// Written by Curtis Olson, started August 1997.
-// overhaul started October 2000.
-//
-// Copyright (C) 1997 - 2000 Curtis L. Olson - curt@flightgear.org
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 2 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//
-// $Id$
-
-
-#include <simgear/compiler.h>
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <plib/ssg.h> // plib include
-
-#include <simgear/constants.h>
-#include <simgear/debug/logstream.hxx>
-#include <simgear/math/point3d.hxx>
-#include <simgear/math/polar3d.hxx>
-#include <simgear/math/sg_geodesy.hxx>
-#include <simgear/math/vector.hxx>
-
-#include <Scenery/scenery.hxx>
-
-#include "globals.hxx"
-#include "viewer_rph.hxx"
-
-
-// Constructor
-FGViewerRPH::FGViewerRPH( void )
-{
- set_reverse_view_offset(false);
-}
-
-
-// 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;
-}
-
-
-inline static void fgMakeLOCAL( sgMat4 dst, const double Theta,
- const double Phi, const double Psi)
-{
- SGfloat cosTheta = (SGfloat) cos(Theta);
- SGfloat sinTheta = (SGfloat) sin(Theta);
- SGfloat cosPhi = (SGfloat) cos(Phi);
- SGfloat sinPhi = (SGfloat) sin(Phi);
- SGfloat sinPsi = (SGfloat) sin(Psi) ;
- SGfloat cosPsi = (SGfloat) cos(Psi) ;
-
- dst[0][0] = cosPhi * cosTheta;
- dst[0][1] = sinPhi * cosPsi + cosPhi * -sinTheta * -sinPsi;
- dst[0][2] = sinPhi * sinPsi + cosPhi * -sinTheta * cosPsi;
- dst[0][3] = SG_ZERO;
-
- dst[1][0] = -sinPhi * cosTheta;
- dst[1][1] = cosPhi * cosPsi + -sinPhi * -sinTheta * -sinPsi;
- dst[1][2] = cosPhi * sinPsi + -sinPhi * -sinTheta * cosPsi;
- dst[1][3] = SG_ZERO ;
-
- dst[2][0] = sinTheta;
- dst[2][1] = cosTheta * -sinPsi;
- dst[2][2] = cosTheta * cosPsi;
- dst[2][3] = SG_ZERO;
-
- dst[3][0] = SG_ZERO;
- dst[3][1] = SG_ZERO;
- dst[3][2] = SG_ZERO;
- dst[3][3] = SG_ONE ;
-}
-
-
-// Update the view parameters
-void FGViewerRPH::update() {
- sgVec3 minus_z, right, forward, tilt;
- sgMat4 VIEWo;
-
- view_point.setPosition(geod_view_pos[0] * SGD_RADIANS_TO_DEGREES,
- geod_view_pos[1] * SGD_RADIANS_TO_DEGREES,
- geod_view_pos[2] * SG_METER_TO_FEET);
- sgCopyVec3(zero_elev, view_point.getZeroElevViewPos());
- sgdCopyVec3(abs_view_pos, view_point.getAbsoluteViewPos());
- sgCopyVec3(view_pos, view_point.getRelativeViewPos());
-
- // code to calculate LOCAL matrix calculated from Phi, Theta, and
- // Psi (roll, pitch, yaw) in case we aren't running LaRCsim as our
- // flight model
-
- fgMakeLOCAL( LOCAL, rph[1], rph[0], -rph[2] );
-
- sgMakeRotMat4( UP,
- geod_view_pos[0] * SGD_RADIANS_TO_DEGREES,
- 0.0,
- -geod_view_pos[1] * SGD_RADIANS_TO_DEGREES );
-
- sgSetVec3( world_up, UP[0][0], UP[0][1], UP[0][2] );
- sgCopyMat4( VIEWo, LOCAL );
- sgPostMultMat4( VIEWo, UP );
-
- // generate the sg view up and forward vectors
- sgSetVec3( view_up, VIEWo[0][0], VIEWo[0][1], VIEWo[0][2] );
- sgSetVec3( right, VIEWo[1][0], VIEWo[1][1], VIEWo[1][2] );
- sgSetVec3( forward, VIEWo[2][0], VIEWo[2][1], VIEWo[2][2] );
-
- // generate the pilot offset vector in world coordinates
- sgVec3 pilot_offset_world;
- sgSetVec3( pilot_offset_world,
- pilot_offset[2], pilot_offset[1], -pilot_offset[0] );
- sgXformVec3( pilot_offset_world, pilot_offset_world, VIEWo );
-
- // generate the view offset matrix
- sgMakeRotMat4( VIEW_OFFSET, view_offset * SGD_RADIANS_TO_DEGREES, view_up );
-
- sgMat4 VIEW_TILT;
- sgMakeRotMat4( VIEW_TILT, view_tilt * SGD_RADIANS_TO_DEGREES, right );
- sgPreMultMat4(VIEW_OFFSET, VIEW_TILT);
- // cout << "VIEW_OFFSET matrix" << endl;
- // print_sgMat4( VIEW_OFFSET );
- sgXformVec3( view_forward, forward, VIEW_OFFSET );
- SG_LOG( SG_VIEW, SG_DEBUG, "(RPH) view forward = "
- << view_forward[0] << "," << view_forward[1] << ","
- << view_forward[2] );
-
- // VIEW_ROT = LARC_TO_SSG * ( VIEWo * VIEW_OFFSET )
- fgMakeViewRot( VIEW_ROT, VIEW_OFFSET, VIEWo );
-
- sgVec3 trans_vec;
- sgAddVec3( trans_vec, view_pos, pilot_offset_world );
-
- // VIEW = VIEW_ROT * TRANS
- sgCopyMat4( VIEW, VIEW_ROT );
- sgPostMultMat4ByTransMat4( VIEW, trans_vec );
-
- //!!!!!!!!!!!!!!!!!!!
- // THIS IS THE EXPERIMENTAL VIEWING ANGLE SHIFTER
- // THE MAJORITY OF THE WORK IS DONE IN GUI.CXX
- // this in gui.cxx for now just testing
- extern float GuiQuat_mat[4][4];
- sgPreMultMat4( VIEW, GuiQuat_mat);
- // !!!!!!!!!! testing
-
- // Given a vector pointing straight down (-Z), map into onto the
- // local plane representing "horizontal". This should give us the
- // local direction for moving "south".
- sgSetVec3( minus_z, 0.0, 0.0, -1.0 );
-
- sgmap_vec_onto_cur_surface_plane(world_up, view_pos, minus_z,
- surface_south);
- sgNormalizeVec3(surface_south);
- // cout << "Surface direction directly south " << surface_south[0] << ","
- // << surface_south[1] << "," << surface_south[2] << endl;
-
- // now calculate the surface east vector
- sgVec3 world_down;
- sgNegateVec3(world_down, world_up);
- sgVectorProductVec3(surface_east, surface_south, world_down);
-
- set_clean();
-}
-
-
-// Destructor
-FGViewerRPH::~FGViewerRPH( void ) {
-}
+++ /dev/null
-// viewer_rph.hxx -- class for managing a Roll/Pitch/Heading viewer in
-// the flightgear world.
-//
-// Written by Curtis Olson, started August 1997.
-// overhaul started October 2000.
-//
-// Copyright (C) 1997 - 2000 Curtis L. Olson - curt@flightgear.org
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 2 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//
-// $Id$
-
-
-#ifndef _VIEWER_RPH_HXX
-#define _VIEWER_RPH_HXX
-
-
-#ifndef __cplusplus
-# error This library requires C++
-#endif
-
-
-#include "viewer.hxx"
-
-
-// Define a structure containing view information
-class FGViewerRPH: public FGViewer {
-
-private:
-
- // view orientation (roll, pitch, heading)
- sgVec3 rph;
-
- // up vector for the view (usually point straight up through the
- // top of the aircraft
- sgVec3 view_up;
-
- // the vector pointing straight out the nose of the aircraft
- sgVec3 view_forward;
-
- // Transformation matrix for the view direction offset relative to
- // the AIRCRAFT matrix
- sgMat4 VIEW_OFFSET;
-
- // sg versions of our friendly matrices
- sgMat4 LOCAL, TRANS, LARC_TO_SSG;
-
- // Update the view volume, position, and orientation
- void update();
-
-public:
-
- // Constructor
- FGViewerRPH( void );
-
- // Destructor
- ~FGViewerRPH( void );
-
- // Initialize a view class
-// void init( void );
-
- //////////////////////////////////////////////////////////////////////
- // setter functions
- //////////////////////////////////////////////////////////////////////
- inline void set_rph( double r, double p, double h ) {
- // data should be in radians
- set_dirty();
- sgSetVec3( rph, r, p, h );
- }
-
- //////////////////////////////////////////////////////////////////////
- // accessor functions
- //////////////////////////////////////////////////////////////////////
- inline float *get_rph() { return rph; }
- inline float *get_view_forward() { return view_forward; }
- inline float *get_view_up() { return view_up; }
-
- //////////////////////////////////////////////////////////////////////
- // derived values accessor functions
- //////////////////////////////////////////////////////////////////////
-};
-
-
-#endif // _VIEWER_RPH_HXX