Home · All Namespaces · All Classes · Functions · Coding Style · Plugins · File Structure

core/StelProjectorClasses.hpp

00001 /*
00002  * Stellarium
00003  * Copyright (C) 2008 Stellarium Developers
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  */
00019 
00020 #ifndef _STELPROJECTIONS_HPP_
00021 #define _STELPROJECTIONS_HPP_
00022 
00023 #include "StelProjector.hpp"
00024 
00025 class StelProjectorPerspective : public StelProjector
00026 {
00027 public:
00028     StelProjectorPerspective(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00029     virtual QString getNameI18() const;
00030     virtual QString getDescriptionI18() const;
00031     virtual double getMaxFov() const {return 120.;}
00032     bool forward(Vec3d &v) const
00033     {
00034         const double r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
00035         if (v[2] < 0) {
00036             v[0] /= (-v[2]);
00037             v[1] /= (-v[2]);
00038             v[2] = r;
00039             return true;
00040         }
00041         if (v[2] > 0) {
00042             v[0] /= v[2];
00043             v[1] /= v[2];
00044             v[2] = r;
00045             return false;
00046         }
00047         v[0] *= 1e99;
00048         v[1] *= 1e99;
00049         v[2] = r;
00050         return false;
00051     }
00052     bool backward(Vec3d &v) const;
00053     double fovToViewScalingFactor(double fov) const;
00054     double viewScalingFactorToFov(double vsf) const;
00055     double deltaZoom(double fov) const;
00056 };
00057 
00058 class StelProjectorEqualArea : public StelProjector
00059 {
00060 public:
00061     StelProjectorEqualArea(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00062     virtual QString getNameI18() const;
00063     virtual QString getDescriptionI18() const;
00064     virtual double getMaxFov() const {return 360.;}
00065     bool forward(Vec3d &v) const
00066     {
00067         const double r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
00068         const double f = std::sqrt(2.0/(r*(r-v[2])));
00069         v[0] *= f;
00070         v[1] *= f;
00071         v[2] = r;
00072         return true;
00073     }
00074     bool backward(Vec3d &v) const;
00075     double fovToViewScalingFactor(double fov) const;
00076     double viewScalingFactorToFov(double vsf) const;
00077     double deltaZoom(double fov) const;
00078 };
00079 
00080 class StelProjectorStereographic : public StelProjector
00081 {
00082 public:
00083     StelProjectorStereographic(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00084     virtual QString getNameI18() const;
00085     virtual QString getDescriptionI18() const;
00086     virtual double getMaxFov() const {return 235.;}
00087     bool forward(Vec3d &v) const
00088     {
00089         const double r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
00090         const double h = 0.5*(r-v[2]);
00091         if (h <= 0.0) {
00092             v[0] = 1e99;
00093             v[1] = 1e99;
00094             v[2] = -1e99;
00095             return false;
00096         }
00097         const double f = 1.0 / h;
00098         v[0] *= f;
00099         v[1] *= f;
00100         v[2] = r;
00101         return true;
00102     }
00103     bool backward(Vec3d &v) const;
00104     double fovToViewScalingFactor(double fov) const;
00105     double viewScalingFactorToFov(double vsf) const;
00106     double deltaZoom(double fov) const;
00107 };
00108 
00109 class StelProjectorFisheye : public StelProjector
00110 {
00111 public:
00112     StelProjectorFisheye(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00113     virtual QString getNameI18() const;
00114     virtual QString getDescriptionI18() const;
00115     virtual double getMaxFov() const {return 180.00001;}
00116     bool forward(Vec3d &v) const
00117     {
00118         const double rq1 = v[0]*v[0] + v[1]*v[1];
00119         if (rq1 > 0.0) {
00120             const double h = std::sqrt(rq1);
00121             const double f = std::atan2(h,-v[2]) / h;
00122             v[0] *= f;
00123             v[1] *= f;
00124             v[2] = std::sqrt(rq1 + v[2]*v[2]);
00125             return true;
00126         }
00127         if (v[2] < 0.0) {
00128             v[0] = 0.0;
00129             v[1] = 0.0;
00130             v[2] = 1.0;
00131             return true;
00132         }
00133         v[0] = 1e99;
00134         v[1] = 1e99;
00135         v[2] = -1e99;
00136         return false;
00137     }
00138     bool backward(Vec3d &v) const;
00139     double fovToViewScalingFactor(double fov) const;
00140     double viewScalingFactorToFov(double vsf) const;
00141     double deltaZoom(double fov) const;
00142 };
00143 
00144 class StelProjectorCylinder : public StelProjector
00145 {
00146 public:
00147     StelProjectorCylinder(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00148     virtual QString getNameI18() const;
00149     virtual QString getDescriptionI18() const;
00150     virtual double getMaxFov() const {return 175. * 4./3.;} // assume aspect ration of 4/3 for getting a full 360 degree horizon
00151     bool forward(Vec3d &win) const;
00152     bool backward(Vec3d &v) const;
00153     double fovToViewScalingFactor(double fov) const;
00154     double viewScalingFactorToFov(double vsf) const;
00155     double deltaZoom(double fov) const;
00156 };
00157 
00158 class StelProjectorMercator : public StelProjector
00159 {
00160 public:
00161     StelProjectorMercator(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00162     virtual QString getNameI18() const;
00163     virtual QString getDescriptionI18() const;
00164     virtual double getMaxFov() const {return 175. * 4./3.;} // assume aspect ration of 4/3 for getting a full 360 degree horizon
00165     bool forward(Vec3d &win) const;
00166     bool backward(Vec3d &v) const;
00167     double fovToViewScalingFactor(double fov) const;
00168     double viewScalingFactorToFov(double vsf) const;
00169     double deltaZoom(double fov) const;
00170 };
00171 
00172 class StelProjectorOrthographic : public StelProjector
00173 {
00174 public:
00175     StelProjectorOrthographic(const Mat4d& modelViewMat) : StelProjector(modelViewMat) {;}
00176     virtual QString getNameI18() const;
00177     virtual QString getDescriptionI18() const;
00178     virtual double getMaxFov() const {return 179.9999;}
00179     bool forward(Vec3d &win) const;
00180     bool backward(Vec3d &v) const;
00181     double fovToViewScalingFactor(double fov) const;
00182     double viewScalingFactorToFov(double vsf) const;
00183     double deltaZoom(double fov) const;
00184 };
00185 
00186 class StelProjector2d : public StelProjector
00187 {
00188 public:
00189     StelProjector2d() : StelProjector(Mat4d::identity()) {;}
00190     virtual QString getNameI18() const;
00191     virtual QString getDescriptionI18() const;
00192     virtual double getMaxFov() const {return 360.;}
00193     bool forward(Vec3d &win) const;
00194     bool backward(Vec3d &v) const;
00195     double fovToViewScalingFactor(double fov) const;
00196     double viewScalingFactorToFov(double vsf) const;
00197     double deltaZoom(double fov) const;
00198 };
00199 
00200 #endif // _STELPROJECTIONS_HPP_
00201 

Generated on Mon Feb 2 17:23:47 2009 for Stellarium by  doxygen 1.5.5